5 solutions

  • 2
    @ 2024-1-27 11:34:49

    题意

    一个越打越低的防导弹系统,求多少个系统能打完全部导弹

    思路

    当第 ai+1a_{i+1} 个导弹的高度大于第 ii 个导弹,就加 1 个系统

    代码

    #include <bits/stdc++.h>
    using namespace std;
    int a[100005],f[100005],idx,cnt,t;
    int n;
    bool pd(){
    	for (int i = 1;i <= n;i++){
    		if (!f[i])	return 1;
    	}
    	return 0;
    }
    int main(int argc, char **argv){
    	while (cin >> a[++idx])	n++;
    	while (pd()){	// 如果还有没打下来的导弹
    		t = 30001;
    		for(int i = 1;i <= n;i++){
    			if (!f[i]){	// 如果导弹没被打下来
    				if (a[i] <= t){
    					t = a[i];
    					f[i] = 1;
    				}
    			}
    		}
    		cnt++;
    	}
    	cout << cnt;
    	return 0;
    }
    
    

    Information

    ID
    807
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    6
    Tags
    # Submissions
    95
    Accepted
    30
    Uploaded By