HDU 5373 The shortest problem

HDU 5373 The shortest problem

/**
多校聯合
暴力打表+預處理
HDU 5373 The shortest problem
*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#define maxn 100005
#define ll __int64
using namespace std;
int check(int num){ //查詢num是幾位數
    int ans=0;
    while(num){
        ans++;
        num/=10;
    }
    return ans;
}
int fun(int num){  //num的數位和
    int ret=0;
    while(num){
        ret+=(num%10);
        num/=10;
    }
    return ret;
}
ll ten[]={1,10,100,1000,10000,100000,1000000,10000000};//ten[i]10的i次方
int dp[12][maxn];//dp[i][j]指的是i操作j次
void init(){
    for(int i=0;i<11;i++){
        int sum=fun(i),n=i;
        for(int j=0;j<maxn;j++,n%=11){
            dp[i][j]=n;
            n*=ten[check(sum)];
            n+=sum;
            sum+=fun(sum);
        }
    }
}
int main(){
    int n,m;
    init();
    int ii=1;
    while(~scanf("%d%d",&n,&m)){
        if(n==-1&&m==-1) return 0;
        int sum=fun(n);
        int ans=-1;
        for(int i=0;i<m;i++,n%=11){
            n*=ten[check(sum)];
            n+=sum;
            sum+=fun(sum);
            if(n==0){
                sum%=11;
                ans=dp[sum][n-i];
                break;
            }
        }
        if(ans=-1) ans=n%11;
        if(ans) printf("Case #%d: No\n",ii++);
        else printf("Case #%d: Yes\n",ii++);
    }
    return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章