一开始我以为用普通的方式求SG值然后再mex就行了,这题数据量太大没法开下这么多的数组,不过也是加深了我对SG函数的理解,题目的解法是视情况而定的,像这道题完全不必要开数组记录SG函数的值,因为在找到最大的必败点之后再进行分类讨论其SG值自然可以求解,看来我对SG函数的后继态掌握的还不够好。
//HDU-1729.cpp
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <cctype>
#include <algorithm>
#include <iostream>
#include <string>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <utility>
#include <vector>
#include <bitset>
#include <functional>
using namespace std;
//const double pai = acos(-1.0);
const double pai = 3.14159265358979323846;
const int INF = 0x3f3f3f3f;
typedef long long love_live;
int getsg(int s, int c){
int i, j, k;
k = sqrt(s);
while(k * k + k >= s){
k--;
}
if(c > k){
return s - c;
}
else{
return getsg(k, c);
}
}
int main(int argc, char const *argv[]) {
#ifndef ONLINE_JUDGE
// freopen("output", "w", stdout);
freopen("input", "r", stdin);
#endif
int n, m, i, j, k, cse = 1, s, c;
while(scanf("%d", &n) != EOF){
if(n == 0){
break;
}
// cout << n << endl;
int ans = 0;
while(n--){
scanf("%d %d", &s, &c);
ans ^= getsg(s, c);
}
// cout << ans << endl;
printf("Case %d:\n", cse++);
if(ans == 0){
printf("No\n");
}
else{
printf("Yes\n");
}
}
return 0;
}