[2016-02-18][UVA][725][Division]
[2016-02-18][UVA][725][Division]
- 时间:2016-02-18 22:41:48 星期四
- 题目编号:UVA 725
- 题目大意:给定 n,输出所有情况:abcde / fghij = n ,使得 a~j为0~9的一个排列
- 方法:
- 枚举fghij ,通过 fghij * n 得到 abcde,看是否满足
- 前导0输出是 %05d
- 解题过程遇到问题:
- 每组数据间有空行,最后一组数据后面没有空行
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | #include <vector>#include <list>#include <map>#include <set>#include <deque>#include <queue>#include <stack>#include <bitset>#include <algorithm>#include <functional>#include <numeric>#include <utility>#include <sstream>#include <iostream>#include <iomanip>#include <cstdio>#include <cmath>#include <cstdlib>#include <cctype>#include <string>#include <cstring>#include <cstdio>#include <cmath>#include <cstdlib>#include <ctime>using namespace std;typedef long long LL;#define CLR(x,y) memset((x),(y),sizeof((x)))#define FOR(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define FORD(x,y,z) for(int (x)=(y);(x)>=(z);(x)--)#define FOR2(x,y,z) for((x)=(y);(x)<(z);(x)++)#define FORD2(x,y,z) for((x)=(y);(x)>=(z);(x)--)int check(int a,int b){ if(b > 98765) return 0; int vis[10],k,cnt = 0; CLR(vis,0); while(a){ k = a % 10; if(vis[k]) return 0; else ++vis[k]; a /= 10; } while(b){ k = b % 10; if(vis[k]) return 0; else ++vis[k]; b /= 10; } FOR(i,1,10){ if(vis[i]) ++cnt; } return cnt == 9;}int main(){ int n,cntcase = 0; while(~scanf("%d",&n) && n){ if(cntcase++) puts(""); int cnt = 0; for(int i = 01234;i <= 98765;++i){ if(check(i,i*n)){ ++cnt; printf("%05d / %05d = %d\n",i*n,i,n); } } if(!cnt) printf("There are no solutions for %d.\n",n); } return 0;} |
浙公网安备 33010602011771号