P1056 [NOIP2008 普及组] 排座椅(贪心)

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <set>
#include <cmath>
#include <map>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int MN = 65005;
const int MAXN = 1000005;
const int INF = 0x3f3f3f3f;
#define reg register
#define IOS ios::sync_with_stdio(false)

int M, N, L, K, D;
struct point {
	int pos, n;
	point() {
		pos = 0;
		n = 0;
	}
} x[1001], y[1001];

bool cmp1(point a, point b) {
	return a.n > b.n;
}

int main() {
	scanf("%d %d %d %d %d", &M, &N, &K, &L, &D);
	int x1, x2, y1, y2;
	for (int i = 1; i <= D; i++) {
		scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
		if (x1 == x2) {
			if (y1 < y2) {
				y[y1].n++;
				y[y1].pos = y1;
			} else {
				y[y2].n++;
				y[y2].pos = y2;
			}
		} else if (y1 == y2) {
			if (x1 < x2) {
				x[x1].n++;
				x[x1].pos = x1;
			} else {
				x[x2].n++;
				x[x2].pos = x2;
			}
		}
	}
	sort(x + 1, x + M + 1, cmp1);
	sort(y + 1, y + N + 1, cmp1);
	int xx[1001], yy[1001];
	int tmp1 = K, tmp2 = L;
	for (int i = 1;; i++) {
		if (x[i].n == 0 || tmp1 == 0) {
			break;
		}
		xx[i] = x[i].pos;
		tmp1--;
	}
	for (int i = 1;; i++) {
		if (y[i].n == 0 || tmp2 == 0) {
			break;
		}
		yy[i] = y[i].pos;
		tmp2--;
	}
	K -= tmp1;
	L -= tmp2;
	sort(xx + 1, xx + K + 1);
	sort(yy + 1, yy + L + 1);
	for (int i = 1; i <= K; i++) {
		printf("%d ", xx[i]);
	}
	printf("\n");
	for (int i = 1; i <= L; i++) {
		printf("%d ", yy[i]);
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值