排座椅(2021-TRN1-H)
题目大意
传送门
大意是:一个教室里有几条横着的过道和竖着的过道(由你来确定位置),使得过道能够尽可能多的隔开较多的爱交头接耳的同学。爱交头接耳的同学都是成对的,要么在前后,要么在左右。
题目解析
本来不是难题,但是坑有点多。。。
主要还是眼瞎
第一个
每两个整数之间用空格隔开(行尾没有空格)。
第二个
其中 ai<ai+1(所以选出通道位置后还要一次排序)
代码
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e3+1;
struct node
{
int pos;
int num;
}row[maxn],col[maxn];
int cmp1(struct node a,struct node b)
{
return a.num>b.num;
}
int cmp2(struct node a,struct node b)
{
return a.pos<b.pos;
}
int main()
{
int m,n,k,l,d;
scanf("%d%d%d%d%d",&m,&n,&k,&l,&d);
int i;
for(i=1;i<=d;i++)
{
int x1,x2,y1,y2;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
if(x1==x2)
{
if(y1>y2) col[y2].num++,col[y2].pos=y2;
else col[y1].num++,col[y1].pos=y1;
}
else if(y1==y2)
{
if(x1>x2) row[x2].num++,row[x2].pos=x2;
else row[x1].num++,row[x1].pos=x1;
}
}
sort(row+1,row+m+1,cmp1);
sort(row+1,row+k+1,cmp2);
sort(col+1,col+n+1,cmp1);
sort(col+1,col+l+1,cmp2);
for(i=1;i<=k;i++)
{
if(i==k) printf("%d",row[i].pos);
else printf("%d ",row[i].pos);
}
printf("\n");
for(i=1;i<=l;i++)
{
if(i==l) printf("%d",col[i].pos);
else printf("%d ",col[i].pos);
}
return 0;
}
/*
4 5 2 3 6
1 1 1 2
2 2 3 2
2 3 2 4
3 3 3 4
4 1 3 1
4 2 4 3
2 3
3 1 2
*/