HDU 1729

一开始我以为用普通的方式求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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值