Luogu P1568 Race Problem Solution

topic portal

This question is very watery, as long as you can figure out the meaning of the question, don't mix SH and KC (so I used a structure)

#include<bits/stdc++.h>
using namespace std;
int n,m,T,ans;
int now=-1;
struct node{
    int a[1010],b[1010];
    int p;
    int N;
}SH,KC;
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i) scanf("%d%d",&SH.a[i],&SH.b[i]);
    for(int i=1;i<=m;++i) scanf("%d%d",&KC.a[i],&KC.b[i]);
    for(int i=1;i<=n;++i) T+=SH.b[i];
    SH.p=1;KC.p=1;
//    puts("");
    for(int i=1;i<=T;++i){
        if(SH.b[SH.p]<=0) SH.p++;
        if(KC.b[KC.p]<=0) KC.p++;
        SH.N+=SH.a[SH.p];KC.N+=KC.a[KC.p];
        if(SH.N<KC.N){
            if(now==-1) now=2;
            else if(now!=2) ans++,now=2;
        }else if(SH.N==KC.N){
        }else{
            if(now==-1) now=1;
            else if(now!=1) ans++,now=1;
        }
        --SH.b[SH.p];--KC.b[KC.p];
//        cout<<SH.N<<" "<<KC.N<<endl;
    }
    printf("%d\n",ans);return 0;
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325282222&siteId=291194637