信息学奥赛 1322:【例6.4】拦截导弹问题(Noip1999)

 代码:

#include <bits/stdc++.h>
using namespace std;
int a[100005];
bool a1[100005];
int main(){
    int i = 1; 
    while(cin>>a[i]){
        a1[i] = false;
        i++;
    }
    i--;
    int ant = 0,x = a[1],j = 2,sum = 1;
    a1[1] = true;
    while(sum<=i){
        for(;j<=i;j++){
            if(a[j]<=x && a1[j]==false){
                x = a[j];
                a1[j] = true;
                sum++;
            }
        }
        ant++;
        int t1 = x;
        for(int t = 1;t<=i;t++){
            if(a1[t]==false){
                x = a[t];
                a1[t] = true;
                j = t+1;
                sum++;
                break;
            }
        }
        if(t1==x){
            break;
        }
    }
    cout<<ant;
    return 0;
}

 

posted @ 2024-10-20 14:37  王一行(小号)  阅读(86)  评论(0编辑  收藏  举报