UVA 3713 Astronauts
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的更多相关文章
- UVALive - 3713 - Astronauts(图论——2-SAT)
		Problem UVALive - 3713 - Astronauts Time Limit: 3000 mSec Problem Description Input The input cont ... 
- UVA Live 3713 Astronauts (2-SAT)
		用布尔变量表示状态,把限制条件转化为XνY的形式以后跑2SAT,根据变量取值输出方案. #include<bits/stdc++.h> using namespace std; ; #de ... 
- UVa 1391 Astronauts (2SAT)
		题意:给出一些宇航员他们的年龄,x是他们的平均年龄,其中A任务只能给年龄大于等于x的人,B任务只能给小于x的人,C任务没有限制.再给出m对人,他们不能同任务.现在要你输出一组符合要求的任务安排. 思路 ... 
- UVALive 3713 Astronauts (2-SAT,变形)
		题意: 有A,B,C三种任务,每个人必获得1个任务,大于等于平均年龄的可以选择A和C,小于平均年龄的可以选择B和C.这些人有一些是互相讨厌的,必须不能执行同任务,问能否安排他们工作?若行,输出任意一组 ... 
- UVALive - 3713 Astronauts
		给定n个宇航员的年龄,平均年龄为 ave,根据下列要求分配任务: B任务只能分配给年龄<ave的宇航员: A任务只能分配给年龄>=ave的宇航员: C任务可以任意分配. 给定m组互相憎恨的 ... 
- uva 1391 Astronauts(2-SAT)
		/*翻译好题意 n个变量 不超过m*2句话*/ #include<iostream> #include<cstdio> #include<cstring> #inc ... 
- LA 3713 Astronauts
		给个题目链接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=sh ... 
- 图论$\cdot$2-SAT问题
		2-SAT问题是这样的:有$n$个布尔变量$x_i$,另有$m$个需要满足的条件,每个条件的形式都是“$x_i$为真/假或者$x_j$为真/假”.比如:"$x_1$为真或者$x_3$为假“. ... 
- 【UVALive - 3713】Astronauts (2-SAT)
		题意: 有n个宇航员,按照年龄划分,年龄低于平均年龄的是年轻宇航员,而年龄大于等于平均年龄的是老练的宇航员. 现在要分配他们去A,B,C三个空间站,其中A站只有老练的宇航员才能去,而B站是只有年轻的才 ... 
随机推荐
- DES   MEI号码加密
			对于加密来说,使用DES加密解密很好,但是为了使不同设备的密文不一样,可以使用 固定字符串 + 设备IMEI号码 加密的方式,这样可以分辨不同手机,限制手机的使用(若是注册,一个手机只有一个IMEI号 ... 
- vue 保留两位小数 不能直接用toFixed(2) ?
			用vue做项目的时候多多少少都会遇到这个问题 刚开始我是用toFixed()这个方法来写的 效果是有的 但是控制台一直是红红的围绕着我 突然想到 vue和jquery混搭 的 问题 于是乎 看了一下 ... 
- JavaScript 动态显示当前时间
			代码如下: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <tit ... 
- Python内置函数(15)——memoryview
			英文文档: class memoryview(obj) memoryview objects allow Python code to access the internal data of an o ... 
- vuex在项目中使用的一点总结
			以下为vue后台管理项目中使用vuex的一点总结,截取了其中部分代码,如有什么错误,还望指出. 1. token 存储 登陆成功之后,需要把获取到的 token 存储到 vuex 中,配合 axios ... 
- 【漏洞复现】PHPCMS wap模块 SQL注入(附EXP)
			漏洞影响版本:v9.5.8.v9.6.0 Step1: 访问:http://www.xxx.com/index.php?m=wap&a=index&siteid=1, 获取返回的coo ... 
- springmvc的ModelAttribute注解
			先看一个没有使用@ModelAttribute的Controller方法. @RequestMapping("/save") public String save(User use ... 
- 1.phpStrom连接远程代码
			1.选择一个新的文件 2.选择自己需要的传输方式 3.添加项目名+路径 4.填写连接基本信息 5.配置成功,下载完毕后,设计本地与远程代码同步修改 自此本地修改代码,同时修改远程服务器代码就设置完毕~ ... 
- build.gradle & gradle.properties
			一.build.gradle buildscript { ext { springBootVersion = '1.5.9.RELEASE' } repositories { maven { cred ... 
- Ajax.html:35 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org
			AJAX的容易错误的地方 Ajax.html:35 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated ... 
