UVA 1482 - Playing With Stones (SG博弈)
2013-08-22 09:38
281 查看
题目地址:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=477&problem=4228&mosmsg=Submission+received+with+ID+12234776
哎……做了这么多的SG博弈还是不能体会SG的精华。
SG博大精深,看来还要多学学。
通过打表可得:
当n为偶数时:SG(n)=n/2
当n为奇数时:SG(n)=SG((n+1)/2)
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
#include <ctime>
using namespace std;
typedef long long LL;
const int N=1005;
const double eps=1e-6;
const int M=1<<12;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
LL SG(LL p)
{
if(p==1)
return 0;
if(p%2==0)
return p/2;
return SG(p/2);
}
int main()
{
int i,j,T;
scanf("%d",&T);
while(T--)
{
LL a,t=0;
int n;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%lld",&a);
t=t^SG(a);
}
if(t==0)
printf("NO\n");
else
printf("YES\n");
}
return 0;
}
哎……做了这么多的SG博弈还是不能体会SG的精华。
SG博大精深,看来还要多学学。
通过打表可得:
当n为偶数时:SG(n)=n/2
当n为奇数时:SG(n)=SG((n+1)/2)
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
#include <ctime>
using namespace std;
typedef long long LL;
const int N=1005;
const double eps=1e-6;
const int M=1<<12;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
LL SG(LL p)
{
if(p==1)
return 0;
if(p%2==0)
return p/2;
return SG(p/2);
}
int main()
{
int i,j,T;
scanf("%d",&T);
while(T--)
{
LL a,t=0;
int n;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%lld",&a);
t=t^SG(a);
}
if(t==0)
printf("NO\n");
else
printf("YES\n");
}
return 0;
}
相关文章推荐
- uva 1482 - Playing With Stones(Nim游戏)
- UVA 1482 - Playing With Stones(SG打表规律)
- UVA 1482 - Playing With Stones(SG打表规律)
- uva 1482 - Playing With Stones
- UVA1482:Playing With Stones(SG)
- uvalive 5059 Playing With Stones(组合游戏,SG函数)@
- UVA - 1482 Playing With Stones
- UVALive 5059 C - Playing With Stones 博弈论Sg函数
- UVaLive5059 Playing With Stones
- UVA 11859 - Division Game (SG博弈)
- Boxes and Stones - UVa 12525 dp
- UVALive/LA 5059 Play with Stones 组合游戏/SG定理
- UVALive 5059 Play with Stones SG函数,难度较低
- UVa 12525 Boxes and Stones (dp 博弈)
- UVa 12525 Boxes and Stones (dp 博弈)
- UVA-1482 Playing With Stones(SG函数打表找规律)
- UVALive 5059 C Playing With Stones
- (SG博弈)uva 10561 - Treblecross
- UVALive 5116 Dividing Stones(dfs + 打表)
- uva 10558 A Brief Gerrymander