标签:algorithm == space algo std main else col lse
完全弹性碰撞可以视作互相穿过
所以直接考虑只有单个小球的时候,从板子上滑下所需要的时间即可
最后以30000为界分开流读入与缓冲区优化的io方法
//Case4用缓冲区io优化会WA???
1 /* 2 Written By StelaYuri 3 */ 4 #pragma GCC optimize(3) 5 #include<iostream> 6 #include<algorithm> 7 #include<cctype> 8 using namespace std; 9 int pos[1000000],dir[1000000],ans[1000000]; 10 const int bsz=1<<16; 11 char bf[bsz],*head,*tail; 12 inline char gc() 13 { 14 if(head==tail) 15 { 16 int l=fread(bf,1,bsz,stdin); 17 tail=(head=bf)+l; 18 } 19 return *head++; 20 } 21 inline int read() 22 { 23 int x=0,f=1;char c=gc(); 24 for(;!isdigit(c);c=gc()) 25 if(c==‘-‘) 26 f=-1; 27 for(;isdigit(c);c=gc()) 28 x=x*10+c-‘0‘; 29 return x*f; 30 } 31 inline void write(int x) 32 { 33 if(x>=10) 34 write(x/10); 35 putchar(x%10+‘0‘); 36 } 37 int main() 38 { 39 ios::sync_with_stdio(0); 40 cin.tie(0);cout.tie(0); 41 int i,vd,nl,n,m,L; 42 cin>>n>>m>>L; 43 if(n>30000) 44 { 45 for(i=0;i<n;i++) 46 pos[i]=read(); 47 for(i=0;i<n;i++) 48 dir[i]=read(); 49 for(i=0;i<n;i++) 50 { 51 vd=read(); 52 if(dir[i]) 53 nl=L+1-pos[i]; 54 else 55 nl=pos[i]; 56 ans[i]=nl/vd+(nl%vd?1:0); 57 } 58 sort(ans,ans+n); 59 write(ans[n-m-1]); 60 } 61 else 62 { 63 for(i=0;i<n;i++) 64 cin>>pos[i]; 65 for(i=0;i<n;i++) 66 cin>>dir[i]; 67 for(i=0;i<n;i++) 68 { 69 cin>>vd; 70 if(dir[i]) 71 nl=L+1-pos[i]; 72 else 73 nl=pos[i]; 74 ans[i]=nl/vd+(nl%vd?1:0); 75 } 76 sort(ans,ans+n); 77 cout<<ans[n-m-1]; 78 } 79 80 return 0; 81 }
标签:algorithm == space algo std main else col lse
原文地址:https://www.cnblogs.com/stelayuri/p/12235271.html