The shortest problem
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1004 Accepted Submission(s): 503
Problem Description
In this problem, we should solve an interesting game. At first, we have an integer n, then we begin to make some funny change. We sum up every digit of the n, then insert it to the tail of the number n, then let the new number be
the interesting number n. repeat it for t times. When n=123 and t=3 then we can get 123->1236->123612->12361215.
Input
Multiple input.
We have two integer n (0<=n<=104
) , t(0<=t<=105)
in each row.
When n==-1 and t==-1 mean the end of input.
Output
For each input , if the final number are divisible by 11, output “Yes”, else output ”No”. without quote.
Sample Input
35 2 35 1 -1 -1
Sample Output
Case #1: Yes Case #2: No
Source
2015 Multi-University Training Contest 7
Recommend
wange2014 | We have carefully selected several similar problems for you: 5379 5378 5377 5376 5374
题意:给定n和m,n代表一个数,m代表m次操作。每次操作都是加上各个位数的数,再加到n的尾部去。比如35 第一次操作358 第二次操作35816.
最后问的是这个数能否被11整除。
n的范围是1W,m的范围是10W,直接暴力的话显然不行,这个数实在是太大了。我们考虑用字符窜存储,,,能被11整除的数的规律是奇位数字的和减去偶位数字的和为11的倍数就行。然后我们模拟那个过程,最后for一遍字符数组就行。
#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include <math.h> #include <vector> #include <cstdlib> #include <map> #include <string> using namespace std; int main() { int t,i; char s[1000000]; int dd=0; while(~scanf("%s%d",&s,&t)) { if (s[0]=='-'&& t == -1) break; int l=strlen(s),sum=0; for(i=0; i<l; i++) { sum+=s[i]-'0'; } int cnt; while(t--) { int pp=sum; itoa(sum,s+l,10); cnt=0; while(pp) { sum+=pp%10; pp=pp/10; cnt++; } l+=cnt; } int ans=0; for(i=0; i<l; i++) { if(i&1) ans+=s[i]-'0'; else ans-=s[i]-'0'; } if(abs(ans)%11==0) printf("Case #%d: Yes\n",++dd); else printf("Case #%d: No\n",++dd); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。