CodeForces
来源:互联网 发布:萌萌猪软件系统开发 编辑:程序博客网 时间:2024/05/20 07:50
题目链接:Very Beautiful Number
题目大意:给定两个整数 p 和 x; 找出一个p 位的数 这个数要求最后一位移道首位 编程原来的数的x倍;注意不能出现前导0(就是首位不能为0);
解题思路: 枚举最后一位 for(int i=1; i<10; i++) ; c 为上一位的进位;
倒数第二位: A[p-1] = A[p] * x + c;
倒数第三位:A[p-2] = A[p-1] * x + c;
最后判定第一位与最后一位是否相等即可;
#include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>using namespace std;int A[1000005];int main(){ int p, x; while(~scanf("%d%d", &p, &x)) { int c = 0; int ok = 0; for(int i= 1; i<10; i++) { c = 0; A[p-1] = i; for(int j = p-2; j>=0; j--) { A[j] = (A[j+1] * x + c) % 10; c = (A[j+1] * x + c) / 10; } if(A[0] *x + c == A[p-1] && A[0]!=0) { ok = 1; break; } } if(ok) for(int i=0; i<p; i++) printf("%d", A[i]); else printf("Impossible"); printf("\n"); } return 0;}
阅读全文
0 0
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- 华为mate8对flex的支持
- 自定义View解决滑动冲突
- C++操作mysql方法总结(1)
- Android Studio无法识别Java文件。红色J
- ISP、IAP、ICP烧写方式的区别
- CodeForces
- CODEGEN: 参数“GetDataResult”需要其他方案信息,使用参数模式无法捕获这些信息。特定特性为“System.Xml.Serialization.XmlElementAttribute
- 图片加载
- spyder 护眼背景
- 卸载CDH5
- 使用VS时遇到的错误
- 程序员的婚后生活
- 数学规划
- varnish