CSP-S2T4/P7078 贪吃蛇

#include <bits/stdc++.h>
using namespace std;
const int mn=1e6+7;
int c[mn];
struct ccf{
	int l,id;
}q1[mn],q2[mn];
int main()
{
	int T;int n;
	cin>>T;
	for(int t=1;t<=T;++t)
	{
		memset(q2,-1,sizeof(q2));
		if(t==1)
		{
			scanf("%d",&n);
			for(int i=n;i>=1;--i)
			{
				scanf("%d",&q1[i].l);
				q1[i].id=n+1-i;
			}
		}	
		else
		{
			int m;
			scanf("%d",&m);
			for(int i=1;i<=m;++i)
			{
				int k,x;
				scanf("%d%d",&k,&x);
				q1[n+1-k].l=x;
			}
		}
		int h1=1,t1=n,h2=1,t2=0,ans=n;
		while(1)
		{
			if((q1[h1].l>q2[h2].l)||(q1[h1].l==q2[h2].l&&q1[h1].id>q2[h2].id))
			{
				q2[++t2].l=q1[h1].l-q1[t1].l;
				q2[t2].id=q1[h1].id;
				++h1;--t1;
			}
			else
			  if((q1[h1].l<q2[h2].l)||(q1[h1].l==q2[h2].l&&q1[h1].id<q2[h2].id))
			  {
			  	q2[++t2].l=q2[h2].l-q1[t1].l;
				q2[t2].id=q2[h2].id;
				++h2;--t1;
			  }
			--ans;
			if(ans<=1||h1>t1||q2[t2].l<q1[t1].l||(q2[t2].l==q1[t1].l&&q2[t2].id<q1[t1].id))
			  break;
		}
		printf("%d\n",ans+(ans+1)%2);
	}
	return 0;
}
posted @ 2020-11-09 15:48  停不下来的奥尔加  阅读(183)  评论(0编辑  收藏  举报