The shortest problem
2015-08-12 21:52
260 查看
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
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; }
相关文章推荐
- sunburnt 学习笔记 (八)管理索引
- Makefile 使用总结
- HibernateTemplate与JdbcTemplate项目
- 【Hadoop系列第九章】(二)实践:HBase部署及应用
- 颜色聚类方法综述
- 冒泡排序2
- chrome浏览器安装离线的插件--是百度很久才搜索到的办法
- golang 数组切片(二)
- 基于ftp模式搭建的yum服务器
- hdu1002
- Eclipse工程出现红叉
- Cocos2d-x使用Luajit将Lua脚本编译成bytecode,启用加密
- 多线程编程 实战篇 (三)
- leetcode: Maximum Depth of Binary Tree
- jdk版本的特点
- cookie 和 Session
- iOS开发-UIScreenEdgePanGestureRecognizer实战
- MySQL字符集设置及字符转换(latin1转utf8)
- TableView省市区数组字典 属性传值
- Java笔试面试题006