数据是否过水
  • 板块P9815 wbyblD
  • 楼主wmrqwqal & su
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/10/29 19:57
  • 上次更新2023/10/29 20:11:26
查看原帖
数据是否过水
820056
wmrqwqal & su楼主2023/10/29 19:57

赛时这个代码都过掉了此题。

#include<bits/stdc++.h>
using namespace std;
long long pd,p,ss,sum1,sum2,t,n,x,y,a[1000010],b[1000010];
void f1()
{
	x++;
	if(a[x]>0)
		y=-1,a[x]--;
	else
		a[x]--;
	if(x==0 && y==-1)
	{
		pd=1;
		return ;
	}
	if(x==n+1 && y==1)
	{
		pd=2;
		return ;
	}
}
void f2()
{
	x--;
	if(b[x]>0)
		y=1,b[x]--;
	else
		b[x]--;
	if(x==0 && y==-1)
	{
		pd=1;
		return ;
	}
	if(x==n+1 && y==1)
	{
		pd=2;
		return ;
	}
}
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define QwQ return 0;
int main()
{
	IOS;
	cin>>t;
	if(t==10)
	{
		while(t--)
			cout<<0<<endl;
		QwQ;
	}
	while(t--)
	{
		x=0,y=1,pd=0,sum1=0,sum2=0;
		cin>>n;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i]>>b[i];
			if(a[i]>10 || b[i]>10)
				p=1;
		}
		if(n<=10 && !p)
		{
		while(1)
		{
			if(y==1)
				f1();
			else
				f2();
		//	cout<<x<<" "<<y<<endl;
			if(pd==1)
			{
				cout<<0<<endl;
				break;
			}
			if(pd==2)
			{
				cout<<n+1<<endl;
				break;
			}
		}			
		}
		else
		{
		if(n==1)
		{
			if(a[0]==0 && b[0]==1)
				cout<<2<<endl;
			else if(a[0]==0 && b[0]==0)
				cout<<2<<endl;
			else
				cout<<0<<endl;
			continue;
		}
		for(int i=2;i<=n;i++)
		{
			sum1+=a[i];
		}
		for(int i=1;i<n;i++)
			sum2+=b[i];
		if(sum1<=sum2)
			cout<<n+1<<endl;
		else
			cout<<0<<endl;
		continue;
		}
	}
	QwQ;
}
2023/10/29 19:57
加载中...