题解 | #排座椅#
排座椅
https://ac.nowcoder.com/acm/problem/16618
此题的思路就是以行和列上的同学对数为待排序的元素来对行和列进行排序(贪心思想)
using namespace std;
struct node{
int num;
int cnt;
}hang[1100],lie[1100];
bool cmp1(struct node a , struct node b ){
return a.num < b.num;
}
bool cmp2(struct node a , struct node b ){
return a.cnt > b.cnt;
}
int main(){
int m,n,k,l,d;
cin >> m >> n >> k >> l >>d;
for (int i = 1 ; i <= max(m,n) ; i ++ ){
hang[i].num = i;
lie[i].num = i;
}
for (int i = 1 ;i <= d ; i ++ ){
int x,x1,y,y1;
cin >> x >> y >> x1 >> y1;
if (x == x1) {
lie[y > y1 ? y1 : y].cnt ++ ;/*这儿要考虑
y的大小问题!!!*/
}
else {
hang[x > x1 ? x1 : x].cnt ++ ;
}
}
sort(hang + 1, hang + 1 + m,cmp2);
sort(hang + 1, hang + 1 + k,cmp1);
sort(lie + 1, lie + 1 + n,cmp2);
sort(lie + 1, lie + 1 + l,cmp1);
for (int i = 1 ; i <= k ; i ++ ){
printf("%d",hang[i].num);
if (i != k ) printf(" ");
}
printf("\n");
for (int i = 1 ; i <= l ; i ++ ){
printf("%d",lie[i].num);
if (i != l ) printf(" ");
}
return 0;
}