sicily1762 排座椅

Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

Description

上课的时候总有一些同学和前后左右的人交头接耳,这是令小学班主任十分头疼的一件事情。不过,班主任小雪发现了一些有趣的现象,当同学们的座次确定下来之后,只有有限的D对同学上课时会交头接耳。同学们在教室中坐成了MN列,坐在第i行第j

 

 

 

的同学的位置是(ij),为了方便同学们进出,在教室中设置了K条横向的通道,L条纵向的通道。于是,聪明的小雪想到了一个办法,或许可以减少上课时学生交头接耳的问题:她打算重新摆放桌椅,改变同学们桌椅间通道的位置,因为如果一条通道隔开了两个会交头接耳的同学,那么他们就不会交头接耳了。

 

请你帮忙给小雪编写一个程序,给出最好的通道划分方案。在该方案下,上课时交头接耳的学生对数最少。

 

Input

输入有多组Case,每组Case有5各用空格隔开的整数,分别是MNKLD2<=NM<=10000<=K<M0<=L<ND<=2000)。

 

接下来D行,每行有4个用空格隔开的整数,第i行的4个整数XiYiPiQi,表示坐在位置(Xi,Yi)(Pi,Qi)的两个同学会交头接耳(输入保证他们前后相邻或者左右相邻)。

 

输入数据保证最优方案的唯一性。

 

Output

每个Case输出共两行。

 

第一行包含K个整数,a1a2……aK,表示第a1行和a1+1行之间、第a2行和第a2+1行之间、…、第aK行和第aK+1行之间要开辟通道,其中ai< ai+1,每两个整数之间用空格隔开(行尾没有空格)。

 

第二行包含L个整数,b1b2……bk,表示第b1列和b1+1列之间、第b2列和第b2+1列之间、…、第bL列和第bL+1列之间要开辟通道,其中bi< bi+1,每两个整数之间用空格隔开(行尾没有空格)。

 

Sample Input

4 5 1 2 34 2 4 32 3 3 32 5 2 4

Sample Output

22 4


题目分析:水题一道!

参考代码 写的很乱 很水

#include <iostream>
#include <string>
#include <cstring>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;

bool cmp(int a, int b)
{
	return a > b;
}

struct Nodex
{
	int index;
	int sum;
	friend bool operator<(Nodex n1, Nodex n2)
	{
		return n1.sum > n2.sum;
	}
};

struct Nodey
{
	int index;
	int sum;
	friend bool operator<(Nodey n1, Nodey n2)
	{
		return n1.sum > n2.sum;
	}
};


int main()
{
	int m, n, k, a, d;
	while (cin >> m >> n >> k >> a >> d)
	{
		int x1, y1, x2, y2;
		int x[1009], y[1009];
		memset(x, 0, sizeof(x));
		memset(y, 0, sizeof(y));
		int inx = 0, iny = 0;
		for (int i = 0; i < d; ++ i)
		{
			cin >> x1 >> y1 >> x2 >> y2;
			if (x1 == x2)
			{
				if (y1 < y2)
				{
					++ y[y1];
				}
				else
				{
					++ y[y2];
				}
			}
			else if (y1 == y2)
			{
				if (x1 < x2)
				{
					++ x[x1];
				}
				else
				{
					++ x[x2];
				}
			}
		}
		Nodex nodex[m + 1];
		for (int i = 1; i <= m; ++ i)
		{
			if (x[i] != 0)
			{
				nodex[inx].index = i;
				nodex[inx].sum = x[i];
				++ inx;
			}
		}
		sort(nodex, nodex + inx);
		Nodey nodey[n + 1];
		for (int i = 1; i <= n; ++ i)
		{
			if (y[i] != 0)
			{
				nodey[iny].index = i;
				nodey[iny].sum = y[i];
				++ iny;
			}
		}
		sort(nodey, nodey + iny);
		set<int> myset;
		for (int i = 0; i < k; ++ i)
		{
			myset.insert(nodex[i].index);
		}
		set<int>::iterator it = myset.begin();
		for (int i = 0; i < k; ++ i, ++ it)
		{
			cout << *it;
			if (i != k - 1)
			{
				cout << " ";
			}
		}
		cout << endl;
		set<int> mysety;
		for (int i = 0; i < a; ++ i)
		{
			mysety.insert(nodey[i].index);
		}
		set<int>::iterator ity = mysety.begin();
		for (int i = 0; i < a; ++ i, ++ ity)
		{
			cout << *ity;
			if (i != a - 1)
			{
				cout << " ";
			}
		}
		cout <<endl;
	}
  //system("pause");
}                                 


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值