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).

题目大意:飞行员分为两种:小于平均年龄的和大于的,小于的可以选择B,C两种space,大于的可以选择A,C两种,存在一些有矛盾的人不希望分在同一组,求一种方案使得不存在矛盾

解题报告:

个人理解:twosat的连边,有推导出的意思,依据这个,我们就可以分类讨论进行连边:


我们设年长的true表示在A,年小的true在B,false都表示在C

对于不同年龄的(x,y),那么只要不在同在C即可,所以直接两者的false分别连到对方的true

对于不同年龄的(x,y),他们不能在同一舱内,意味着不能同为false或同为true,所以两者的true分别向false连边的同时,也要false向true连边

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#define RG register
#define il inline
#define iter iterator
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std;
const int N=200055;
bool mark[N];int n,m,edg[N],head[N],nxt[N<<2],to[N<<2],num=0;
int gi(){
int str=0;char ch=getchar();
while(ch>'9' || ch<'0')ch=getchar();
while(ch>='0' && ch<='9')str=(str<<1)+(str<<3)+ch-48,ch=getchar();
return str;
}
void init(int x,int y,bool tx,bool ty){
x=((x-1)<<1)+tx;y=((y-1)<<1)+ty;
nxt[++num]=head[x];to[num]=y;head[x]=num;
}
int st[N],top=0;
bool dfs(int x){
if(mark[x^1])return false;
if(mark[x])return true;
mark[x]=true;
st[++top]=x;
for(int i=head[x];i;i=nxt[i]){
if(!dfs(to[i]))return false;
}
return true;
}
bool solve(){
int lim=(n<<1);
for(int i=0;i<lim;i+=2){
top=0;
if(!dfs(i)){
while(top)mark[st[top--]]=false;
if(!dfs(i^1))return false;
}
}
return true;
}
void work()
{
int x,y;double sum=0;
for(int i=1;i<=n;i++)edg[i]=gi(),sum+=edg[i];
sum=sum/(n*1.0);
for(int i=1;i<=m;i++){
x=gi();y=gi();
if((edg[x]>=sum)!=(edg[y]>=sum)){
init(x,y,0,1);init(y,x,0,1);
}
else{
init(x,y,1,0);init(x,y,0,1);
init(y,x,1,0);init(y,x,0,1);
}
}
bool tmp=solve();
if(!tmp)puts("No solution.");
else{
for(int i=1;i<=n;i++){
x=(i-1)<<1;
if(mark[x])
puts("C");
else{
if(edg[i]<sum)puts("B");
else puts("A");
}
}
}
}
void Clear(){
memset(head,0,sizeof(head));num=0;
memset(mark,0,sizeof(mark));
}
int main()
{
while(1){
n=gi();m=gi();
if(n+m==0)break;
work();
Clear();
}
return 0;
}

