35 2 35 1 -1 -1
Case #1: Yes Case #2: No
##1005. The shortest problem
本场最水的题,被11整除的性质是奇偶位的和之差能被11整除,然后模拟一下就好了。 然后如果用longlong的话可能会T(写的好就不会),用int就好了。(经过测试用int时间为longlong的1/4)
转载请注明出处:寻找&星空の孩子
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5373
#include <iostream> #include <cstdio> #include <cstring> #include <stack> #include <queue> #include <map> #include <set> #include <vector> #include <cmath> #include <algorithm> using namespace std; #define ll long long const double eps = 1e-6; const double pi = acos(-1.0); const int INF = 0x3f3f3f3f; const int MOD = 1000000007; int n,t; int x,y,k; int main () { int a,b,c,d,e,ii=1; while (scanf ("%d%d",&n,&t)==2) { if (n==-1&&t==-1) break; a = n/10000; b = (n/1000)%10; c = (n/100)%10; d = (n/10)%10; e = n%10; //if (d!=0){k++; if(c!=0)k++; if(b!=0)k++; if(a!=0)k++;} y = d+b; x = c+a+e; while (t--) { k = 0; int p=0,q=0,m=x+y; while (m) { k++; if (k%2) p += m%10; else q += m%10; m /= 10; } //cout<<p<<" "<<q<<endl;cout<<x<<" "<<y<<endl; if (k%2) { x += q; y += p; swap(x, y); } else { x += p; y += q; } } if ((x-y)%11) printf ("Case #%d: No\n",ii++); else printf ("Case #%d: Yes\n",ii++); } return 0; }