P2338 [USACO14JAN]失败的滑雪Bessie Slows Down
模拟
1 #include<bits/stdc++.h> 2 using namespace std; 3 int n,m,v; 4 int num1,num2,now1,now2; 5 double t[100000],d[100000],nows,nowt; 6 char a; 7 int main() 8 { 9 scanf("%d",&n); 10 for(int i=1;i<=n;i++) 11 { 12 cin>>a>>m; 13 if(a==‘T‘) t[++num1]=m; 14 else d[++num2]=m; 15 } 16 sort(d+1,d+num2+1); 17 sort(t+1,t+num1+1); 18 v=1; now1=1; now2=1; 19 for(int i=1;i<=n;i++) 20 { 21 if((now2>num2||(d[now2]-nows)*v+nowt>=t[now1])&&(now1<=num1)) 22 { 23 if((t[now1]-nowt)/v+nows>1000) break; 24 nows+=(t[now1]-nowt)/v; nowt=t[now1]; v++; now1++; 25 } 26 else 27 { 28 if(d[now2]>1000) break; 29 nowt+=(d[now2]-nows)*v; nows=d[now2]; v++; now2++; 30 } 31 } 32 cout<<int((1000-nows)*v+nowt+0.499999); 33 return 0; 34 }
时间: 2024-10-20 09:19:38