2015 Multi-University Training Contest 7 hdu 5373 The shortest problem
2024-08-27 22:33:43
The shortest problem
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 346 Accepted Submission(s): 167
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.
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
解题:由于能被11整除的数的特点是奇数位与偶数位的和的绝对值可以被11整除,所以,搞一下就可以了
#include <bits/stdc++.h>
using namespace std;
int cur = ,n,m,d[];
int solve(int x) {
int a[] = {};
cur = ;
while(x) {
a[cur^] += x%;
x /= ;
cur ^= ;
}
if(cur&) swap(d[],d[]);
d[] += a[];
d[] += a[];
return d[] + d[];
}
int main() {
int cs = ;
while(scanf("%d%d",&n,&m),(~n) && (~m)) {
d[] = d[] = ;
for(int i = ; i <= m; ++i) n = solve(n);
printf("Case #%d: %s\n",cs++,abs(d[]-d[])%?"No":"Yes");
}
return ;
}
最新文章
- Python for Infomatics 第13章 网页服务一(译)
- jq 页面延时刷新
- Windows Azure 入门系列课程Windows Azure 入门系列课程
- ABP入门系列(5)——创建应用服务
- swift(一)
- [luogu 1880]石子合并
- MySQL 高可用MHA安装部署以及故障转移详细资料汇总 转
- JSON解析例子
- STMP发送邮件被当垃圾邮件处理的解决方法
- 动手实现Expression翻译器1
- ubuntu14.04下安装有道词典
- MarkDown---超强文本编辑器
- 解决IIS配置问题
- 校验台湾身份证号码的js脚本
- windows mysql绿色版配置
- PL2303 Windows8.1驱动
- log4net记录系统错误日志到文本文件用法详解(最新)
- RHEL7 -- systemd
- 字符串hash的学习部分 可以算是模板?
- 加快npm包安装的方法