469人阅读 评论(0)

# The shortest problem

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2223    Accepted Submission(s): 902

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$10^4$ ) , t(0<=t<=105$10^5$) 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

n$n$ 的后面组成一个新的数，操作 t(t105)$t(t\le 10^5)$ 次，问 t$t$ 次之后的结果是不是能够被 11$11$

My Code$My\ Code：$

/**
2016 - 08 - 29 下午
Author: ITAK

Motto:

**/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9+5;
const int MAXN = 1e6+5;
const int MOD = 1e9+7;
const double eps = 1e-7;
const double PI = acos(-1);
using namespace std;
LL Scan_LL()///输入外挂
{
LL res=0,ch,flag=0;
if((ch=getchar())=='-')
flag=1;
else if(ch>='0'&&ch<='9')
res=ch-'0';
while((ch=getchar())>='0'&&ch<='9')
res=res*10+ch-'0';
return flag?-res:res;
}
int Scan_Int()///输入外挂
{
int res=0,ch,flag=0;
if((ch=getchar())=='-')
flag=1;
else if(ch>='0'&&ch<='9')
res=ch-'0';
while((ch=getchar())>='0'&&ch<='9')
res=res*10+ch-'0';
return flag?-res:res;
}
void Out(LL a)///输出外挂
{
if(a>9)
Out(a/10);
putchar(a%10+'0');
}
int a[MAXN];
int main()
{
int t, cas = 1, n;
while(cin>>n>>t)
{
if(n==-1 && t==-1)
break;
int tmp = n, cnt = 1, sum = 0;
memset(a, 0, sizeof(a));
while(tmp)
{
a[cnt++] = tmp%10;
sum += (tmp%10);
tmp /= 10;
}
for(int i=1; i<=cnt/2; i++)
swap(a[i], a[cnt-i]);
int sum1 = 0, sum2 = 0, tp;
for(int i=1; i<cnt; i++)
{
if(i & 1)
sum1 += a[i];
else
sum2 += a[i];
}
///cout<<"sum1 = "<<sum1<<endl<<"sum2 = "<<sum2<<endl;
while(t--)
{
tmp = sum, tp = cnt;
///cout<<"sum = "<<sum<<endl;
while(tmp)
{
a[cnt++] = tmp%10;
sum += (tmp%10);
tmp /= 10;
}
for(int i=tp; i<=(cnt-1+tp)/2; i++)
swap(a[i], a[cnt-i+tp-1]);
/**for(int i=1; i<cnt; i++)
cout<<"a[i] = "<<a[i]<<endl;
cout<<"+++++++++++++++++++++++"<<endl;*/
for(int i=tp; i<cnt; i++)
{
if(i & 1)
sum1 += a[i];
else
sum2 += a[i];
}
}
///cout<<"sum1 = "<<sum1<<endl<<"sum2 = "<<sum2<<endl;
if(abs(sum1-sum2) % 11 == 0)
printf("Case #%d: Yes\n",cas++);
else
printf("Case #%d: No\n",cas++);
}
return 0;
}

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：506731次
• 积分：11326
• 等级：
• 排名：第1597名
• 原创：639篇
• 转载：5篇
• 译文：0篇
• 评论：93条
博客专栏
 计算机专业的相关课程知识 文章：24篇 阅读：31281
 ACM_组合数学 文章：27篇 阅读：31349
 ITAK的ACM之路 文章：295篇 阅读：330164
阅读排行
喜欢的Music
友情推荐