Aprendizaje de algoritmos (1) Teoría de juegos

Hice algunas preguntas de algoritmos sobre teoría de juegos y, a veces, me siento muy angustiado por el aprendizaje de algoritmos. Registraré algunas aquí y espero convertirme en un maestro lo antes posible.

1. Robo de recursos

#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. El polvo negro de 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/ juego

 

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


}

  ¡Continuar acumulando más tarde! ¡Vamos pato!

Supongo que te gusta

Origin blog.csdn.net/qq_58259539/article/details/123760402
Recomendado
Clasificación