5218 排座椅

描述

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

同学们在教室中坐成了 M 行 N 列,坐在第 i 行第 j 列的同学的位置是 (i,j),为了方便同学们进出,在教室中设置了 K 条横向的通道,L 条纵向的通道。

于是,聪明的小雪想到了一个办法,或许可以减少上课时学生交头接耳的问题:她打算重新摆放桌椅,改变同学们桌椅间通道的位置,因为如果一条通道隔开了 2 个会交头接耳的同学,那么他们就不会交头接耳了。

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

输入描述

第一行,有 5 个用空格隔开的整数,分别是 M,N,K,L,D(2≤N,M≤1000,0≤K<M,0≤L<N,D≤2000)。

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

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

输出描述

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

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

样例输入 1 

4 5 1 2 3
4 2 4 3
2 3 3 3
2 5 2 4

样例输出 1 

2
2 4

提示

数据范围与提示

上图中用符号*、※、+标出了 3 对会交头接耳的学生的位置,图中 3 条粗线的位置表示通道,图示的通道划分方案是唯一的最佳方案。

2008 年普及组第二题

                                (熟悉这缺省源的,一定是AKIOI的团队成员😀)      (~ ̄▽ ̄)~

#include<bits/stdc++.h>
//#define ONLINE_TEST
#ifdef ONLINE_TEST
#define getchar() p1 == p2 && (p2 = (p1 = buf) + fread (buf, 1, 1 << 18, stdin), p1 == p2) ? EOF : *p1++
#define flush() fwrite (buffer, 1, p11 + 1, stdout), p11 = -1
#define putchar(c) p11 == p22 ? flush(), buffer[++p11] = c : buffer[++p11] = c
char buf[1 << 18], *p1 = buf, *p2 = buf;
char buffer[1 << 18];
int p11 = -1;
const int p22 = (1 << 18) - 1;
#endif
template <typename T> inline void rei (T &x) {
	x = 0; bool f = 1; int ch;
	while (!isdigit (ch = getchar ())) f = ch != '-';
	if (f) do x = x * 10 + (ch & 15); while (isdigit (ch = getchar ()));
	else   do x = x * 10 - (ch & 15); while (isdigit (ch = getchar ()));
}
template <typename T> inline void wri (T x) {
	if (x < 0) putchar ('-'), x = ~x + 1;
	static int stk[40], top = 0;
	while (x) stk[++top] = x % 10, x /= 10;
	if (top == 0) stk[++top] = 0;
	while (top) putchar (stk[top--] ^ 48);
	putchar (' ');
}
template <typename T, typename... Args> inline void rei (T &x, Args&... args) {rei (x), rei (args...);}
template <typename T, typename... Args> inline void wri (T x, Args... args) {wri (x), wri (args...);}
template <typename T1, typename T2> inline T1 &cmin (T1 &a, const T2 &b) {return a > b ? a = b : a;}
template <typename T1, typename T2> inline T1 &cmax (T1 &a, const T2 &b) {return a < b ? a = b : a;}
typedef long long LL;
typedef unsigned long long ULL;
#define fir(i,a,b,...) for (register int i = (a), ##__VA_ARGS__; i <= (b); i++)
#define firr(i,a,b,...) for (register int i = (a), ##__VA_ARGS__; i >= (b); i--)
#define cls(a) memset (a, 0, sizeof a)
#define mset(a,b) memset (a, b, sizeof a)
#define dbug(x) (void)(cerr << #x " = " << x << endl)
using namespace std;
struct saccess{
	int id;
	int num;
}row[1005],cal[1005];
int n,m,k,l,d;
bool cmp1(saccess x,saccess y){
	return x.num>y.num;
}bool cmp2(saccess x,saccess y){
	return x.id<y.id;
}
signed main () {
	cin>>n>>m>>k>>l>>d;
	int x1,y1,x2,y2;
	for(int i=0;i<n;i++){
		row[i].id=i;
	}for(int i=0;i<m;i++){
		cal[i].id=i;
	}
	for(int i=0;i<d;i++){
		cin>>x1>>y1>>x2>>y2;
		if(x1==x2){
			cal[min(y1,y2)].num++;
		}if(y1==y2){
			row[min(x1,x2)].num++;
		}
	}
	sort(cal,cal+m,cmp1);
	sort(row,row+n,cmp1);
	sort(cal,cal+l,cmp2);
	sort(row,row+k,cmp2);
	for(int i=0;i<k;i++){
		cout<<row[i].id<<' ';
	}cout<<endl;
	for(int i=0;i<l;i++){
		cout<<cal[i].id<<' ';
	}
	return 0;
#ifdef ONLINE_TEST
	flush ();
#endif
	return 0;
}

                                    欢迎加入AKIOI团队

                                  (虽然我也只是个AKIOI成员,但真的觉得大有收获)

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值