社区讨论
救命!bebug一小时没看出哪里错了!加急
B3784[语言月赛202306] 演唱会参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @mjcwstkb
- 此快照首次捕获于
- 2025/12/19 21:32 3 个月前
- 此快照最后确认于
- 2025/12/21 15:05 3 个月前
CPP
#include<bits/stdc++.h>
using namespace std;
int student[10005][10005];
struct song{
int h,id;
}songs[105];
bool cmp(song x,song y){
return x.h>y.h;
}
int main()
{
int n,m,a,b;
cin>>n>>m>>a>>b;
int maxn=-9999,maxid=-85;
for(int i=1;i<=a;i++){
for(int j=1;j<=n;j++){
cin>>student[i][j];
if(i==b){
if(student[i][j]>maxn){
maxn=student[i][j];
maxid=j;
}
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=a;j++){
songs[i].h+=student[j][i];
}
songs[i].id=i;
}
sort(songs+1,songs+n+1,cmp);
vector<int> songs2;
bool flag=false;
songs2.push_back(-11);
for(int i=1;i<=m;i++){
songs2.push_back(songs[i].id);
if(maxid==songs2[i]){
flag=true;
songs2.pop_back();
songs2.insert(songs2.begin(),maxid);
}
}
if(flag==false){
songs2.pop_back();
songs2.push_back(maxid);
}
for(int i=1;i<=m;i++)
cout<<songs2[i]<<" ";
return 0;
}
/*
4 3 3 2
2 4 3 1
1 2 3 4
2 3 4 1
*/
回复
共 1 条回复,欢迎继续交流。
正在加载回复...