2015多校第7场 HDU 5373 The shortest problem 规律,暴力
来源:互联网 发布:地方门户源码带手机版 编辑:程序博客网 时间:2024/05/18 13:46
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5373
题意:把一个数的数位之和加到这个数的后面,构成新数,继续这样操作,操作m轮,问最后这个数可以整除11吗?
解法:能被11整除的数的特征 把一个数由右边向左边数,将奇位上的数字与偶位上的数字分别加起来,再求它们的差,如果这个差是11的倍数(包括0),那么,原来这个数就一定能被11整除。代码直接统计奇偶的和,最后作差比较下。
#include <bits/stdc++.h>using namespace std;int n,t,x,y,m,a,b,c,d,e,p,q,k,ks=0;int main(){ while(~scanf("%d %d", &n,&t)) { if(n==-1&&t==-1) break; a=n/10000; b=(n/1000)%10; c=(n/100)%10; d=(n/10)%10; e=n%10; y=b+d; x=a+c+e; while(t--){ k=0; p=0,q=0,m=x+y; while(m){ k++; if(k%2)p+=m%10; else q+=m%10; m/=10; } if(k%2){ x+=q; y+=p; swap(x,y); } else{ x+=p,y+=q; } } if((x-y)%11) printf("Case #%d: No\n", ++ks); else printf("Case #%d: Yes\n", ++ks); } return 0;}
阅读全文
0 0
- 2015多校第7场 HDU 5373 The shortest problem 规律,暴力
- hdu 5373 The shortest problem(模拟、数学规律)
- hdu 5373 The shortest problem(杭电多校赛第七场)
- HDU 5373(2015多校7)-The shortest problem(模拟%11)
- HDU 5373 The shortest problem
- hdu 5373 the shortest problem
- HDU 5373 The shortest problem
- hdu 5373 The shortest problem
- HDU 5373 The shortest problem
- hdu 5373 The shortest problem
- HDU 5373 The shortest problem
- hdu 5373 The shortest problem
- HDU 5373 The shortest problem
- HDU 5373 The shortest problem (水题)
- HDU 5373 The shortest problem //模拟
- hdu 5373 The shortest problem(模拟)
- hdu 5373 The shortest problem (模拟)
- hdu 5373 The shortest problem(水)
- CDH:hdfs劵故障
- CFNetwork internal error (0xc01a:/BuildRoot/Library/Caches/com.apple.xbs/Sources/CFNetwork_Sim/CFNet
- Android Activty的加载过程 启动流程 源码分析
- 设计模式(19)--观察者模式
- LeetCode 3Sum Closest C++
- 2015多校第7场 HDU 5373 The shortest problem 规律,暴力
- LaTeX插入多行多列图
- 学习笔记
- android加入谷歌地图(2)
- 根据@把邮箱的用户名和地址分离,以键值对应的方式放入HashMap中
- C++函数模板
- HDU6060 RXD and dividing【DFS】
- setTag()和getTag() android
- python学习之路-基础篇-day02