您的位置:首页 > 编程语言 > C语言/C++

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Crashing Balloon ZOJ C++