Home > Database > Mysql Tutorial > body text

HDU 1814 Peaceful Commission(2

WBOY
Release: 2016-06-07 15:44:05
Original
1190 people have browsed it

HDU 1814 Peaceful Commission 题目链接 题意: 根据宪法,Byteland民主共和国的公众和平委员会应该在国会中通过立法程序来创立。 不幸的是,由于某些党派代表之间的不和睦而使得这件事存在障碍。 此委员会必须满足下列条件: 每个党派都在委员会中恰有1个代

HDU 1814 Peaceful Commission

题目链接

题意:
根据宪法,Byteland民主共和国的公众和平委员会应该在国会中通过立法程序来创立。 不幸的是,由于某些党派代表之间的不和睦而使得这件事存在障碍。

此委员会必须满足下列条件:

每个党派都在委员会中恰有1个代表,
如果2个代表彼此厌恶,则他们不能都属于委员会。
每个党在议会中有2个代表。代表从1编号到2n。 编号为2i-1和2i的代表属于第I个党派。

任务

写一程序:

从文本文件读入党派的数量和关系不友好的代表对,
计算决定建立和平委员会是否可能,若行,则列出委员会的成员表,
结果写入文本文件。
输入

在文本文件的第一个行有2非负整数n和m。 他们各自表示:党派的数量n,1

输出

如果委员会不能创立,文本文件中应该包括单词NIE。若能够成立,文本文件SPO.OUT中应该包括n个从区间1到2n选出的整数,按升序写出,每行一个,这些数字为委员会中代表的编号。如果委员会能以多种方法形成,程序可以只写他们的某一个。

思路:显然的2-sat,问题是输出字典序最小的,那么就以每个人作为结点,0,1代表选与不选,每次都优先从最小的人开始,尽量选1,最后输出路径就可以了

代码:

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;

const int MAXNODE = 16005;

struct TwoSet {
	int n;
	vector<int> g[MAXNODE * 2];
	bool mark[MAXNODE * 2];
	int S[MAXNODE * 2], sn;

	void init(int tot) {
		n = tot * 2;
		for (int i = 0; i <br>
<br>



</int></algorithm></vector></cstdlib></cstring></cstdio>
Copy after login
Related labels:
h
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!