思路:行和列怎么划分相互没有干扰,分开算,根据给的坐标我们去算那个位置接耳的人多我们去吧他们分开,存一下位置,最后答案要对位置从小到大输出。
#include <cstdio> #include <cstring> #include <algorithm> #include <set> #include<iostream> #include<vector> #include<queue> #include<stack> #include<bits/stdc++.h> using namespace std; typedef long long ll; #define SIS std::ios::sync_with_stdio(false) #define space putchar(' ') #define enter putchar('\n') #define lson root<<1 #define rson root<<1|1 typedef pair<int,int> PII; const int mod=998244353; const int N=2e6+10; const int M=2e3+10; const int inf=0x7f7f7f7f; const int maxx=2e5+7; ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); } ll lcm(ll a,ll b) { return a*(b/gcd(a,b)); } template <class T> void read(T &x) { char c; bool op = 0; while(c = getchar(), c < '0' || c > '9') if(c == '-') op = 1; x = c - '0'; while(c = getchar(), c >= '0' && c <= '9') x = x * 10 + c - '0'; if(op) x = -x; } template <class T> void write(T x) { if(x < 0) x = -x, putchar('-'); if(x >= 10) write(x / 10); putchar('0' + x % 10); } ll qsm(int a,int b,int p) { ll res=1%p; while(b) { if(b&1) res=res*a%p; a=1ll*a*a%p; b>>=1; } return res; } struct node { int cnt,index; }; int vx[N],vy[N]; bool cmp(node a,node b) { return a.cnt>b.cnt; } vector<node> vt1,vt2; int a1[N],b1[N]; int main() { int m,n,k,l,d; cin>>m>>n>>k>>l>>d; for(int i=0;i<d;i++) { int x1,x2,y1,y2; cin>>x1>>y1>>x2>>y2; if(x1==x2) vy[min(y1,y2)]++; else vx[min(x1,x2)]++; } for(int i=1;i<=m;i++) { if(vx[i]) vt1.push_back({vx[i],i}); } for(int i=1;i<=n;i++) { if(vy[i]); vt2.push_back({vy[i],i}); } sort(vt1.begin(),vt1.end(),cmp); sort(vt2.begin(),vt2.end(),cmp); for(int i=0;i<k;i++) a1[i]=vt1[i].index; for(int i=0;i<l;i++) b1[i]=vt2[i].index; sort(a1,a1+k); sort(b1,b1+l); for(int i=0;i<k;i++) cout<<a1[i]<<' '; cout<<endl; for(int i=0;i<l;i++) cout<<b1[i]<<' '; cout<<endl; return 0; }