Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 31611 Accepted Submission(s): 12412
8 389 207 155 300 299 170 158 65
2
做法:每次按拦截完将当前高度更新,一直往后扫,直到拦截完所有导弹(这题很多题解有BUG,一些数据是错误的,也许我这份代码也有错误)
代码:
#include<iostream> #include<algorithm> #include<cstdlib> #include<sstream> #include<cstring> #include<cstdio> #include<string> #include<deque> #include<cmath> #include<queue> #include<set> #include<map> using namespace std; int pos[100010]; int main (void) { ios::sync_with_stdio(false); int t,n,i,j,ans; while (cin>>n) { memset(pos,0,sizeof(pos)); for (i=0; i<n; i++) { cin>>pos[i]; } int temp=pos[0]; int cnt=0,ans=0; for (i=0; i<n; i++) { if(pos[i]!=-1) { temp=pos[i]; for (j=i; j<n; j++) { if(pos[j]!=-1&&pos[j]<=temp) { temp=pos[j];//更新拦截高度 pos[j]=-1;//标记已拦截过 cnt++;//拦截数更新 } } ans++;//拦截一轮加一套防御系统 } if(cnt==n)//全部拦截完毕,break { break; } } cout<<ans<<endl; } return 0; }