90分求调(有谜之注释
查看原帖
90分求调(有谜之注释
1260091
_people楼主2024/8/13 20:05
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
int n,m,a,b;
int h[110][10010];
PII sumh[10010];//前欢乐值,后编号 
PII ta;
bool cmp(PII a,PII b){
	return a.first>b.first;//优先排大的 
}
int main(){
	scanf("%d%d%d%d",&n,&m,&a,&b);
	for(int i=1;i<=a;i++){
		for(int j=1;j<=n;j++){
			scanf("%d",&h[i][j]);
			if(i==b&&ta.first<h[i][j]){
				ta.second=j;//记录“她”最喜欢的歌的编号
				ta.first=h[i][j];//同时记录欢乐值用于找最大值 
			}
		}
	}
	for(int j=1;j<=n;j++){
		int sum=0;
		for(int i=1;i<=a;i++) sum+=h[i][j];
		sumh[j]=(PII){sum,j};//记录每首歌的总欢乐值与各自的编号 
	}
	sort(sumh+1,sumh+1+n,cmp);//从大到小排序 
	for(int i=1;i<=m;i++){
		if(sumh[i].second==ta.second){//找到“她”的歌 
			for(int j=1;j<i;j++) swap(sumh[j].second,sumh[i].second);
			//移位,把最后一位一直与第一位交换 
			for(int j=1;j<=m;j++) printf("%d ",sumh[j].second);//输出 
			return 0;//终止 
		}
	}
	sumh[m].second=ta.second;//把最后一位(第m位)替换为“她”的歌 
	for(int j=1;j<=m;j++) printf("%d ",sumh[j].second);//输出 
	return 0;
}

rt

2024/8/13 20:05
加载中...