#include<bits/stdc++.h>
using namespace std;
struct l
{long long x1,y1,x2,y2;}lie[200001];
struct h
{long long x1,y1,x2,y2;}hang[200001];
struct tp
{long long s,xy;}tpl[100010],tph[100010];
long long lt[100010],ht[100010];
bool cmpl(l a,l b)
{if(a.x1<b.x1) return true;return false;}
bool cmph(h a,h b)
{if(a.y1<b.y1) return true;return false;}
bool cmpt(tp a,tp b)
{if(a.s>b.s) return true;return false;}
int main()
{
// freopen("1.in","r",stdin);
// freopen("1.out","w",stdout);
long long m,n,k,l,d,x,y,p,q,lien=0,hangn=0,liem=0,hangm=0;
cin>>m>>n>>k>>l>>d;
for(long long i=1;i<=d;i++)
{
cin>>x>>y>>p>>q;
if(x>p) swap(x,p);
if(y>q) swap(y,q);
if(y==q) lien+=1,lie[lien].x1=x,lie[lien].y1=y,lie[lien].x2=p,lie[lien].y2=q;
else if(x==p) hangn+=1,hang[hangn].x1=x,hang[hangn].y1=y,hang[hangn].x2=p,hang[hangn].y2=q;
}
sort(lie+1,lie+lien+1,cmpl);
sort(hang+1,hang+hangn+1,cmph);
for(long long i=1;i<=lien;i++)
if(lie[i].x1==lie[i+1].x1&&lie[i].x2==lie[i+1].x2) tpl[liem+1].s+=1;
else liem+=1,tpl[liem].s+=1,tpl[liem].xy=lie[i].x1;
for(long long i=1;i<=hangn;i++)
if(hang[i].y1==hang[i+1].y1&&hang[i].y2==hang[i+1].y2) tph[hangm+1].s+=1;
else hangm+=1,tph[hangm].s+=1,tph[hangm].xy=hang[i].y1;
sort(tpl+1,tpl+liem+1,cmpt);
sort(tph+1,tph+hangm+1,cmpt);
for(long long i=1;i<=min(k,liem);i++) lt[i]=tpl[i].xy;
for(long long i=1;i<=min(l,hangm);i++) ht[i]=tph[i].xy;
sort(lt+1,lt+min(liem,k)+1);
sort(ht+1,ht+min(l,hangm)+1);
for(long long i=1;i<=min(k,liem);i++) cout<<lt[i]<<" ";
cout<<endl;
for(long long i=1;i<=min(l,hangm);i++) cout<<ht[i]<<" ";
return 0;
}
桶排记录横竖每行/列可以隔开的学生数量,再排序,贪心从大到小输出。
求翻译:时间常常变化。