ZOJ 1003 Crashing Balloon
2017-03-05 12:10
260 查看
#include <iostream> #include <algorithm> using namespace std; bool FlagA, FlagB; void dfs(int A, int B, int MaxNumber) { if (FlagA == true) { return; } if (A == 1 && B == 1) // it's possible to get A and B points { FlagA = true; return; } if (B == 1) // it's possible to get B points { FlagB = true; } for (int i = MaxNumber; i > 1; i--) { if (A%i == 0) { dfs(A / i, B, i - 1); } if (B%i == 0) { dfs(A, B / i, i - 1); } } } int main() { int A, B; while (cin >> A >> B) { if (A < B) { swap(A, B); } FlagA = false; FlagB = false; dfs(A, B, 100); if (!FlagA && FlagB) // it's impossible to get A and B points { //but it's possible to get B points cout << B << endl; } else { cout << A << endl; } } return 0; }
相关文章推荐
- ZOJ 1003 Crashing Balloon
- POJ1003 UVALive2294 HDU1056 ZOJ1045 Hangover【数学计算+水题】
- zoj 1003
- ZOJ 1003 Crashing Balloon
- ZOJ Problem Set - 1003 Crashing Balloon
- zoj 1003
- ZOJ 1003 Crashing Balloon (DFS)
- 浙大ZOJ 1003 Crashing Ballon问题解决及其他人的做法
- ZOJ 1003 Crashing Balloon 搜索
- 【ZOJ 1003】 Crashing Balloon
- ZOJ 1003 Crashing Balloon
- zoj1003:DFS
- ZOJ 1003
- zoj 1003 Crashing Balloon
- [ZOJ 1003] Crashing Balloon (dfs搜索)
- zoj 1003 Crashing Balloon
- ZOJ 1003
- zoj 1003 Crashing Balloon
- HDU 1482/ZOJ 1184/FOJ 1003/POJ 1013 Counterfeit Dollar
- zoj 1003 Crashing Balloon