UVA 725 Division(除法)
生活随笔
收集整理的這篇文章主要介紹了
UVA 725 Division(除法)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
輸入正整數n,按從小到大的順序輸出所有形如abcde/fghij=n的表達式,其中a~j恰好為數字0~9的一個排列,2n79。
題解:暴力破解枚舉fghij。
#include<iostream> #include <string> #include <string.h> #include<vector> #include<stack> #include<queue> #include<stdio.h> #include<stdlib.h> #include<iomanip> using namespace std; const int maxn = 50000; int main() { int kase=0;int a[5], b[5];int x = 0; while (cin >> x && x) {if(kase)cout<<endl;kase++;int c = 99999 / x; bool iscout = false;for (int i = 1234; i <= c; i++) {int k = i;for (int z = 0; z < 5; z++) {a[z] = k % 10; k /= 10;}bool isequal = false;for (int z = 0; z < 5; z++) {for (int j = z + 1; j < 5; j++) {if (a[z] == a[j]) {isequal = true; break;}}}if (isequal)continue;int to = i * x;if (to >= 100000)break;int tx = to;for (int z = 0; z < 5; z++) {b[z] = tx % 10; tx /= 10;}isequal = false;for (int z = 0; z < 5; z++) {for (int j = z + 1; j < 5; j++) {for (int r = 0; r < 5; r++)if (b[z] == a[r] || b[j] == a[r]) {isequal = true; break;}if (b[z] == b[j]) {isequal = true; break;}}}if (isequal)continue;/*cout << to << " / " << right << setw(5) << setfill('0') << i << " = " << x << endl;*/printf("%05d / %05d = %d\n", to, i, x);iscout = true;}if (!iscout)printf("There are no solutions for %d.\n", x);}//system("pause");return 0; }?
總結
以上是生活随笔為你收集整理的UVA 725 Division(除法)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: UVa810 A Dicey Probl
- 下一篇: 子集生成方式