50分求正解
  • 板块P9815 wbyblD
  • 楼主Sun_Island
  • 当前回复3
  • 已保存回复3
  • 发布时间2023/10/30 13:10
  • 上次更新2023/11/3 22:56:55
查看原帖
50分求正解
838333
Sun_Island楼主2023/10/30 13:10

看见讨论群的大佬说这题没有黄题难度,可是本蒟蒻只能拿50pts,求大佬指点

#include <iostream>
using namespace std;
const int maxn=1e6+10;

int t,n,x,y;
int a[maxn],b[maxn];
int main(){
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        x=0,y=1;
        a[0]=b[0]=a[n+1]=b[n+1]=0;
        for(int i=1; i<=n; i++) scanf("%d%d",&a[i],&b[i]);
        while(true){
            if((!x&&y==-1) or (y==1&&x==n+1)) break;
            if(y==1){
                x++;
                if(a[x]>0) y=-1;
                a[x]--;
            }
            else if(y==-1){
                x--;
                if(b[x]>0) y=1;
                b[x]--;
            }
        }
        printf("%d\n",x);
    }
    return 0;
}

2023/10/30 13:10
加载中...