文章

10

粉丝

179

获赞

5

访问

27.1k

头像
使用第二个数组进行辅助记录(C++)
P1677 中南大学2017年机试题
发布于2023年2月13日 16:47
阅读数 2.9k


#include <bits/stdc++.h>
using namespace std; 
typedef long long ll;
const int INF=1e9;

const int maxn=1e7+10;
int N=0,M=0,K=0,Q=0,n=0,m=0,a=0,b=0,c=0;
string str,stra,strb,strc;
int x,y;
ll sum=0,ksum=0,cnt;

bool flag=false;//记录本次是否应该建立新的队伍
int shu1[100001],shu2[100001];

int main(){
    
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int k=0;
    while(cin>>n){
        for(int i=0;i<n;i++) cin>>shu1[i];//输入小朋友的身高
       
        for(int i=0;i<n;i++){
            for(int j=0;j<k;j++){
                if(shu2[j]>=shu1[i]){//将每队的最小值与当前值做比较,看是否允许加入
                    shu2[j]=shu1[i];
                    flag=true;
                    break;
                }
            }
            if(flag==false) shu2[k++]=shu1[i];//如果都不允许加入,说明可以建立新的队伍
            else flag=false;
        }
        cout<<k<<endl;
        flag=false;
        k=0;
        
    }
    

     return 0;
 }
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发