Algorithm Learning (1) Game Theory

I did a few algorithm questions about game theory, and sometimes I feel very distressed about the algorithm learning. I will record some here and hope that I will become a master as soon as possible.

1. Resource snatching

#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. The black powder of 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. Nim https://leetcode-cn.com/problems/nim-game/ game

 

bool canWinNim(int n){
    if(n==1||n==2||n==3)
    return true;
    else
    {
        if(n%4==0)
        return false;
        else 
        return true;
    }


}

  Continue to accumulate later! Come on duck!

Guess you like

Origin blog.csdn.net/qq_58259539/article/details/123760402