2015 Multi-University Training Contest 7 1005
2015-08-11 20:50
387 查看
The shortest problem
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 380 Accepted Submission(s): 186
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
For each input , if the final number are divisible by 11, output “Yes”, else output ”No”. without quote.
[align=left]Sample Input[/align]
35 2
35 1
-1 -1
[align=left]Sample Output[/align]
Case #1: Yes
Case #2: No
[align=left]Source[/align]
2015 Multi-University Training Contest 7
题意:将前面的每位数相加得到的数加到最后,如此往复执行n次,问最后得到的数字能否被11整除
分析:模拟一次就行,注意答案可能计算中的结果可能会超int
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<string> #include<iostream> #include<cstring> #include<cmath> #include<stack> #include<queue> #include<vector> #include<map> #include<stdlib.h> #include<algorithm> #define LL __int64 using namespace std; LL num,n,ans,sum; LL calc(LL x) { LL res=0; while(x) { res+=x%10; x=x/10; } return res; } LL count_digit(LL x) { if(x==0) return 10; LL ok=1; while(x) { x=x/10; ok=ok*10; } return ok; } int main() { //freopen("in.txt","r",stdin); int Case=0; while(scanf("%I64d %I64d",&num,&n)!=EOF) { if(num==-1 && n==-1) break; ans=calc(num);//ans表示当前要加在后排的数 sum=num;//sum表示累加的和 for(int i=1;i<=n;i++) { sum=sum*count_digit(ans)+ans; sum=sum%11; ans=ans+calc(ans); } printf("Case #%d: ",++Case); if(sum%11==0) printf("Yes\n"); else printf("No\n"); } return 0; }
View Code
相关文章推荐
- hdu 5379 Mahjong tree DFS 心塞,比赛时没取模 2015 Multi-University Training Contest 7
- 2015 Multi-University Training Contest 7 1007
- Add Custom Tab in Detail screen for MIGO Transaction
- 2015 Multi-University Training Contest 7 hdu 5373 The shortest problem
- abap chain endchain
- hdu 5319 - Painter(模拟题)解题报告
- 2015 2015 Multi-University Training Contest 7 hdu 5375
- Rain on your Parade---hdu2389(HK求最大匹配)
- ubuntu 突然不能 sudo成功,报错su: Authentication failure
- No identities are available for signing的解决方法
- socket bind failed解决方案
- 2015 Multi-University Training Contest 7 hdu 5375 Gray code
- Matrix Chain Multiplication
- hdu 4630 No Pain No Game(树状数组)
- 2015 Multi-University Training Contest 7
- [AIR] AS3读取本地文件夹中的文件
- [AIR] AS3读取txt文档
- Exception in thread "main" com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport e
- Container with most water
- main函数中通过使用Person类和AddressBook类,创建对象、调用方法,实现以下8个功能