cf B Very Beautiful Number

题意:给你两个数p和x,然后让你找出一个长度为p的数,把它的最后移到最前面之后得到的数是原来数字的x倍,有很多这样的数取最小。

思路:枚举最后一位,然后就可以推出整个的一个数,然后比较得到的数的第一个数字和枚举的数字是否相等既可以。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cmath>
 4 #include <algorithm>
 5 using namespace std;
 6
 7 int p,x;
 8 char str[1000010];
 9
10 int main()
11 {
12     scanf("%d%d",&p,&x);
13     bool flag=false;
14     for(int i=1; i<=9; i++)
15     {
16         int m=i;
17         int c=0;
18         int y=i;
19         str[0]=m+‘0‘;
20         for(int j=1; j<=p; j++)
21         {
22             int cc=(y*x+c)/10;
23             y=(y*x+c)%10;
24             str[j]=y+‘0‘;
25             c=cc;
26         }
27         if(y==m&&str[p-1]!=‘0‘&&c==0)
28         {
29             flag=true;
30             for(int k=p-1; k>=0; k--)
31             {
32                 printf("%c",str[k]);
33             }
34             printf("\n");
35             break;
36         }
37     }
38     if(!flag) printf("Impossible\n");
39     return 0;
40 }

时间: 2024-10-12 17:07:27

cf B Very Beautiful Number的相关文章

Codeforces 55D Beautiful Number

Codeforces 55D Beautiful Number a positive integer number is beautiful if and only if it is divisible by each of its nonzero digits. Input The first line of the input contains the number of cases t (1 ≤ t ≤ 10). Each of the next t lines contains two

HDU 5179 beautiful number (数位dp / 暴力打表 / dfs)

beautiful number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 801    Accepted Submission(s): 518 Problem Description Let A=∑ni=1ai?10n?i(1≤ai≤9)(n is the number of A's digits). We call A as "

hdu 5179 beautiful number

beautiful number 问题描述 令 A = \sum_{i=1}^{n}a_i * {10}^{n-i}(1\leq a_i \leq 9)A=∑?i=1?n??a?i??∗10?n−i??(1≤a?i??≤9)(nn为AA的位数).若AA为“漂亮的数”当且仅当对于任意1 \leq i < n1≤i<n满足a[i] \geq a[i+1]a[i]≥a[i+1]且对于任意1 \leq i \leq n,i < j \leq n1≤i≤n,i<j≤n,满足a[i]a[i]

HDU 5179 beautiful number 离线处理

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5179 beautiful number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 176    Accepted Submission(s): 104 Problem Description Let A=∑ni=1ai?10n?i(1≤

Beautiful number

一个数是美丽的,当且仅当其可以被其所有的非0数位整除.求在区间[a,b]中有多少数是美丽的. a,b<=10^18 这道题很明显是数位DP的分格,f[i][j][k][sta]表示前i个数,取值是否贴紧,前i个数的值%2520的值,前i个数的lcm(这里用离散化存),的方案数,答案就是count(b)-count(a-1); 还有数位DP中的技巧就是加上一个状态j表示是否贴紧. 666HQ的代码 #include<cstdio> #include<iostream> #inc

CF 546D Soldier and Number Game

Describe Two soldiers are playing a game. At the beginning first of them chooses a positive integer n and gives it to the second soldier. Then the second one tries to make maximum possible number of rounds. Each round consists of choosing a positive

CF 441E Valera and Number

CF 441E Description 一共执行\(k\)次,每次有\(p\%\)把\(x * 2\),有\((100 - p)\%\)把\(x + 1\).问二进制下\(x\)末尾期望\(0\)的个数. Solution 设\(f[i][j]\)为执行第\(i\)次后\(x + j\)末尾期望\(0\)的个数 加一:$f[i + 1][j - 1] = f[i + 1][j - 1] + (100 - p)% * f[i][j]; $ 乘二:\(f[i + 1][j * 2] = f[i +

CF 1215 B The Number of Products(思维题)

链接:https://codeforces.com/contest/1215/problem/B You are given a sequence a1,a2,…,ana1,a2,…,an consisting of nn non-zero integers (i.e. ai≠0ai≠0). You have to calculate two following values: the number of pairs of indices (l,r)(l,r) (l≤r)(l≤r) such t

ZOJ 2829 Beautiful Number(睡前一水)

链接:click here 题意:输出第N个能被3或者5整除的数,注意是||而不是&&. 代码: <pre name="code" class="cpp">//zoj 2829 #include <stdio.h> #include <stdlib.h> #include <iostream> #include <string.h> #include <math.h> using