2011年3月18日

poj 3537

摘要: nim博弈,简单,1A代码:#include<iostream>#include<fstream>using namespace std;int g[2001];int v[2001];int solve(int s){ int i,j,k; if(v[s]) return g[s]; bool v2[2100]={0}; v[s]=1; for(i=1;i<=s/2+1;i++) { if(i-3>=1) j=solve(i-3); else j=0; if(i+3<=s) k=solve(s-i-2); else k=0; v2[j^k]=1; } 阅读全文

posted @ 2011-03-18 16:15 宇宙吾心 阅读(390) 评论(0) 推荐(0)

poj 1704

摘要: 楼梯nim,自己推出来的,爽!!注意输入是没排序好的。代码:#include<iostream>#include<fstream>using namespace std;int n;int a[1010];int b[1010];int cmp(const void *a,const void *b){ return *(int*)a-*(int *)b;}void read(){// ifstream cin("in.txt"); int i,j,k,s; int K; cin>>K; while(K--){ cin>>n; 阅读全文

posted @ 2011-03-18 14:30 宇宙吾心 阅读(271) 评论(0) 推荐(0)

poj 2960

摘要: nim 求动归求G(X).代码:#include<iostream>#include<fstream>using namespace std;int a[101];int dp[10001];int v[10001];int n,m;int solve(int s){ int i; if(v[s]==1) return dp[s]; v[s]=1;bool v2[20001]={0}; for(i=1;i<=n;i++) if(s>=a[i]) { int j=solve(s-a[i]); v2[j]=1; } dp[s]=0; for(i=0;;i++) 阅读全文

posted @ 2011-03-18 13:21 宇宙吾心 阅读(480) 评论(0) 推荐(0)

2011年3月17日

poj 2348

摘要: 博弈题,有些深层意义尚未挖掘。代码:#include<iostream>#include<fstream>#include<cmath>using namespace std;void read(){// ifstream cin("in.txt"); int i,j,k,s,t; while(1){ cin>>i>>j; if(i==0&&j==0) return; s=min(i,j); t=max(i,j); if(t>=s+1&&t<=s*(1+sqrt(5.)) 阅读全文

posted @ 2011-03-17 15:25 宇宙吾心 阅读(205) 评论(0) 推荐(0)

poj 1082

摘要: 博弈找规律。代码:#include<iostream>#include<fstream>using namespace std;void read(){// ifstream cin("in.txt"); int i,j,k,s; cin>>k; while(k--){ cin>>i>>j>>s; if((j+s)%2) { if(j==11&&s==30) cout<<"YES"<<endl; else if(j==9&&s= 阅读全文

posted @ 2011-03-17 13:59 宇宙吾心 阅读(230) 评论(0) 推荐(0)

poj 1740

摘要: 博弈,首先讨论石头堆两堆两堆相等的情况,例如x,x,y,y,z,z.6堆的情况.在这种情况下先取的必输,很简单,先取的那人怎么取后取的那人就怎么取(如 果对方把石头分配到一堆上,你就分配到与之对应的堆上),总之保持这个相等的均势不变,这样到最后,后取的人就将取走最后一堆石头.代码:#include<iostream>#include<fstream>using namespace std;int a[11];int cmp(const void *a,const void *b){ return *((int *)a)-*((int *)b);}void read(){ 阅读全文

posted @ 2011-03-17 13:28 宇宙吾心 阅读(193) 评论(0) 推荐(0)

poj 1067

摘要: 威佐夫博奕(Wythoff Game): 有两堆各若干个物品,两个人轮流从某一堆或同时从两堆中取同样多的物品,规定每次至少取一个,多者不限,最后取光者得胜。 这种情况下是颇为复杂的。我们用(ak,bk)(ak ≤ bk ,k=0,1,2,...,n)表示两堆物品的数量并称其为局势,如果甲面对(0,0),那么甲已经输了,这种局势我们称为奇异局势。前几个奇异局势是:(0,0)、(1,2)、(3,5)、(4,7)、(6,10)、(8,13)、(9,15)、(11,18)、(12,20)。 可以看出,a0=b0=0,ak是未在前面出现过的最小自然数,而 bk= ak + k。 奇异局势有如下三条性质: 阅读全文

posted @ 2011-03-17 10:43 宇宙吾心 阅读(257) 评论(0) 推荐(0)

poj 2975

摘要: nim。先把每堆中的数按位异或,得到一个数temp。然后把temp和每一堆中的石子数按位异或得到m,如果num[i]>m,则可以从这堆中取走num[i]-m个石子,使之成为胜局;否则不能从这堆中取子使之成为胜局。现在解释原因。设其中任意一堆的数量为a,其它堆异或和为A,所有堆中的数量异或和为b,则a^A==b。已知a和b,可以求出A==a^b。而这个A,就是在a中取完石子后要剩下的石子数量,因为只有当取完子后剩下的数量为A,才能使得a^A==b。代码:#include<iostream>#include<fstream>using namespace std;lo 阅读全文

posted @ 2011-03-17 10:10 宇宙吾心 阅读(362) 评论(0) 推荐(0)

2011年3月16日

poj 2125

摘要: 最小点权覆盖。注意入边,出边不要搞反了。代码:#include<iostream>#include<fstream>#include<queue>using namespace std;int n;int d[210];int flow;int v[210];typedef struct e{ int data; int f,c; e *next,*opt;}e;e edge[210];int build(){ int i,j,k; queue<int> q; q.push(1); memset(d,0,sizeof(d)); d[1]=1; w 阅读全文

posted @ 2011-03-16 19:59 宇宙吾心 阅读(486) 评论(0) 推荐(0)

poj 2987

摘要: 二分图最小点权覆盖。代码:#include<iostream>#include<fstream>#include<queue>#include<cmath>using namespace std;int n;int d[110];double flow;int v[110];typedef struct e{ int data; double f,c; e *next,*opt;}e;e edge[110];int build(){ int i,j,k; queue<int> q; q.push(1); memset(d,0,size 阅读全文

posted @ 2011-03-16 18:24 宇宙吾心 阅读(432) 评论(0) 推荐(0)

导航