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整除的数字 ...
随机推荐
- java中HashSet详解(转)
HashSet 的实现 对于 HashSet 而言,它是基于 HashMap 实现的,HashSet 底层采用 HashMap 来保存所有元素,因此 HashSet 的实现比较简单,查看 HashSe ...
- SQL面向对象抽象类
抽象类:抽象类,只为继承而出现,不定义具体的内容,只规定该有哪些东西:一般抽象类中只放置抽象方法,只规定了返回类型和参数:例: 人 - 有吃饭,睡觉方法: 男人 - 继承人抽象类,必须实现吃饭,睡觉的 ...
- UML:组件图
要搞清楚组件图,必须先搞清楚什么是组件? 组件有以下特点:1.能实现一定功能,或者提供一些服务.2.不能单独运行,要作为系统的一部分来发挥作用.3.在物理上独立的,不是逻辑上的概念.4.可单独维护.可 ...
- python在window下的Nginx部署
Python版本3.21 安装nginx下载windows上的nginx最新版本,http://www.nginx.org/en/download.html.解压后即可.运行nginx.exe后本地打 ...
- c标签 总结
JSTL标签用法 关键字:JSTL标签.<c:choose>.<c:forEach>.<c:forTokens>.<c:if>.<c:import ...
- C语言 单引号 双引号问题
C语言中的单引号和双引号含义迥异,用单引号引起的一个字符实际上代表一个整数,整数值对应于该字符在编译器采用的字符集中的序列值,因此,采用ASCII字符集的编译器而言,‘a’的含义与0141或97严格一 ...
- Java中的并发线程操作(只贴代码,内有注释)
package com.thread1; public class LiffOff implements Runnable{ protected int countDown = 10; private ...
- [tp3.2.1]开启URL(重写模式),省略URL中的index.php
重写模式(省略url中的index.php) 在apache配置文件httpd.conf中,查找 1.mod_rewrite.so, 启动此模块 2.AllowOverride , 值= All 3. ...
- oracle中dual表的使用
dual表是一个虚拟表,用来和select语句一起使用.1.查看当前用户select user from dual2.用来调用系统函数select to_char(sysdate,'yyyy-mm- ...
- FTP小教程
1.下载文件:http://pan.baidu.com/s/1gd3Uo63 2. 右键点击“传送”,就会把本地的文件传送到服务器现在打开的目录