做了几道关于博弈论的算法题, 对于算法的学习,有时候也会让自己感到很苦恼,在此记录一些,希望自己早日成为大神。
1.资源抢夺
#include<stdio.h>
int main()
{ int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
//如果n%(m+1)==0先手必败,否则,先手必胜。
if(n%(m+1)==0)
printf("Wildhunte");
else
printf("Gerlot");
printf("\n");
}
}
2.dls的黑粉
#include<stdio.h>
int main()
{
long long int a[100000];
int n;
char b;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d %c",&a[i],&b);
if(a[i]==1||a[i]==2)
{
if('W'==b)
printf("east is anti-fan");
else
printf("west is anti-fan");
}
else
{
if(n%2!=0)
{
if(b=='W')
printf("east is anti-fan");
else
printf("west is anti-fan");
}
else
{
if(b=='W')
printf("east is anti-fan");
else
printf("west is anti-fan");
}
}
}
}
3.Nimhttps://leetcode-cn.com/problems/nim-game/游戏
bool canWinNim(int n){
if(n==1||n==2||n==3)
return true;
else
{
if(n%4==0)
return false;
else
return true;
}
}
后期继续积累吧!加油鸭!
扫描二维码关注公众号,回复:
15297323 查看本文章