UVALive 3713 Astronauts
来源:互联网 发布:最热软件 编辑:程序博客网 时间:2024/05/20 00:50
2sat....可看出每个宇航员可以有两种任务选择 (A/B) 或 C
对于每一对有矛盾的宇航员,如果属于同一年龄段 那么这两个人选择的任务不应该相同
如果属于不同的年龄段,则俩个人不能同时选择任务C
[Submit] [Go Back] [Status]
Description
The Bandulu Space Agency (BSA) has plans for the following three space missions:
- Mission A: Landing on Ganymede, the largest moon of Jupiter.
- Mission B: Landing on Callisto, the second largest moon of Jupiter.
- Mission C: Landing on Titan, the largest moon of Saturn.
Your task is to assign a crew for each mission. BSA has trained a number of excellent astronauts; everyone of them can be assigned to any mission. However, if two astronauts hate each other, then it is not wise to put them on the same mission. Furthermore, Mission A is clearly more prestigious than Mission B; who would like to go to the second largest moon if there is also a mission to the largest one? Therefore, the assignments have to be done in such a way that only young, inexperienced astronauts go to Mission B, and only senior astronauts are assigned to Mission A. An astronaut is considered young if their age is less than the average age of the astronauts and an astronaut is senior if their age is at least the averageage. Every astronaut can be assigned to Mission C, regardless of their age (but you must not assign two astronauts to the same mission if they hate each other).
Input
The input contains several blocks of test cases. Each case begins with a line containing two integers 1n100000 and 1m100000 . The number n is the number of astronauts. The next n lines specify the age of the n astronauts; each line contains a single integer number between 0 and 200. The next m lines contains two integers each, separated by a space. A line containing i and j(1i, jn) means that the i -th astronaut and the j -th astronaut hate each other.
The input is terminated by a block with n = m = 0 .
Output
For each test case, you have to output n lines, each containing a single letter. This letter is either `A', `B', or `C'. The i -th line describes which mission the i -th astronaut is assigned to. Astronauts that hate each other should not be assigned to the same mission, only young astronauts should be assigned to Mission B and only senior astronauts should be assigned to Mission A. If there is no such assignment, then output the single line ` No solution.' (without quotes).
Sample Input
16 2021222324252627281011021031041051061071081 23 45 6 7 89 1011 1213 1415 161 102 93 124 115 146 13 7 168 151 121 133 166 150 0
Sample Output
BCCBCBCBACCACACA
Source
[Submit] [Go Back] [Status]
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn=200200;struct Edge{ int to,next;}edge[maxn*4];int Adj[maxn],Size;void init(){ Size=0; memset(Adj,-1,sizeof(Adj));}void Add_Edge(int u,int v){ edge[Size].to=v; edge[Size].next=Adj[u]; Adj[u]=Size++;}int n,m;int age[maxn],sum;int vis[maxn],Stack[maxn],top;bool dfs(int u){ if(vis[u^1]) return false; if(vis[u]) return true; vis[u]=true; Stack[top++]=u; for(int i=Adj[u];~i;i=edge[i].next) { if(!dfs(edge[i].to)) return false; } return true;}bool two_sat(){ memset(vis,0,sizeof(vis)); for(int i=0;i<2*n;i+=2) { if(vis[i]||vis[i^1]) continue; top=0; if(!dfs(i)) { while(top) vis[Stack[--top]]=0; if(!dfs(i^1)) return false; } } return true;}bool kind(int x){ return age[x]*n<sum;}int main(){ while(scanf("%d%d",&n,&m)!=EOF) { if(n==0&&m==0) break; init();sum=0; for(int i=0;i<n;i++) { scanf("%d",age+i); sum+=age[i]; } for(int i=0;i<m;i++) { int a,b; scanf("%d%d",&a,&b); a--;b--; if(kind(a)==kind(b)) { Add_Edge(a<<1,b<<1|1); Add_Edge(b<<1,a<<1|1); } Add_Edge(a<<1|1,b<<1); Add_Edge(b<<1|1,a<<1); } if(two_sat()) { for(int i=0;i<2*n;i+=2) { if(!vis[i]) { puts("C"); continue; } if(kind(i/2)) puts("B"); else puts("A"); } } else puts("No solution."); } return 0;}
- UvaLive-3713-Astronauts
- UVALive 3713 Astronauts
- UVALive - 3713 Astronauts
- UVALive 3713 Astronauts
- UVALive 3713 - Astronauts(2-SAT)
- UVALive - 3713 Astronauts(2-SAT)
- UVALive 3713 Astronauts(2SAT)
- UVALIVE 3713 Astronauts(2-SAT)
- UVALive 3713 Astronauts(2-sat+输出任意路径)
- [蓝书/Ch5] Astronauts UVALive
- LA 3713 Astronauts
- LA 3713 - Astronauts 2-SAT
- LA 3713 Astronauts
- uva 3713 Astronauts (2-sat)
- LA 3713 Astronauts(2-SAT)
- LA3713 Astronauts
- UVALive3713 Astronauts
- uvaLive 3713
- 僵尸(zombie)进程
- 全排列
- rmq算法,利用倍增思想
- 真实世界里的钢铁侠-特斯拉汽车创始人埃隆·马斯克(Elon Musk)
- Python 描述符
- UVALive 3713 Astronauts
- Actor编程模型——Erlang/OTP
- CTime FILETIME 与CString之间的转换
- Android内容提供者 --ContentProvider(待写)
- POJ 1979 Red and Black 基础性的DFS
- lightoj1422(区间DP)
- poj 3126
- 活出最好的自己
- Android内容观察者 --ContentObserver(待写)