Codeforces Round #231 (Div. 2) B Very Beautiful Number(数字递推)
来源:互联网 发布:网络解锁 编辑:程序博客网 时间:2024/05/17 07:14
一看到题目的时候就感觉很有思路,后写了几次试了一下,感觉对了。可惜代码能力不够强,一直在dbug,最后才过了样例。但是感觉怪怪的,要过不了,最后真的卡在了24组数据上了啊。sad、、、又是细节没注意啊、、
递推的方法,枚举最后一位数字,因为这个数字里面的顺序是有关系的所以最后一位dp[q]*x一定等于dp[q-1]。
比如样例:6 5 中的142857 和 714285。
7*5 的个位数一定是7前面的5,也是下面的最后一位5.
(5*5+3)%10 = 8是142857中5前面的8,也是714285中5前面的8.
同理模拟过程就可以推出来,一个q位数。但是这样枚举的时候最后一个数推出来的时候一定要判断一下是否有进位,否则就会卡在24组数据上了啊。
Teacher thinks that we make a lot of progress. Now we are even allowed to use decimal notation instead of counting sticks. After the test the teacher promised to show us a "very beautiful number". But the problem is, he's left his paper with the number in the teachers' office.
The teacher remembers that the "very beautiful number" was strictly positive, didn't contain any leading zeroes, had the length of exactlyp decimal digits, and if we move the last digit of the number to the beginning, it grows exactly x times. Besides, the teacher is sure that among all such numbers the "very beautiful number" is minimal possible.
The teachers' office isn't near and the teacher isn't young. But we've passed the test and we deserved the right to see the "very beautiful number". Help to restore the justice, find the "very beautiful number" for us!
The single line contains integers p, x (1 ≤ p ≤ 106, 1 ≤ x ≤ 9).
If the teacher's made a mistake and such number doesn't exist, then print on a single line "Impossible" (without the quotes). Otherwise, print the "very beautiful number" without leading zeroes.
6 5
142857
1 2
Impossible
6 4
102564
Sample 1: 142857·5 = 714285.
Sample 2: The number that consists of a single digit cannot stay what it is when multiplied by 2, thus, the answer to the test sample is "Impossible".
#include <algorithm>#include <iostream>#include <stdlib.h>#include <string.h>#include <iomanip>#include <stdio.h>#include <string>#include <queue>#include <cmath>#include <stack>#include <map>#include <set>#define eps 1e-7#define M 10001000//#define LL __int64#define LL long long#define INF 0x3f3f3f3f#define PI 3.1415926535898using namespace std;const int maxn = 2001000;int dp[maxn];int s1[maxn], s2[maxn];int main(){ int p, x; while(cin >>p>>x) { int flat; int sss; for(int i = 1; i <= 9; i++) { dp[p] = i; int s = p; int t = p-1; int add = 0; flat = 0; sss = 0; while(s) { dp[t] = ((dp[s]*x)%10+add)%10; add = ((dp[s]*x)+add)/10; s1[sss] = dp[s]; s2[sss++] = dp[t]; t--; s--; } if(add > 0)//就是这里没有判啊。。。 continue; if(s1[0] == s2[p-1] && dp[1]) { flat = 1; break; } } if(!flat) cout<<"Impossible"<<endl; else { for(int i = 1; i <= p; i++) cout<<dp[i]; cout<<endl; } } return 0;}
- Codeforces Round #231 (Div. 2) B Very Beautiful Number(数字递推)
- Codeforces Round #231 (Div. 2)B. Very Beautiful Number
- Codeforces Round #231 (Div. 2) B. Very Beautiful Number
- Codeforces Round #231 (Div. 2) B Very Beautiful Number
- Codeforces 394 B. Very Beautiful Number
- codeforces 394B Very Beautiful Number
- CF:394B - Very Beautiful Number(逆推)
- CF 394B Very Beautiful Number(逆推)
- CF 231div2 B. Very Beautiful Number
- Codeforces Round #325 (Div. 2) B 递推
- Codeforces 394B Very Beautiful Number(水题)
- Codeforces Round #345 (Div. 2) B. Beautiful Paintings
- Codeforces Round #345 (Div. 2)-B. Beautiful Paintings(暴力)
- Codeforces Round #345 (Div. 2) B. Beautiful Paintings【贪心】
- Codeforces Round #345 (Div. 2) B. Beautiful Paintings
- CF---B. Very Beautiful Number
- codeforces#231_div2_B Very Beautiful Number 高精度枚举
- Codeforces Round #245 (Div. 1)B 递推DP
- 仔细推敲,这些说法都是无稽之谈
- C#多线程协同完成一个任务
- linphone mediastream2 分析-双向录音机
- filter过滤器的功能简要介绍
- linux打包压缩命令汇总
- Codeforces Round #231 (Div. 2) B Very Beautiful Number(数字递推)
- ZJU_PAT_basic level_1014 字符串的简单处理与临界值的判定
- 深度围观block:三
- android camera(二):摄像头工作原理、s5PV310 摄像头接口(CAMIF) .
- 通过shell脚本修改xml文件中的某行记录
- 史上最全:Android开发者必知的开发资源 (图书、源码、站点、博客……)
- Oracle Database 11g Release 1中的自适应游标共享
- android camera(三):camera V4L2 FIMC
- Search Insert Position