bzoj1972&ljoj2206: [Sdoi2010]猪国杀 - HZH's Blog - 自闭症

bzoj1972&ljoj2206: [Sdoi2010]猪国杀

nbdhhzh posted @ 2014年8月04日 15:47 in 屯题 with tags 乱搞 码农 , 708 阅读

猪国杀啊!

没什么好说的了,写了一个上午还没A掉,下午才发现反猪优先打主猪。。

脑细胞死光光,昨天一直在码农。。

#include<cstdio>
#include<cstring>
using namespace std;
struct player
{
	int id,outid,zgln,head,end,HP,ysb,zsb;
	int card[11];
}pig[11];
int card[2010],allcard[50010],next[50010],pignum[4];
int n,m,l,cardl;
char ch;
char dr()
{
	char ch=getchar();
	while (ch<'A'||ch>'Z')ch=getchar();
	return ch;
}
int cardnum(char ch)
{
	if (ch=='P')return 1;
	if (ch=='K')return 2;
	if (ch=='D')return 3;
	if (ch=='F')return 4;
	if (ch=='N')return 5;
	if (ch=='W')return 6;
	if (ch=='J')return 7;
	if (ch=='Z')return 8;
}
char cardchar(int x)
{
	if (x==1)return 'P';
	if (x==2)return 'K';
	if (x==3)return 'D';
	if (x==4)return 'F';
	if (x==5)return 'N';
	if (x==6)return 'W';
	if (x==7)return 'J';
	if (x==8)return 'Z';
}
int gameend()
{
	if (pignum[3]==0)return 1;
	if (pignum[1]==0)return 2;
	return 0;
}
void getcard(int x,int y)
{
	pig[x].card[y]++;allcard[++cardl]=y;
	if (pig[x].head==0)pig[x].head=cardl,pig[x].end=pig[x].head;
	next[pig[x].end]=cardl;pig[x].end=cardl;
}
void losecard(int x,int y)
{
	pig[x].card[y]--;int last=pig[x].head,i;
	if (allcard[pig[x].head]==y)
	{
		if (pig[x].end==pig[x].head)pig[x].end=0;
		pig[x].head=next[pig[x].head];
		return;
	}
	for (i=next[pig[x].head];i!=0;last=i,i=next[i])
		if (allcard[i]==y)
		{
			next[last]=next[i];
			break;
		}
	if (pig[x].end==i)pig[x].end=last;
}
void Init()
{
	memset(next,0,sizeof(next));
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
	{
		ch=dr();dr();pig[i].HP=4;
		pig[i].zsb=(i+n-2)%n+1;pig[i].ysb=i%n+1;
		if (ch=='M')pignum[pig[i].id=1]++,pig[i].outid=1;
		if (ch=='Z')pignum[pig[i].id=2]++;
		if (ch=='F')pignum[pig[i].id=3]++;
		for (int j=1;j<=4;j++)
			getcard(i,cardnum(dr()));
	}
	for (int i=1;i<=m;i++)card[i]=cardnum(dr());
}
void output()
{
	if (gameend()==1)printf("MP\n");
	if (gameend()==2)printf("FP\n");
	for (int i=1;i<=n;i++)
	{
		if (pig[i].HP<=0)printf("DEAD");else
		{
			for (int j=pig[i].head;next[j]!=0;j=next[j])
				printf("%c ",cardchar(allcard[j]),j);
			if (pig[i].end!=0)printf("%c",cardchar(allcard[pig[i].end]));
		}
		printf("\n");
	}
}
void dead(int x,int y)
{
	pig[pig[y].zsb].ysb=pig[y].ysb;
	pig[pig[y].ysb].zsb=pig[y].zsb;
	pignum[pig[y].id]--;
	if (gameend())return;
	if (pig[y].id==3)
	{
		if (l==m)l--;getcard(x,card[++l]);
		if (l==m)l--;getcard(x,card[++l]);
		if (l==m)l--;getcard(x,card[++l]);
	}
	if (pig[y].id==2&&pig[x].id==1)
	{
		pig[x].zgln=0;
		while (pig[x].head!=0)
			losecard(x,allcard[pig[x].head]);
	}
}
int attack(int x,int y)
{
	if (pig[y].outid==3&&pig[x].id<=2){pig[x].outid=pig[x].id;return 1;}
	if ((pig[y].outid==1||pig[y].outid==2)&&pig[x].id==3){pig[x].outid=pig[x].id;return 1;}
	if (pig[x].id==1&&pig[y].outid==-1)return 1;
	return 0;
}
int protect(int x,int y)
{
	if (pig[y].outid==3&&pig[x].id==3){pig[x].outid=pig[x].id;return 1;}
	if ((pig[y].outid==1||pig[y].outid==2)&&(pig[x].id==1||pig[x].id==2)){pig[x].outid=pig[x].id;return 1;}
	return 0;
}
int askwx(int x,int y,int z)
{
	if (z==1)
	{
		if (pig[y].card[7]>0)if (protect(y,x))
		{losecard(y,7);return askwx(x,y,1-z);}
		for (int i=pig[y].ysb;i!=y;i=pig[i].ysb)
		{
			if (pig[i].card[7]>0)if (protect(i,x))
			{
				losecard(i,7);
				return askwx(x,i,1-z);
			}
		}
	}
	if (z==0)
	{
		if (pig[y].card[7]>0)if (attack(y,x))
		{losecard(y,7);return askwx(x,y,1-z);}
		for (int i=pig[y].ysb;i!=y;i=pig[i].ysb)
			if (pig[i].card[7]>0)if (attack(i,x))
			{
				losecard(i,7);
				return askwx(x,i,1-z);
			}
	}
	return 1-z;
}
void hit(int x,int y)
{
	if (pig[y].id==1&&pig[x].outid==0)pig[x].outid=-1;pig[y].HP--;
	if (pig[y].HP<=0)
	{
		while (pig[y].card[1]>0&&pig[y].HP<=0)losecard(y,1),pig[y].HP++;
		if (pig[y].HP<=0)dead(x,y);
	}
}
int usecard(int x,int y,int &usegs)
{
	if (y==1&&pig[x].HP<4){pig[x].HP++;return 1;}
	if (y==2)
	{
		if (usegs&&!pig[x].zgln)return 0;
		if (attack(x,pig[x].ysb))
		{
			usegs=1;
			if (pig[pig[x].ysb].card[3]<=0)hit(x,pig[x].ysb);
			else losecard(pig[x].ysb,3);
			return 1;
		}
	}
	if (y==3)return 0;
	if (y==4)
	{
		for (int i=pig[x].ysb;i!=x;i=pig[i].ysb)
		if (attack(x,i)&&(!(pig[x].id==3)||pig[i].id==1))
		{
			if (askwx(i,x,1))return 1;
			if (x==1&&pig[i].id==2){hit(x,i);return 1;}
			if (pig[x].card[2]>=pig[i].card[2])
			{
				for (int j=1;j<=pig[i].card[2];j++)
					losecard(x,2),losecard(i,2);
				hit(x,i);
			}else 
			{
				for (int j=1;j<=pig[x].card[2];j++)
					losecard(x,2),losecard(i,2);
				losecard(i,2);hit(i,x);
			}
			return 1;
		}
	}
	if (y==5)
	{
		for (int i=pig[x].ysb;i!=x;i=pig[i].ysb)
		{
			if (!askwx(i,x,1))
			{
				if (pig[i].card[2]>0)losecard(i,2);
				else hit(x,i);
			}
			if (gameend())return 1;
		}
		return 1;
	}
	if (y==6)
	{
		for (int i=pig[x].ysb;i!=x;i=pig[i].ysb)
		{
			if (!askwx(i,x,1))
			{
				if (pig[i].card[3]>0)losecard(i,3);
				else hit(x,i);
			}
			if (gameend())return 1;
		}
		return 1;
	}
	if (y==7)return 0;
	if (y==8){pig[x].zgln=1;return 1;}
	return 0;
}
void pigsturn(int x)
{
	int i,kgm=0;
	if (l==m)l--;getcard(x,card[++l]);
	if (l==m)l--;getcard(x,card[++l]);
	while (pig[x].HP>0&&!gameend())
	{
		for (i=pig[x].head;i!=0;i=next[i])
			if (usecard(x,allcard[i],kgm))break;
		if (i==0)break;
		losecard(x,allcard[i]);
	}
}
void play()
{
	int turn=1;
	while (!gameend())
	{
		pigsturn(turn);
		turn=pig[turn].ysb;
	}
}
int main()
{
	Init();
	play();
	output();
}
Avatar_small
JDC Result rajshahi 说:
2022年8月30日 20:08

The Rajshahi Board is also completed the Junior School Certificate and Junior Dakil (Grade-8) terminal exams successfully under Secondary and Higher Secondary Education Board, and a huge number of students have appeared from all districts of Rajshahi Division, and those subject wise exams are completed between 1st to 3rd weeks at all schools across the country along with the divisional schools to the academic year of 2022. Both of JSC & JDC students are waiting to check their exam result with full marksheet in student wise to get total GPA grade for this year terminal exams, JDC Result rajshahi Grade 8th standard is the most important examination for secondary education in the country and this is gateway to secondary education in the country, and the school education department will announce student wise result with total marksheet online and this year also published same like as previous years.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter
Host by is-Programmer.com | Power by Chito 1.3.3 beta | © 2007 LinuxGem | Design by Matthew "Agent Spork" McGee