疑似不正经题解(?)
2026-08-31 19:29:02
发布于:江苏
7阅读
0回复
0点赞
应该是暑假最后一舞把
//我的马蜂怎么这么奇特
#include<bits/stdc++.h>
using namespace std;
struct stu{
int h;//身高
int w;//体重
}st[3010];//=stu st[3010];
bool cmp(stu x,stu y){
if(x.h != y.h)//如果身高不同
return x.h<y.h;{//如果身高升序-无需交换,返回false 否则需要交换-返回true
else if(x.w != y.w)//如果体重不同
return x.w<y.w;//如果体重升序-无需交换,返回false 否则需要交换-返回true
}
int main(){
int n;
cin>>n;
int ans=0;//交换次数
for(int i=1;i <= n;i++){
cin>>st[i].h>>st[i].w;//输入身高、体重
}
for(int i=1;i <= n;i++){
for(int j=2;j <= n;j++){
if(cmp(st[j-1],st[j])){
swap(st[j-1],st[j]);//交换
ans++;//累加
}
}
}
cout << ans;
}
也不知道怎么想出来这么猎奇的方法的(((
这里空空如也








有帮助,赞一个