4
1
2015
0

Tyvj 1007 排座椅

//敲了一遍就过,开心^_^
#include <iostream>
#include <algorithm>
using namespace std;

int m,n,k,l,d;

struct str
{
	int order; //序号
	int value; //该行(或列)讲话的人数
	str() {
		value=0;
	}
}row[1000],col[1000];

bool cpv(str a,str b)
{
	return a.value>b.value; //以讲话人数为关键字,显然优先把人多的分开
}

bool cpo(str a,str b)
{
	return a.order<b.order; //按照题目要求,按序号从小到大输出
}

int main()
{
	cin>>m>>n>>k>>l>>d;
	for (int i=1;i<m;++i) row[i].order=i;
	for (int i=1;i<n;++i) col[i].order=i; //初始化序号
	for (int i=0,x,y,p,q;i<d;++i) {
		cin>>x>>y>>p>>q;
		if (x==p) col[min(y,q)].value++; //若行号相同则在该列说话人数加一,下同
		else row[min(x,p)].value++; 
	}
	sort(row+1,row+m+1,cpv); sort(row+1,row+k+1,cpo); //两边排序后,row[1..k]就是答案,下同
	sort(col+1,col+n+1,cpv); sort(col+1,col+l+1,cpo);
	for (int i=1;i<k;++i) cout<<row[i].order<<' '; cout<<row[k].order<<endl; //注意行尾无空格
	for (int i=1;i<l;++i) cout<<col[i].order<<' '; cout<<col[l].order;
	return 0;
}
Category: 题解 | Tags: Tyvj 贪心 | Read Count: 192

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com