HDU 2177
5228 ワード
http://acm.hdu.edu.cn/showproblem.php?pid=2177
ウィゾフゲームは、奇異な情勢に直面してbk=ak+kの時に必ず負けて、その中のbk>=ak、k=bk-ak
他の処理は他のゲームと同じで、問題のデータが山積みになっているときにデータに問題があることに注意します.
View Code
ウィゾフゲームは、奇異な情勢に直面してbk=ak+kの時に必ず負けて、その中のbk>=ak、k=bk-ak
他の処理は他のゲームと同じで、問題のデータが山積みになっているときにデータに問題があることに注意します.
#include <iostream>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
int OK(int b, int k) {
if(b == (int)(k * (1 + sqrt(5.0)) / 2) + k) return 1;
return 0;
}
int main() {
int a, b;
while(~scanf("%d%d", &a, &b)) {
if(!a && !b) break;
if(a > b) swap(a, b);
int k = b - a;
if(OK(b, k)) puts("0");
else {
puts("1");
int x, y;
for(int i = 1; i <= a; i++) {
x = a - i, y = b - i;
if(OK(y, y-x)) printf("%d %d
", x, y);
}
map <int, int> mp;
for(int i = 1; i <= b; i++) {
x = a - i, y = b;
if(x > 0 && OK(y, y-x) && mp[x]!=y) {
printf("%d %d
", x, y);
mp[x] = y;
}
x = a, y = b - i;
if(x > y) swap(x, y);
if(OK(y, y-x) && mp[x]!=y) {
printf("%d %d
", x, y);
mp[x] = y;
}
}
}
}
return 0;
}
View Code