HDU 1847Good Luck in CET-4 Everybody!
n个石子取2的次幂个,0为terminal position
P/N分析和求SG值方法都可以,找规律的话模3余0也能过
主要是为了练习SG的求法
#include
#include
//单纯博弈型 也可用P/N分析法
int x[12],SG[1050];
bool vis[1050];
void init()
{
for (int i=0 ; i<11 ; ++i)
x[i]=1<
HDU 3980 Paint Chain
n元环,每次取连续的m个元素,最先不能取者败。
可以考虑n
#include
#include
const int maxn=1005;
int SG[maxn];
bool vis[maxn];
bool sg(int n , int m)//get SG value
{
memset(SG , 0 , sizeof(SG));
SG[m]=1;
for (int i=m+1 ; i<=n ; ++i)
{
memset (vis , 0 , sizeof(vis));
for (int j=0 ; jn)printf("Case #%d: abcdxyzk\n",I);
else if(sg(n-m,m))printf("Case #%d: abcdxyzk\n",I);
else printf("Case #%d: aekdycoin\n",I);
}
return 0;
}
POJ 3537 Crosses and Crosses
给一个1*n的长方形格子,在格子里轮流画X,最先得到3个连续X的人即为winner
#include
#include
const int maxn=2005;
int SG[maxn];
bool vis[maxn];
void sg()
{
memset (SG , 0 , sizeof(SG));
SG[1]=1;SG[2]=1;SG[3]=1;//SG[4]=1;
for (int i=4; i
#include
#include
const int maxm=2005000;
const int maxn=1005;
struct Edge {
int v,next;
}edge[maxm];
int head[maxn],cnt;
void addedge(int u,int v)
{
edge[cnt].v=v;
edge[cnt].next=head[u];
head[u]=cnt++;
}
bool vis[maxn],visit[maxn][maxn];//for dfs for sg;
int SG[maxn];
void dfs (int u)
{
if(~SG[u]) return ;
//vis[u]=true;
int p=head[u];
for ( ; ~p ; p=edge[p].next)
{
int v=edge[p].v;
//printf("%d ",u);
//if(vis[v])continue;
dfs(v);
visit[u][SG[v]]=true;
}
for (int i=0 ; true ; ++i)
{
if(!visit[u][i]){SG[u]=i;break;}
}
}
int main ()
{
int n,node,v,m,t;
while (~scanf("%d",&n))
{
memset (head , -1 , sizeof(head));
memset (SG , -1 , sizeof(SG));
cnt=0;
for (int u=0 ; u
#include
#include
using namespace std;
const int maxn=1005;
int nim[maxn];
int n;
int main ()
{
int cas;
scanf("%d",&cas);
while (cas--)
{
scanf("%d",&n);
int ans=0;
nim[0]=0;
for (int i=1 ; i<=n ; ++i)
{
scanf("%d",nim+i);
}
sort(nim,nim+n+1);
for (int i=0 ; i<(n+1)/2 ; ++i)
{
ans^=(nim[n-2*i]-nim[n-2*i-1]-1);
//printf("%d %d %d\n",nim[n-2*i],nim[n-2*i-1],ans);
}
puts(ans?"Georgia will win":"Bob will win");
}
return 0;
}
#include
#include
int SG[105][105];
bool vis[5000];
/*棋盘上的2维SG递推,非组合游戏可以不用SG*/
/*输出格式很恶心*/
int main ()
{
int l,w;
SG[0][0]=0;
for (int i=1 ; i<105 ; ++i)
{
SG[i][0]=i;
for (int j=1 ; j<105 ; ++j)
{
SG[0][j]=j;
if(i==j){SG[i][i]=i+1;continue;}
memset (vis , 0 , sizeof(vis));
for (int k=0 ; k
#include
#include
#include
#define abs(a) (a)>(0)?(a):(-(a))
#define min(a,b) (a>b?b:a)
const int maxn=100000+123;
typedef int typen;
typen a[maxn];
typen count[maxn];
const int maxp = 5000;
int prime[maxp + 1];//prime[0] is the counter
int getPrime()
{
memset (prime, 0, sizeof (prime));
for (int i = 2 ; i <= maxp ; i++)
{
if (!prime[i]) prime[++prime[0]] = i;
for (int j = 1; j <= prime[0] && prime[j] * i <= maxp ; j++)
{
prime[prime[j]*i] = 1;
if (i % prime[j] == 0) break;
}
}
return prime[0];
}
int getFactors(typen x)
{
int facCnt = 0;
typen tmp = x;
for(int i = 1; prime[i]*prime[i] <= tmp ; ++i)
{
if(tmp % prime[i] == 0)
{
while(tmp % prime[i] == 0)
tmp /= prime[i],++facCnt;
}
}
if(tmp != 1)
++facCnt;
return facCnt;
}
int cas=0;
int main ()
{
int n;
getPrime();
while ( ~scanf("%d",&n) )
{
memset (count , 0 , sizeof(count));
int sum=0;
for (int i=0 ; i