UVA 3713 Astronauts的更多相关文章

  1. UVALive - 3713 - Astronauts(图论——2-SAT)

    Problem   UVALive - 3713 - Astronauts Time Limit: 3000 mSec Problem Description Input The input cont ...

  2. UVA Live 3713 Astronauts (2-SAT)

    用布尔变量表示状态,把限制条件转化为XνY的形式以后跑2SAT,根据变量取值输出方案. #include<bits/stdc++.h> using namespace std; ; #de ...

  3. UVa 1391 Astronauts (2SAT)

    题意:给出一些宇航员他们的年龄,x是他们的平均年龄,其中A任务只能给年龄大于等于x的人,B任务只能给小于x的人,C任务没有限制.再给出m对人,他们不能同任务.现在要你输出一组符合要求的任务安排. 思路 ...

  4. UVALive 3713 Astronauts (2-SAT,变形)

    题意: 有A,B,C三种任务,每个人必获得1个任务,大于等于平均年龄的可以选择A和C,小于平均年龄的可以选择B和C.这些人有一些是互相讨厌的,必须不能执行同任务,问能否安排他们工作?若行,输出任意一组 ...

  5. UVALive - 3713 Astronauts

    给定n个宇航员的年龄,平均年龄为 ave,根据下列要求分配任务: B任务只能分配给年龄<ave的宇航员: A任务只能分配给年龄>=ave的宇航员: C任务可以任意分配. 给定m组互相憎恨的 ...

  6. uva 1391 Astronauts(2-SAT)

    /*翻译好题意 n个变量 不超过m*2句话*/ #include<iostream> #include<cstdio> #include<cstring> #inc ...

  7. LA 3713 Astronauts

    给个题目链接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=sh ...

  8. 图论$\cdot$2-SAT问题

    2-SAT问题是这样的:有$n$个布尔变量$x_i$,另有$m$个需要满足的条件,每个条件的形式都是“$x_i$为真/假或者$x_j$为真/假”.比如:"$x_1$为真或者$x_3$为假“. ...

  9. 【UVALive - 3713】Astronauts (2-SAT)

    题意: 有n个宇航员,按照年龄划分,年龄低于平均年龄的是年轻宇航员,而年龄大于等于平均年龄的是老练的宇航员. 现在要分配他们去A,B,C三个空间站,其中A站只有老练的宇航员才能去,而B站是只有年轻的才 ...

随机推荐

  1. webView调用系统地图,电话,和跳转链接的方法

    webView.dataDetectorTypes = UIDataDetectorTypePhoneNumber | UIDataDetectorTypeLink | UIDataDetectorT ...

  2. AWS EMR上搭建HBase环境

    0. 概述 AWS的EMR服务为客户提供的托管 Hadoop 框架可以让您轻松.快 速.经济高效地在多个动态可扩展的 Amazon EC2 实例之间分发和处理 大量数据.您还可以运行其他常用的分发框架 ...

  3. Docker1.12.6+CentOS7.3 的安装

    安装旧版的docker-engine-1.12.6 kubeadm init --api-advertise-addresses=172.16.160.211命令的时候,提示docker版本太新了 一 ...

  4. Docker学习笔记 - Docker的数据卷容器

    一.什么是数据卷容器 如果你有一些持续更新的数据需要在容器之间共享,最好创建数据卷容器. 数据卷容器:用于容器间的数据共享,主动挂载宿主机目录,用于其他容器挂载和共享. 二.数据卷容器的操作 1.创建 ...

  5. 新概念英语(1-47)A cup of coffee

    新概念英语(1-47)A cup of coffee How does Ann like her coffee? A:Do you like coffee, Ann? B:Yes, I do. A:D ...

  6. 【52ABP实战教程】0.3-- 从github推送代码回vsts实现双向同步

    需求 在之前的文章中"[DevOps]如何用VSTS持续集成到Github仓库" 我们有讲述如何将vsts中的代码编译推送到github中,这一篇我们来完善,如果有人给你开源项目推 ...

  7. [CodeForces10D]LCIS(最长公共上升子序列) - DP

    Description 给定两个数列,求最长公共上升子序列,并输出其中一种方案. Input&Output Input 第一行一个整数n(0<n<=500),数列a的长度. 第二行 ...

  8. Windows10 64位系统安装 .NET Framework 3.5

    1)下载NET Framework 3.5 [地址:https://pan.baidu.com/s/1c1FhXLY] 2)编辑NET Framework 3.5.bat ,修改sxs文件存放路径: ...

  9. Docker:云栖社区开源论题及Spark开源论题

    https://yq.aliyun.com/topic/78?spm=5176.8290451.656547.7.rMYhAF https://yq.aliyun.com/activity/155?u ...

  10. POJ-1122 FDNY to the Rescue!---Dijkstra+反向建图

    题目链接: https://vjudge.net/problem/POJ-1122 题目大意: 给出矩阵,矩阵中每个元素tij表示从第i个交叉路口到第j个交叉路口所需时间,若tij为-1则表示两交叉路 ...