测试点7

P1568 赛跑

$\texttt{int}$ 可以过啊
by AC_CSP @ 2022-11-11 18:25:49


? 我全程int过了 ```cpp #include<iostream> #include<cstdio> #define rii register int i #define rij register int j using namespace std; int place_sh[1000005],place_kc[1000005],n,m; int time_sh,time_kc,cnt; int main() { cin>>n>>m; for(rii=1;i<=n;i++) { int speed,time; cin>>speed>>time; for(rij=1;j<=time;j++) { time_sh++; place_sh[time_sh]=place_sh[time_sh-1]+speed; } } for(rii=1;i<=m;i++) { int speed,time; cin>>speed>>time; for(rij=1;j<=time;j++) { time_kc++; place_kc[time_kc]=place_kc[time_kc-1]+speed; } } int min_time=min(time_kc,time_sh); int bol=0; for(rii=1;i<=min_time;i++) { if(place_sh[i]<place_kc[i]) { if(bol==-1) { continue; } else { bol=-1; cnt++; } } if(place_sh[i]>place_kc[i]) { if(bol==1) { continue; } else { bol=1; cnt++; } } } if(cnt!=0) { cnt--; } cout<<cnt; } ```
by ztz11 @ 2022-11-11 18:34:06


@[AC_CSP](/user/481527) 不知道,反正我把数据类型改为long long 就AC了
by 段落 @ 2022-11-12 12:48:11


@[段落](/user/392327) ``` s=l1-l2; if(s*f<0) { cnt++; f=s; } ``` 如果s=1e5,f=1e5相乘就爆int了,然后得一个负数。所以建议你s赋值时用l1<l2这样的布尔型,这样s只能为0或者1,就不会爆int了
by Chenyufeng040525 @ 2023-05-30 18:14:44


谢谢@[Chenyufeng040525](/user/929850)
by 段落 @ 2023-05-30 18:56:57


|