QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#21363#2821. 鸭棋DaBenZhongXiaSongKuaiDi#AC ✓3ms3732kbC++205.0kb2022-03-04 17:00:542022-05-08 02:56:03

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-08 02:56:03]
  • 评测
  • 测评结果:AC
  • 用时:3ms
  • 内存:3732kb
  • [2022-03-04 17:00:54]
  • 提交

answer

#include<iostream>
#include<cstdio>
using namespace std;
inline int read()
{
	int n=0,f=1,ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		n=n*10+ch-'0';
		ch=getchar();
	}
	return n*f;
}
int a[11][11];
//1=王 2=士 3=象 4=马 5=车 6=兵 7=鸭
int jdz(int x)
{
	if(x<0)return -x;
	return x;
}
bool check(int x1,int y1,int x2,int y2)
{
	if(a[x1][y1]*a[x2][y2]>0)
	{
		return false;
	}
	if(a[x1][y1]==1||a[x1][y1]==-1)
	{
		if(jdz(x2-x1)+jdz(y2-y1)!=1)
		{
			return false;
		}
		return true;
	}
	if(a[x1][y1]==2||a[x1][y1]==-2)
	{
		if(jdz(x2-x1)==1&&jdz(y2-y1)==1)return true;
		return false;
	}
	if(a[x1][y1]==3||a[x1][y1]==-3)
	{
		if(jdz(x2-x1)!=2||jdz(y2-y1)!=2)return false;
		int sx=(x2-x1)/2,sy=(y2-y1)/2;
		if(a[x1+sx][y1+sy]!=0)return false;
		return true;
	}
	if(a[x1][y1]==4||a[x1][y1]==-4)
	{
		if(jdz(x2-x1)==2&&jdz(y2-y1)==1)
		{
			int sx=(x2-x1)/2,sy=(y2-y1);
			if(a[x1+sx][y1]!=0)return false;
			return true;
		}
		if(jdz(x2-x1)==1&&jdz(y2-y1)==2)
		{
			int sx=x2-x1,sy=(y2-y1)/2;
			if(a[x1][y1+sy]!=0)return false;
			return true;
		}
		return false;
	}
	if(a[x1][y1]==5||a[x1][y1]==-5)
	{
		if(x2==x1&&y2==y1)return false;
		if(x2==x1)
		{
			if(y2<=y1)
			{
				for(int j=y2+1;j<=y1-1;j++)if(a[x1][j]!=0)return false;
				return true;
			}
			else
			{
				for(int j=y1+1;j<=y2-1;j++)if(a[x1][j]!=0)return false;
				return true;
			}
		}
		if(y2==y1)
		{
			//printf("orz%d %d %d %d\n",x1,y1,x2,y2);
			if(x2<=x1)
			{
				for(int j=x2+1;j<=x1-1;j++)if(a[j][y1]!=0){return false;}
				return true;
			}
			else
			{
				for(int j=x1+1;j<=x2-1;j++)if(a[j][y1]!=0){return false;}
				return true;
			}
		}
		return false;
	}
	if(a[x1][y1]==-6||a[x1][y1]==6)
	{
		if(jdz(x1-x2)<=1&&jdz(y2-y1)<=1)return true;
		return false;
	}
	if(a[x1][y1]==-7||a[x1][y1]==7)
	{
		if(jdz(x1-x2)==3&&jdz(y1-y2)==2)
		{
			int sx=(x2-x1)/3,sy=(y2-y1)/2;
			if(a[x1+sx][y1]!=0||a[x1+2*sx][y1+sy]!=0)return false;
			return true;
		}
		if(jdz(x1-x2)==2&&jdz(y1-y2)==3)
		{
			int sx=(x2-x1)/2,sy=(y2-y1)/3;
			if(a[x1][y1+sy]!=0||a[x1+sx][y1+2*sy]!=0)return false;
			return true;
		}
		return false;
	}
}
int main()
{
	int q,n,m,x1,y1,x2,y2;
	q=read();
	a[1][1]=5;
	a[1][2]=4;
	a[1][3]=3;
	a[1][4]=2;
	a[1][5]=1;
	a[1][6]=2;
	a[1][7]=3;
	a[1][8]=4;
	a[1][9]=5;
	a[4][1]=a[4][3]=a[4][5]=a[4][7]=a[4][9]=6;
	a[3][1]=a[3][9]=7;
	a[10][1]=-5;
	a[10][2]=-4;
	a[10][3]=-3;
	a[10][4]=-2;
	a[10][5]=-1;
	a[10][6]=-2;
	a[10][7]=-3;
	a[10][8]=-4;
	a[10][9]=-5;
	a[7][1]=a[7][3]=a[7][5]=a[7][7]=a[7][9]=-6;
	a[8][1]=a[8][9]=-7;
	int hf=0,sth;
	bool flag=true;
	for(int i=1;i<=q;i++)
	{
		x1=read()+1;
		y1=read()+1;
		x2=read()+1;
		y2=read()+1;
		//printf("???%d\n",a[x1][y1]);
		if(flag==false)
		{
			printf("Invalid command\n");
			continue;
		}
		if(x1<1||x1>10||y1<1||y1>9||x2<1||x2>10||y2<1||y2>9)
		{
			printf("Invalid command\n");
			continue;
		}
		if(a[x1][y1]==0)
		{
			printf("Invalid command\n");
			continue;
		}
		if(hf==0&&a[x1][y1]<0)
		{
			printf("Invalid command\n");
			continue;
		}
		if(hf==1&&a[x1][y1]>0)
		{
			printf("Invalid command\n");
			continue;
		}
		if(check(x1,y1,x2,y2)==false)
		{
			printf("Invalid command\n");
			continue;
		}
		if(hf==0)printf("red ");
		else printf("blue ");
		if(jdz(a[x1][y1])==1)printf("captain;");
		else if(jdz(a[x1][y1])==2)printf("guard;");
		else if(jdz(a[x1][y1])==3)printf("elephant;");
		else if(jdz(a[x1][y1])==4)printf("horse;");
		else if(jdz(a[x1][y1])==5)printf("car;");
		else if(jdz(a[x1][y1])==6)printf("soldier;");
		else printf("duck;");
		if(a[x2][y2]==0)printf("NA;");
		else
		{
			if(hf==0)printf("blue ");
			else printf("red ");
			if(jdz(a[x2][y2])==1)printf("captain;");
			else if(jdz(a[x2][y2])==2)printf("guard;");
			else if(jdz(a[x2][y2])==3)printf("elephant;");
			else if(jdz(a[x2][y2])==4)printf("horse;");
			else if(jdz(a[x2][y2])==5)printf("car;");
			else if(jdz(a[x2][y2])==6)printf("soldier;");
			else printf("duck;");
		}
		if(hf==0&&a[x2][y2]==-1)
		{
			flag=false;
			printf("no;yes\n");
			continue;
		}
		if(hf==1&&a[x2][y2]==1)
		{
			flag=false;
			printf("no;yes\n");
			continue;
		}
		a[x2][y2]=a[x1][y1];
		a[x1][y1]=0;
			sth=0;
			for(int i=1;i<=10;i++)
			{
				for(int j=1;j<=9;j++)
				{
					if(a[i][j]==-1)
					{
						//printf("%d %d\n",i,j);
						for(int k=1;k<=10;k++)
						{
							for(int l=1;l<=9;l++)
							{
								if(a[k][l]>0&&check(k,l,i,j))/*printf("orz%d %d %d %d\n",k,l,i,j),*/sth=1;
							}
						}
					}
				}
			}
			for(int i=1;i<=10;i++)
			{
				for(int j=1;j<=9;j++)
				{
					if(a[i][j]==1)
					{
						//printf("%d %d\n",i,j);
						for(int k=1;k<=10;k++)
						{
							for(int l=1;l<=9;l++)
							{
								if(a[k][l]<0&&check(k,l,i,j))/*printf("orz%d %d %d %d\n",k,l,i,j),*/sth=1;
							}
						}
					}
				}
			}
			if(sth==1)printf("yes;no\n");
			else printf("no;no\n");
			hf^=1;
	}
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 3588kb

input:

18
0 0 7 0
9 0 8 0
0 1 1 3
0 2 2 0
0 3 1 2
0 4 0 3
9 4 8 4
3 2 2 3
7 0 4 2
7 0 5 3
9 2 7 4
2 0 4 3
9 1 8 3
4 3 6 6
7 4 9 2
8 4 9 4
6 6 9 4
9 8 8 8

output:

Invalid command
Invalid command
Invalid command
Invalid command
red guard;NA;no;no
Invalid command
blue captain;NA;no;no
red soldier;NA;no;no
Invalid command
Invalid command
blue elephant;NA;no;no
red duck;NA;no;no
blue horse;NA;no;no
red duck;blue soldier;no;no
Invalid command
blue captain;NA;yes;n...

result:

ok 18 lines

Test #2:

score: 0
Accepted
time: 3ms
memory: 3732kb

input:

1000
0 7 2 6
3 8 4 8
3 0 4 0
0 6 8 6
0 3 1 4
6 2 5 3
6 0 5 0
0 4 1 4
9 7 7 6
9 5 8 4
9 5 8 6
7 0 3 2
3 0 2 1
9 2 7 4
5 3 4 2
1 4 2 4
0 1 2 2
6 0 7 1
9 5 8 4
2 6 1 4
2 1 1 2
2 8 8 1
9 8 8 8
6 6 7 7
7 4 9 2
8 8 8 0
2 0 5 2
2 8 6 1
1 7 1 1
0 3 1 2
3 8 3 7
9 0 8 0
0 3 1 2
3 4 2 5
9 6 9 4
6 4 5 5
4 2 7 4...

output:

red horse;NA;no;no
Invalid command
Invalid command
Invalid command
Invalid command
blue soldier;NA;no;no
Invalid command
red captain;NA;no;no
blue horse;NA;no;no
Invalid command
Invalid command
Invalid command
red soldier;NA;no;no
blue elephant;NA;no;no
Invalid command
red captain;NA;no;no
Invalid c...

result:

ok 1000 lines

Test #3:

score: 0
Accepted
time: 3ms
memory: 3632kb

input:

1000
3 8 4 1
6 2 8 2
0 0 1 5
9 7 7 6
0 7 8 7
9 5 8 6
5 4 1 0
9 7 6 4
9 7 0 3
2 0 3 0
9 3 8 0
2 8 9 2
7 5 7 8
9 5 8 6
9 6 8 2
6 2 6 3
0 7 1 7
9 1 7 2
1 7 0 5
7 0 8 5
9 5 0 4
3 4 4 5
0 6 8 8
6 2 5 1
9 5 8 4
0 1 2 1
0 3 2 4
2 7 8 5
9 8 8 8
0 0 1 0
3 2 7 3
3 0 0 1
0 5 9 4
9 2 7 4
0 1 2 2
9 7 1 0
6 6 6 5...

output:

Invalid command
Invalid command
Invalid command
Invalid command
Invalid command
Invalid command
Invalid command
Invalid command
Invalid command
Invalid command
Invalid command
Invalid command
Invalid command
Invalid command
Invalid command
Invalid command
Invalid command
Invalid command
Invalid comm...

result:

ok 1000 lines

Test #4:

score: 0
Accepted
time: 3ms
memory: 3632kb

input:

1000
6 4 5 5
9 1 4 5
9 7 5 8
9 4 8 4
0 6 5 1
0 3 5 5
0 3 5 5
9 7 6 2
2 8 9 6
9 5 5 8
0 4 1 4
0 0 5 6
0 7 3 5
2 8 7 8
0 5 6 8
7 8 9 8
9 2 9 3
0 3 1 2
3 2 5 5
0 5 1 6
3 6 5 6
3 2 1 1
0 5 6 7
9 5 3 4
3 0 2 4
3 4 6 3
9 7 8 7
0 6 9 1
6 8 8 4
6 8 6 3
6 0 5 7
2 0 8 7
9 8 4 0
0 7 3 8
0 3 5 2
2 0 1 7
3 2 0 3...

output:

Invalid command
Invalid command
Invalid command
Invalid command
Invalid command
Invalid command
Invalid command
Invalid command
Invalid command
Invalid command
red captain;NA;no;no
Invalid command
Invalid command
Invalid command
Invalid command
Invalid command
Invalid command
Invalid command
Invalid...

result:

ok 1000 lines