1 条题解

  • 0
    @ 2025-4-7 21:41:58

    C++ :

    #include <iostream>
    using namespace std;
    void Max_plus_1(int *p,double **pp,int k){
    	int max = 0;
    	for(int i=1;i<k;i++)
    			if(pp[max][p[max]] < pp[i][p[i]])
    				max = i;
    	p[max]++;
    }
    void maxAi(double **pp,int k,int m){
    	int *p = new int[k];
    	int i;
    	for(i=0;i<k;i++)
    		p[i] = 0;
    	m -= k;
    	if(m<=0){
    		int q = k+m;
    		while(q--)
    			Max_plus_1(p,pp,k);
    		cout<<p[0];
    		for(i=1;i<k;i++)
    			cout<<" "<<p[i];
    		cout<<endl;
    		delete[] p;
    		return ;
    	}
    	while(m--)
    		Max_plus_1(p,pp,k);
    	cout<<p[0]+1;
    	for(i=1;i<k;i++)
    		cout<<" "<<p[i]+1;
    	cout<<endl;
    	delete[] p;	
    }
    void minAi(double **pp,int k,int m){
    	int *p = new int[k];
    	int i;
    	for(i=0;i<k;i++)
    		p[i] = 1;
    	m -= k;
    	if(m<=0){
    		int q = k+m;
    		while(q--)
    			Max_plus_1(p,pp,k);
    		cout<<p[0]-1;
    		for(i=1;i<k;i++)
    			cout<<" "<<p[i]-1;
    		cout<<endl;
    		delete[] p;
    		return ;
    	}	
    	while(m--)
    		Max_plus_1(p,pp,k);
    	cout<<p[0];
    	for(i=1;i<k;i++)
    		cout<<" "<<p[i];
    	cout<<endl;
    	delete[] p;
    }
    int main(){
    	int flag=0;
    	for(int k,m;cin>>k>>m;){
    		int i,j;
    		double **pp = new double*[k];
    		for(i=0;i<k;i++)
    			pp[i] = new double[m];
    		for(i=0;i<k;i++)
    			cin>>pp[i][0];
    		for(i=0;i<k;i++){
    			for(j=1;j<m;j++)
    				pp[i][j] = pp[i][0] / (j+1);
    		}
    		if(flag++)
    			cout<<endl;
    		maxAi(pp,k,m);
    		minAi(pp,k,m);
    		for(i=0;i<k;i++)
    			delete[] pp[i];
    	}
    	return 0;
    }
    
    
    • 1

    信息

    ID
    2133
    时间
    1000ms
    内存
    64MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者