HDU5373 The shortest problem (YY)

http://acm.hdu.edu.cn/showproblem.php?pid=5373 

YY题,模拟下计算过程就好了,计算中并不要保存实际数(这个数会非常大),只要保存到目前为止的数字位上的和 与 奇偶位上的差即可

 

 

 

#pragma comment(linker, "/STACK:1677721600")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <bitset>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstdarg>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define inf (-((LL)1<<40))
#define root 1, 1, n
#define lc (k << 1)
#define rc (k << 1 | 1)
#define middle ((L + R) >> 1)
#define lson k<<1, L, (L + R)>>1
#define rson k<<1|1,  ((L + R)>>1) + 1, R
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define mem(a, b) memset(a, b, sizeof(a))
#define FIN freopen("in.txt", "r", stdin)
#define FOUT freopen("out.txt", "w", stdout)
#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define dec(i, a, b) for(int i = a; i >= b; i --)

//typedef __int64 LL;
typedef long long LL;
typedef pair<int, int> Pair;
const int MAXN = 200000 + 100;
const int MAXM = 110000;
const double eps = 1e-10;
LL MOD = 1000000007;

int n, t;

//将n拆开,数字和加到sum中,奇偶差加到dif中,符号保存在f中
void calc_dif(int n, int &f, int &dif, int &sum) {
    int d = 0, s = 0, pf = f;
    while(n) {
        s += n % 10;
        d += n % 10 * f;
        f = -f;
        n /= 10;
    }
    if(f == pf) d *= -1;
    sum += s;
    dif += d;
}

int main()
{
#ifndef ONLINE_JUDGE
    FIN;
//    FOUT;
#endif
    int cas = 0;
    while(cin >> n >> t && (n != -1)) {
        int f = 1, dif = 0, sum = 0;
        calc_dif(n, f, dif, sum);
        while(t--) calc_dif(sum, f, dif, sum);
        printf("Case #%d: %s\n", ++cas, dif % 11 ? "No" : "Yes");
    }
    return 0;
}
posted @ 2015-08-12 15:41  再见~雨泉  阅读(207)  评论(0编辑  收藏  举报