https://www.luogu.org/problem/P1056
#include<bits/stdc++.h> using namespace std; struct aisle { int hs; int num; } hen[10001],shu[10001]; bool cmp(aisle ta,aisle tb) { return ta.num>tb.num; //按分割的数目从大到小排序 } bool cmp2(aisle ta,aisle tb) { return ta.hs<tb.hs; //按横或竖的序号排序 } int m,n,k,l,d,h,s; int main() { cin>>m>>n>>k>>l>>d; int x1,y1,x2,y2; for(int i=1; i<=n; i++) hen[i].hs=i; for(int i=1; i<=m; i++) shu[i].hs=i; for(int i=1; i<=d; i++) { cin>>x1>>y1>>x2>>y2; if(x1==x2) { //竖相同 hen[min(y1,y2)].num++; } if(y1==y2) { //横相同 shu[min(x1,x2)].num++; } } ////因为从1开始,所以要加一 sort(shu+1,shu+m+1,cmp); //先按可以分割的同学对的数目从大到小排序,看哪个最多 sort(hen+1,hen+n+1,cmp); sort(shu+1,shu+k+1,cmp2); //选前k个数字,再按从小到大排序 sort(hen+1,hen+l+1,cmp2); for(int i=1; i<=k; i++) { cout<<shu[i].hs; if(i!=k) cout<<" "; } cout<<endl; for(int i=1; i<=l; i++) { cout<<hen[i].hs; if(i!=l) cout<<" "; } return 0; }