Uva 725 Division(暴力)
2016-08-13 16:26
351 查看
题意:给一个数N([2,79]),让你输出所有的形如abcde/fghij = N的表达式,其中的a-j为0-9的数字,且两两不同。
解法:枚举fghij,对应可以求出abcde,判断是否符合题意即可。
解法:枚举fghij,对应可以求出abcde,判断是否符合题意即可。
#include <bits/stdc++.h> #define _ ios_base::sync_with_stdio(0);cin.tie(0); #define INF 0x3f3f3f3f #define eps 1e-6 typedef long long LL; const double pi = acos(-1.0); const long long mod = 1e9 + 2015; using namespace std; int a[15]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); //freopen("int.txt","r",stdin); //freopen("out.txt","w",stdout); int N; int first = 1; while(cin >> N && N != 0) { memset(a,0,sizeof(a)); int ok = 0; if(first) first = 0; else puts(""); for(int i1 = 0;i1 < 10;i1++) { if(a[i1]) continue; a[i1] = 1; for(int i2 = 0;i2 < 10;i2++) { if(a[i2]) continue; a[i2] = 1; for(int i3 = 0;i3 < 10;i3++) { if(a[i3]) continue; a[i3] = 1; for(int i4 = 0;i4 < 10;i4++) { if(a[i4]) continue; a[i4] = 1; for(int i5 = 0;i5 < 10;i5++) { if(a[i5]) continue; a[i5] = 1; int k = 10000 * i1 + 1000 * i2 + 100 * i3 + 10 * i4 + i5; int t = k * N; int c = t; if(t < 100000) { while(t) { int b = t % 10; if(a[b]) break; a[b] = 1; t /= 10; } for(int i = 0;i < 10;i++) { if(a[i] != 1) { t = 1; break; } } if(t == 0) { printf("%05d / %05d = %d\n",c,k,N); ok = 1; } } memset(a,0,sizeof(a)); a[i1] = a[i2] = a[i3] = a[i4] = 1; } a[i4] = 0; } a[i3] = 0; } a[i2] = 0; } a[i1] = 0; } if(ok == 0) printf("There are no solutions for %d.\n",N); } return 0; }
相关文章推荐
- UVA 725 Division(暴力枚举 简单)
- UVA725 Division【暴力枚举】
- UVA 725 Division (暴力)
- 暴力枚举 UVA 725 Division
- UVa - 725 - Division(暴力枚举)
- UVa725 Division(暴力)
- Division UVA - 725(暴力)
- uva 725 DIVISION (暴力枚举)
- UVA.725 Division (暴力)
- uva 725 Division(暴力枚举) 解题心得
- uva 725 Division(除法)暴力法!
- UVA 725 Division ( 找出 abcde / fghij = N的形式—— 暴力枚举 )
- UVa 725 Division(暴力求解)
- UVa - 725 Division ( 暴力枚举 )
- uva 725 Division(暴力枚举)
- UVa 725 Division 【暴力入门】
- uva 725 Division 暴力求解入门
- Uva 725 Division (暴力搜索求解,入门题)
- Uva 725 Division (技巧暴力)
- UVA - 725 Division (暴力枚举)