求问checker是否有误
  • 板块灌水区
  • 楼主ACtheQ
  • 当前回复6
  • 已保存回复6
  • 发布时间2024/6/8 19:52
  • 上次更新2024/6/8 21:46:42
查看原帖
求问checker是否有误
755689
ACtheQ楼主2024/6/8 19:52
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;
char Flag[5][5];
char Flagg[5][5];
int check()
{
	for(int i=1;i<=3;i++)
	{
		bool vis=true;
		for(int j=1;j<=3;j++) vis&=(Flag[i][j]==Flag[i][1]); 
		if(vis)
		{
			if(Flag[i][1]=='O') return 1;
			else return -1;
		}
	}
	for(int i=1;i<=3;i++)
	{
		bool vis=true;
		for(int j=1;j<=3;j++) vis&=(Flag[j][i]==Flag[1][i]); 
		if(vis)
		{
			if(Flag[1][i]=='O') return 1;
			else return -1;
		}
	}
	bool vis1=true;
	for(int i=1;i<=3;i++) vis1&=(Flag[i][i]==Flag[1][1]);
	if(vis1)
	{
		if(Flag[1][1]=='O') return 1;
		else return -1;
	}
	bool vis2=true;
	for(int i=1;i<=3;i++) vis2&=(Flag[i][4-i]==Flag[1][3]);
	if(vis2)
	{
		if(Flag[1][3]=='O') return 1;
		else return -1;
	}
	return 0;
}
pair<int,int> checkwin()
{
	for(int i=1;i<=3;i++)
	{
		for(int j=1;j<=3;j++)
		{
			if(Flag[i][j]!='-') continue;
			Flag[i][j]='O';
			int id=check(); 
			Flag[i][j]='-';
			if(id==1) return make_pair(i,j);
		}
	}
	return make_pair(-1,-1);
} 
pair<int,int> checklose()
{
	for(int i=1;i<=3;i++)
	{
		for(int j=1;j<=3;j++)
		{
			if(Flag[i][j]!='-') continue;
			Flag[i][j]='X';
			int id=check(); 
			Flag[i][j]='-';
			if(id==-1) return make_pair(i,j);
		}
	}
	return make_pair(-1,-1);
} 
pair<int,int> checkangle()
{
	for(int i=1;i<=3;i++)
	{
		for(int j=1;j<=3;j++)
		{
			if(i==2||j==2) continue;
			Flag[i][j]='O';
			pair<int,int> ans=checkwin();
			int id=0;
			if(ans.first!=-1&&ans.second!=-1) id=1;
			Flag[i][j]='-'; 
			if(id==1) return make_pair(i,j);
		}
	}
	return make_pair(-1,-1);
}
pair<int,int> checkside()
{
	for(int i=1;i<=3;i++)
	{
		for(int j=1;j<=3;j++)
		{
			if(i!=2&&j!=2) continue;
			if(i==2&&j==2) continue;
			Flag[i][j]='O';
			pair<int,int> ans=checkwin();
			int id=0;
			if(ans.first!=-1&&ans.second!=-1) id=1;
			Flag[i][j]='-'; 
			if(id==1) return make_pair(i,j);
		}
	}
	return make_pair(-1,-1);
}
int main(int argc, char ** argv){
	srand(time(NULL));
	registerInteraction(argc, argv);
	int X = inf.readInt();	// chosen integer
	int Y = inf.readInt();
	cout.flush();	// to make sure output doesn't stuck in some buffer
	for(int i=1;i<=3;i++)
	{
		for(int j=1;j<=3;j++) Flag[i][j]='-';
	}
	Flag[X][Y]='O';
	int flag=0;
	int XX=0,YY=0;
	int xx=0,yy=0;
	for(int i=1;i<=4;i++)
	{
		int x = ouf.readInt();
		int y = ouf.readInt();	// the number you tell me
		if(Flag[x][y]!='-'||x<1||x>3||y<1||y>3)
		{
			quitf(_wa, "are you looks the rules? dummy!");
			return 0;
		}
		Flag[x][y]='X';
		if(X==2&&Y==2)
		{
			if(i==2&&x==2||y==2)
			{
				xx=x;
				yy=y;
				if(x==2)
				{
					YY=y;
					XX=rand()%2;
					if(XX==0) XX=1;
					else XX=3;
				}
				if(y==2)
				{
					XX=x;
					YY=rand()%2;
					if(YY==0) YY=1;
					else YY=3;
				}
				cout<<XX<<" "<<YY<<endl;
				Flag[XX][YY]='O';
			}
			else if(i==3&&flag)
			{
				int xxx,yyy;
				if(XX==1) xxx=3;
				else xxx=1;
				if(YY==1) yyy=3;
				yyy=1;
				if(Flag[xxx][yyy]=='-')
				{
					Flag[xxx][yyy]='O';
					cout<<xxx<<" "<<yyy<<endl;
				}
				else
				{
					int XXX,YYY;
					if(xx==2)
					{
						XXX=xxx;
						if(yyy=1) YYY=3;
						else YYY=1;
					}
					if(yy==2)
					{
						YYY=yyy;
						if(xxx=1) XXX=3;
						else XXX=1;
					}
					Flag[XXX][YYY]='O';
					cout<<XXX<<" "<<YYY<<endl;
				}
			}
			else if(i==4&&flag)
			{
				pair<int,int> ans=checkwin();
				int xxx=ans.first,yyy=ans.second;
				cout<<xxx<<" "<<yyy<<endl;
				Flag[xxx][yyy]='O';
			}
			else
			{
				int xxx,yyy;
				pair<int,int> ans;
				ans=checkwin();
				xxx=ans.first,yyy=ans.second;	
				if(xxx!=-1&&yyy!=-1)
				{
					cout<<xxx<<" "<<yyy<<endl;
					Flag[xxx][yyy]='O';
				}
				else
				{
					ans=checklose();
					xxx=ans.first,yyy=ans.second;	
					if(xxx!=-1&&yyy!=-1)
					{
						cout<<xxx<<" "<<yyy<<endl;
						Flag[xxx][yyy]='O';
					}
					else
					{
						ans=checkangle();
						xxx=ans.first,yyy=ans.second;	
						if(xxx!=-1&&yyy!=-1)
						{
							cout<<xxx<<" "<<yyy<<endl;
							Flag[xxx][yyy]='O';
						}
						else
						{
							ans=checkside();
							xxx=ans.first,yyy=ans.second;	
							if(xxx!=-1&&yyy!=-1)
							{
								cout<<xxx<<" "<<yyy<<endl;
								Flag[xxx][yyy]='O';
							}
							else
							{
								int cnt=0;
								int id=0;
								for(int i=1;i<=3;i++)
								{
									for(int j=1;j<=3;j++)
									{
										if(Flag[i][j]=='-') cnt++;
									}
								}
								id=rand()%cnt+1;
								int tmp=0;
								for(int i=1;i<=3;i++)
								{
									for(int j=1;j<=3;j++)
									{
										if(Flag[i][j]=='-')
										{
											tmp++;
											if(id==tmp)
											{
												xxx=i;
												yyy=j;
											}
										}
									}
								}
								cout<<xxx<<" "<<yyy<<endl; 
							}
						}
					}
				}
			}
		}
		else
		{
			pair<int,int> ans;
			int xxx,yyy;
			ans=checkwin();
			xxx=ans.first;
			yyy=ans.second;
			if(xxx!=-1&&yyy!=-1)
			{
				cout<<xxx<<" "<<yyy<<endl;
				Flag[xxx][yyy]='O';
			}
			else
			{
				ans=checklose();
				xxx=ans.first;
				yyy=ans.second;
				if(xxx!=-1&&yyy!=-1)
				{
					cout<<xxx<<" "<<yyy<<endl;
					Flag[xxx][yyy]='O';
				}
				else
				{
					if(Flag[2][2]=='-')
					{
						cout<<2<<" "<<2<<endl;
						Flag[2][2]='O';
					}
					else
					{
						ans=checkangle();
						xxx=ans.first,yyy=ans.second;	
						if(xxx!=-1&&yyy!=-1)
						{
							cout<<xxx<<" "<<yyy<<endl;
							Flag[xxx][yyy]='O';
						}
						else
						{
							ans=checkside();
							xxx=ans.first,yyy=ans.second;	
							if(xxx!=-1&&yyy!=-1)
							{
								cout<<xxx<<" "<<yyy<<endl;
								Flag[xxx][yyy]='O';
							}
							else
							{
								int cnt=0;
								int id=0;
								for(int i=1;i<=3;i++)
								{
									for(int j=1;j<=3;j++)
									{
										if(Flag[i][j]=='-') cnt++;
									}
								}
								id=rand()%cnt+1;
								int tmp=0;
								for(int i=1;i<=3;i++)
								{
									for(int j=1;j<=3;j++)
									{
										if(Flag[i][j]=='-')
										{
											tmp++;
											if(id==tmp)
											{
												xxx=i;
												yyy=j;
											}
										}
									}
								}
								cout<<xxx<<" "<<yyy<<endl; 
							}
						}
					}
				}
			}
		}
		int now=check();
		if(now==-1) 
		{
			quitf(_ok, "you are Won!");
			return 0;
		}
		if(now==1) 
		{
			quitf(0.2, "guessed the number with %20 questions!");
			return 0;
		}
	}
	quitf(0.6, "guessed the number with %60 questions!");
	return 0;
}
2024/6/8 19:52
加载中...