The shortest problem
The shortest problem
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 969 Accepted Submission(s): 491
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
比赛的时候别人直接暴力就可以过,我们为什么过不了QAQ
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
const int INF =0x3f3f3f3f;
int k;
int a[52];
int aa(int m)
{
int sum=0;
k=0;
while(m)
{
sum+=m%10;
a[k++]=m%10;
m/=10;
}
return sum;
}
int main()
{
int n,m;
int sum;
int w=1;
int ans;
while(scanf("%d %d",&n,&m))
{
if(n==-1&&m==-1)
{
break;
}
if(n==0)
{
printf("Case #%d: Yes\n",w++);
continue;
}
sum=aa(n);
ans=0;
int v=1;
while(k--)
{
if(v)
{
ans+=a[k];
v=0;
}
else
{
ans-=a[k];
v=1;
}
}
while(m--)
{
sum+=aa(sum);
while(k--)
{
if(v)
{
ans+=a[k];
v=0;
}
else
{
ans-=a[k];
v=1;
}
}
}
if(ans<0)
{
ans=-ans;
}
if(ans%11)
{
printf("Case #%d: No\n",w++);
}
else
{
printf("Case #%d: Yes\n",w++);
}
}
return 0;
}
The shortest problem的更多相关文章
- HDU-5373 The shortest problem
The shortest problem http://acm.hdu.edu.cn/showproblem.php?pid=5373 Time Limit: 3000/1500 MS (Java/O ...
- hdu 5373 The shortest problem(杭电多校赛第七场)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5373 The shortest problem Time Limit: 3000/1500 MS (J ...
- 同余模定理 HDOJ 5373 The shortest problem
题目传送门 /* 题意:题目讲的很清楚:When n=123 and t=3 then we can get 123->1236->123612->12361215.要求t次操作后, ...
- 2015 Multi-University Training Contest 7 hdu 5373 The shortest problem
The shortest problem Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- The shortest problem(hdu,多校
The shortest problem Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- hdoj 5373 The shortest problem
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5373 一开始想到用整除11的性质去做,即奇位数的和和偶位数的和的差为11的倍数,但估不准数据范围没敢去 ...
- HDU5373 The shortest problem (YY)
http://acm.hdu.edu.cn/showproblem.php?pid=5373 YY题,模拟下计算过程就好了,计算中并不要保存实际数(这个数会非常大),只要保存到目前为止的数字位上的和 ...
- (能被11整除的数的特征)The shortest problem --hdu
链接: http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1005&cid=595 若一个整数的个位数字截去,再从余下的数中 ...
- HDU 5373 The shortest problem (数学)
题意:给定两个数的n和m,有一种操作,把 n 的各位数字加起来放到 n后面形成一个新数n,问重复 m 次所得的数能否整除 11. 析:这个题首先要知道一个规律奇数位的和减去偶数位的和能被11整除的数字 ...
随机推荐
- 【转】线程、Thread类和线程终止
一.线程Thread启动 0. Thread类实现了java.lang.Runnable接口,即实现了run方法.虽然在Sun JDK中,start()调用了start0()方法,start0()方法 ...
- (Abstract Factory)抽象工厂
定义: 抽象工厂同工厂方法有相似处:都提供了对子类创建的封装,都是有工厂方法的接口实现类的中决定了子类被创建为什么对象. 不同于工厂方法之处:工厂方法创建的对象只是一个类型的子类,而抽象工厂创建的对象 ...
- DNS域名解析
之前用的是DNSPOD.CN的解析,没什么问题. 因为想根据不同国家做服务器解析(欧洲,亚洲,美国) 然后就转到DNSPOD.com里面有按国家来分的. 但是欧洲那边反应,每天断断续续会不能访问网站. ...
- 分布式领域CAP理论
分布式领域CAP理论,Consistency(一致性), 数据一致更新,所有数据变动都是同步的Availability(可用性), 好的响应性能Partition tolerance(分区容错性) 可 ...
- Java基础(43):Java中的Object类与其方法(转)
Object类 java.lang.Object java.lang包在使用的时候无需显示导入,编译时由编译器自动导入. Object类是类层次结构的根,Java中所有的类从根本上都继承自这个类. O ...
- Codeforces Round #312 (Div. 2) E. A Simple Task
题目大意就是给一个字符串,然后多个操作,每次操作可以把每一段区间的字符进行升序或者降序排序,问最终的字符串是多少. 一开始只考虑字符串中字符'a'的情况,假设操作区间[L,R]中有x个'a',那么一次 ...
- BeanFactory
Spring容器,最基本的接口就是BeanFactory 负责创建,配置,管理bean 它有一个子接口ApplicationContext并将功能扩展. 理论上bean ...
- 互联网分享知识(一转载 http://www.cnblogs.com/baochuan/p/4636103.html)
风雪之隅-Laruence的博客 http://www.laruence.com/ PHP开发组成员, Zend兼职顾问, PHP7核心开发者, Yaf, Yar, Yac等项目作者.偏向P ...
- ECharts切换主题
初始化接口,返回ECharts实例,其中dom为图表所在节点,theme为可选的主题,内置主题('macarons', 'infographic')直接传入名称,自定义扩展主题可传入主题对象.如: v ...
- Verilog中的specify block和timing check
在ASIC设计中,有两种HDL construct来描述delay信息: 1)Distributed delays:通过specify event经过gates和nets的time,来描述delay; ...