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;
}

转载于:https://www.cnblogs.com/Yuzao/p/7476795.html

UVA 3713 Astronauts相关推荐

  1. 图论算法与模型(训练指南题库)

    一.基础题目 1.UVA 11624 Fire!迷宫问题 多源BFS 题意: 帮助joe走出一个大火蔓延的迷宫,其中joe每分钟可往上下左右四个方向之一走,所有着火的格子都会蔓延(空格与着火格有公共边 ...

  2. 训练指南 UVALive - 3713 (2-SAT)

    layout: post title: 训练指南 UVALive - 3713 (2-SAT) author: "luowentaoaa" catalog: true mathja ...

  3. UVa 207 - PGA Tour Prize Money

    时间限制:3.000秒 题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&catego ...

  4. [搜索]UVa 129 困难的串

    题意:将一个包含两个相邻的重复子串的子串,称为"容易的串",其他为"困难的串". 输入正整数n和l,输出由前l个字符组成的,字典序第n小的困难的串. 输入样例: ...

  5. uva 401.Palindromes

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  6. Uva 3767 Dynamic len(set(a[L:R])) 树套树

    Dynamic len(set(a[L:R])) Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 https://uva.onlinejudge.org/in ...

  7. UVA 11752 超级幂

    UVA 11752 超级幂 Z - The Super Powers Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & ...

  8. UVa 11174 - Stand in a Line

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  9. UVa 10112 - Myacm Triangles

    UVa第一卷最后一题. 求内部不含点并且面积最大的三角形. 暴力. 代码如下: 1 #include<iostream> 2 #include<cstdio> 3 #inclu ...

  10. UVa 10180 - Rope Crisis in Ropeland!

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=41&pa ...

最新文章

  1. 用nginx搭建基于rtmp或者http的flv、mp4流媒体服务器
  2. strcpy和memcpy的区别 | strcpy和strncpy的区别
  3. 界面之间是如何传值的
  4. ElasticSearch 性能优化实战,让你的 ES 飞起来!
  5. 使用bakefile编译C工程代码
  6. rman命令学习-tina(上)
  7. PAT1087 All Roads Lead to Rome (30)(最短路径+dfs+回溯)
  8. 关于一个类中方法的调用
  9. SELECT command denied to user ''@'%' for column 'xxx_id' in table 'users_xxx' 权限问题
  10. 海威计算机网络,海威分布式大屏幕显示控制系统的主要优点
  11. python之路_面向对象
  12. 计算机派位志愿填报技巧,海淀小升初哪些入学途径采取电脑派位 志愿又怎么填报 2021家长了解...
  13. 如何用计算机玩扫雷,电脑扫雷技巧详细解析 扫雷游戏怎么玩
  14. 计算机pc at代表什么意思啊,PC/XT 与PC/AT的分别?
  15. Android系统相机拍照与选择照片
  16. 第一课2021014615
  17. R语言基础教程(1)
  18. 毫米波雷达识别问题分析及解决措施
  19. EAGLE 基本介绍
  20. 山东专升本计算机第八章-多媒体技术基础

热门文章

  1. 跨域 SameSite secure
  2. 在Ubuntu 18.04上畅玩 Cataclysm: Dark Days Ahead:大灾变!
  3. JAVA实现PDF合并、拆分代码工具类
  4. 产品沉思录精选:如何像管理金融投资组合一样来管理知识?
  5. php游戏传奇,GitHub - esons/pmir2: php,swoole,mirserver,mir2,传奇2,服务器,游戏服务器
  6. vue 实现数字滚动卡片
  7. umeditor1.2.2 jsp版本更改图片上传路径的方法
  8. 如何修改电脑的MAC地址(手把手更改)
  9. CNN各模块介绍(一)
  10. 紫外光谱分析的基本原理是什么