ural 1156. Two Rounds
1156. Two Rounds
Memory limit: 64 MB
Input
Output
Sample
input | output |
---|---|
2 3 |
1 4 |
Problem Source: Ural Collegiate Programming Contest, April 2001, Perm, English Round
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
using namespace std;
typedef long long LL;
typedef double DB;
#define For(i, s, t) for(int i = (s); i <= (t); i++)
#define Ford(i, s, t) for(int i = (s); i >= (t); i--)
#define Rep(i, t) for(int i = (0); i < (t); i++)
#define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
#define rep(i, x, t) for(int i = (x); i < (t); i++)
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair
inline void SetIO(string Name) {
string Input = Name+".in",
Output = Name+".out";
freopen(Input.c_str(), "r", stdin),
freopen(Output.c_str(), "w", stdout);
} inline int Getint() {
int Ret = ;
char Ch = ' ';
while(!(Ch >= '' && Ch <= '')) Ch = getchar();
while(Ch >= '' && Ch <= '') {
Ret = Ret*+Ch-'';
Ch = getchar();
}
return Ret;
} const int N = ;
int n, m;
bool Map[N][N];
int Color[N], Pair[N][], Len, Who[N];
bool Dp[N][N][N], Flag, Visit[N];
int Ans[N];
vector<int> Day[]; inline void Input() {
scanf("%d%d", &n, &m);
For(i, , m) {
int a, b;
scanf("%d%d", &a, &b);
Map[a][b] = Map[b][a] = ;
}
} inline void Search(int x, int C) {
if(Flag) return;
Color[x] = C, Pair[Len][C-]++;
int _C = ((C-)^)+;
For(i, , n*)
if(Map[x][i]) {
if(Color[i] && Color[i] != _C) {
Flag = ;
break;
} if(!Color[i]) Search(i, _C);
}
} inline void Solve() {
For(i, , n*)
if(!Color[i]) {
Who[++Len] = i;
Search(i, );
if(Flag) break;
} if(Flag) {
puts("IMPOSSIBLE");
return;
} Dp[][][] = ;
For(i, , Len) {
int a = Pair[i][], b = Pair[i][];
For(j, , n)
For(k, , n) {
if(j+a <= n && k+b <= n)
Dp[i][j+a][k+b] |= Dp[i-][j][k];
if(j+b <= n && k+a <= n)
Dp[i][j+b][k+a] |= Dp[i-][j][k];
}
} if(!Dp[Len][n][n]) {
puts("IMPOSSIBLE");
return;
} int a = n, b = n;
Ford(i, Len, ) {
if(a >= Pair[i][] && b >= Pair[i][] && Dp[i-][a-Pair[i][]][b-Pair[i][]]) {
Ans[Who[i]] = , Visit[i] = ;
a -= Pair[i][], b -= Pair[i][];
} else if(a >= Pair[i][] && b >= Pair[i][] && Dp[i-][a-Pair[i][]][b-Pair[i][]]) {
Ans[Who[i]] = , Visit[i] = ;
a -= Pair[i][], b -= Pair[i][];
}
} clr(Color, );
For(i, , n*)
if(Ans[i]) Search(i, Ans[i]); For(i, , n*)
Day[Color[i]-].pub(i);
Rep(i, ) {
int Length = sz(Day[i]);
Rep(j, Length-) printf("%d ", Day[i][j]);
printf("%d\n", Day[i].back());
}
} int main() {
#ifndef ONLINE_JUDGE
SetIO("G");
#endif
Input();
Solve();
return ;
}
ural 1156. Two Rounds的更多相关文章
- 1156. Two Rounds(dfs+背包)
1156 求出每个联通块的黑白块数 然后再背包 二维的背包 要保证每个块都得取一个 写的有些乱.. #include <iostream> #include<cstdio> # ...
- ural 1246. Tethered Dog
1246. Tethered Dog Time limit: 1.0 secondMemory limit: 64 MB A dog is tethered to a pole with a rope ...
- 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome
题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...
- ural 2071. Juice Cocktails
2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...
- ural 2073. Log Files
2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...
- ural 2070. Interesting Numbers
2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...
- ural 2069. Hard Rock
2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...
- ural 2068. Game of Nuts
2068. Game of Nuts Time limit: 1.0 secondMemory limit: 64 MB The war for Westeros is still in proces ...
- ural 2067. Friends and Berries
2067. Friends and Berries Time limit: 2.0 secondMemory limit: 64 MB There is a group of n children. ...
随机推荐
- HDU 4915 Parenthese sequence
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4915 解题报告:从前往后遍历一次,每次判断')'的数目是不是满足 n < (i +1)/ 2,从 ...
- NGUI 粒子显示在上级
http://bbs.taikr.com/thread-2272-1-1.html [NGUI]3.0+版本,粒子在UI后面显示 -- : 48人阅读 评论() 收藏 举报 [Unity3D][NGU ...
- convert jar to java
(文章是从我的个人主页上粘贴过来的,大家也可以访问我的主页 www.iwangzheng.com) 首先解压一下下载的jar文件,extract jar file , $jar -xvf file.j ...
- [LA3026]Period
[LA3026]Period 试题描述 For each prefix of a given string S with N characters (each character has an ASC ...
- Coursera台大机器学习技法课程笔记02-Dual Support Vector Machine
这节课讲的是SVM的对偶问题,比较精彩的部分:为何要使用拉格朗日乘子以及如何进行对偶变换. 参考:http://www.cnblogs.com/bourneli/p/4199990.html http ...
- Linux CPU负载
昨天查看Nagios警报信息,发现其中一台服务器CPU负载过重,机器为CentOS系统.信息如下: 2011-2-15 (星期二) 17:50 WARNING - load average: 9.73 ...
- WCDMA是什么意思?CDMA是什么意思?GSM是什么意思
有些朋友在购买3G智能手机的时候会遇到这样的困惑,为什么相同的手机会有不同手机网络制式之分呢?有的支持WCDMA/GSM,有的支持CDMA/GSM,到底自己应该选购哪一种手机好呢?WCDMA是什么意思 ...
- ssh: connect to host localhost port 22: Connection refused 问题
错误原因:1.sshd 未安装2.sshd 未启动 3.防火墙 4需重新启动ssh 服务 解决方法:1.确定安装sshd: $ sudo apt-get install openssh-server ...
- android.content.ActivityNotFoundException: Unable to find explicit activity class have you declared this activity in your AndroidManifest.xml?
在整合PullToRefresh的时候出现如下异常 10-22 23:20:01.826 32331-32331/com.example.news.andoridnewsapp E/AndroidRu ...
- iOS 利用self.navigationItem.backBarButtonItem修改后退按钮文字
@property(nonatomic,retain) UIBarButtonItem *backBarButtonItem; // Bar button item to use for the ba ...