uva1391 - Astronauts 2-SAT

【UVa1391】宇航员分组Astronauts【2-SAT】【强连通分量】 大意:有n个宇航员,按照年龄划分,年龄低于平均年龄的是年轻宇航员,而年龄大于等于平均年龄的是老练的宇航员。 现在要分配他们去A,B,C三个空间站,其中A站只有老练的宇航员才能去,而B站是只有年轻的才能去,C站都可以去。 有m对宇航员相互讨厌,不能让他们在同一个空间站工作。 输出每个宇航员应分配到哪个空间站,如果没有则输出No solution.这道题只要构出图来就很好办啦~~ 由于每个宇航员 阅读详情

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 1$ \le$n$ \le$100000 and 1$ \le$m$ \le$100000. 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 (1$ \le$i, j$ \le$n) 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 20
21
22
23
24
25
26
27
28
101
102
103
104
105
106
107
108
1 2
3 4
5 6 
7 8
9 10
11 12
13 14
15 16
1 10
2 9
3 12
4 11
5 14
6 13 
7 16
8 15
1 12
1 13
3 16
6 15
0 0

Sample Output 

B
C
C
B
C
B
C
B
A
C
C
A
C
A
C
A

  有A,B,C 3个任务分配给N个人,每个人分配一个,年龄大于等于平均年龄的只能分配A或C,否则只能分配B或C。有M对人相互讨厌,相互讨厌的人不能分配到一样的任务。

  每个人只有2种选择,这就变成了一个2-SAT问题。把年龄大于等于平均年龄的人设为第1类,年龄小于平均年龄的设为第2类。第1类设分配A为真,分配C为假,第2类人分配B为真,C为假。相互讨厌的两个人u,v如果属于同一类,那么就要增加两次边,u真或v真,u假或v假,如果两个人不是同一类,就只需要增加一次边,u真或v真。

  2-SAT在搜索过程中记录选择情况,最后再根据每个人的类型输出对应的答案。

#include<iostream>
#include<queue>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<algorithm>
#define INF 0x3f3f3f3f
#define eps 1e-9
#define MAXN 100010
#define MAXM 2000010
#define MAXNODE 105
#define MOD 100000
#define SIGMA_SIZE 4
typedef long long LL;
using namespace std;
int T,N,M,sum,age[MAXN],ans[MAXN],type[MAXN];
struct TwoSAT{
    int n,c,S[MAXN*2];
    bool mark[MAXN*2];
    vector<int> G[MAXN*2];
    void init(int n){
        this->n=n;
        for(int i=0;i<n*2;i++) G[i].clear();
        memset(mark,0,sizeof(mark));
    }
    bool dfs(int x){
        if(mark[x^1]) return false;
        if(mark[x]) return true;
        mark[x]=true;
        S[c++]=x;
        int L=G[x].size();
        for(int i=0;i<L;i++) if(!dfs(G[x][i])) return false;
        return true;
    }
    void add_clause(int x,int xval,int y,int yval){
        x=x*2+xval;
        y=y*2+yval;
        G[x^1].push_back(y);
        G[y^1].push_back(x);
    }
    bool solve(){
        for(int i=0;i<n*2;i+=2) if(!mark[i]&&!mark[i+1]){
            c=0;
            if(!dfs(i)){
                while(c>0) mark[S[--c]]=false;
                if(!dfs(i+1)) return false;
            }
            while(c>0) ans[S[--c]>>1]=S[c]%2;
        }
        return true;
    }
}solver;

int main(){
    freopen("in.txt","r",stdin);
    while(scanf("%d%d",&N,&M)!=EOF&&(N||M)){
        sum=0;
        for(int i=0;i<N;i++){
            scanf("%d",&age[i]);
            sum+=age[i];
        }
        for(int i=0;i<N;i++){
            if(age[i]*N>=sum) type[i]=1;
            else type[i]=2;
        }
        solver.init(N);
        int u,v;
        while(M--){
            scanf("%d%d",&u,&v);
            u--;
            v--;
            if(type[u]==type[v]){
                solver.add_clause(u,1,v,1);
                solver.add_clause(u,0,v,0);
            }
            else solver.add_clause(u,1,v,1);
        }
        if(!solver.solve()) printf("No solution.\n");
        else for(int i=0;i<N;i++){
            if(!ans[i]) printf("C\n");
            else if(type[i]==1) printf("A\n");
            else printf("B\n");
        }
    }
    return 0;
}


python指纹识别算法(亲测代码可用) python指纹识别算法 阅读详情

相关推荐

Nvidia Isaac Sim安装与配置 入门教程 2024(2)

Isaac Sim 安装和配置教程将指导用户完成从下载软件到设置和运行仿真的全过程。教程内容包括安装必要的依赖项、配置系统环境、配置Omniverse环境以及调试和优化仿真环境的步骤。通过详细的操作步骤和图文并茂的说明,用户可以快速上手 Isaac Sim,构建出高质量的机器人仿真环境,实现其研究和应用目标。

m0_56661101的博客 2万+

2-SAT问题及其算法

【2-SAT问题】 现有一个由N个布尔值组成的序列A,给出一些限制关系,比如A[x] AND A[y]=0、A[x] OR A[y] OR A[z]=1等,要确定A[0..N-1]的值,使得其满足所有限制关系。这个称为SAT问题,特别的,若每种限制关系中最多只对两个元素进行限制,则称为2-SAT问题。 由于在2-SAT问题中,最多只对两个元素进行限制,所以可能的限制关系共有11种: A[

飞熊入梦 8648

Intel RealSense D435深度相机实战:从数据采集到点云生成的完整避坑指南

本文详细介绍了Intel RealSense D435深度相机的实战应用,从数据采集到点云生成的完整流程,并提供了避坑指南。内容包括环境配置、硬件调优、数据采集技巧、点云生成核心技术及典型场景解决方案,帮助开发者高效利用D435进行机器人导航、三维重建等应用。

weixin_29054195的博客 477

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

weixin_30790841的博客 139

Halcon实战:5分钟搞定线序颜色检测(附完整代码解析)

本文详细介绍了如何使用Halcon在5分钟内实现工业级线序颜色检测的高效方案。通过机器视觉技术,结合实战项目经验,提供完整的代码解析和优化技巧,帮助开发者快速构建鲁棒性强、准确率高的检测系统,适用于电子制造和汽车线束等行业。

weixin_29098367的博客 448

Android Audio常见问题分析方法

分析audio dump,确定写给BT的data是否正常,MTK平台Android原生架构分析threadloop write节点,高通平台分析QXDM 1586节点,从dump确定问题大概位置。分析systrace 确定性能。AudioFocus状态(用于播放或者音量异常的情况)。AudioTrack是否正常创建bt连接是否正常通路异常,setMode,setSpeakerphoneOn等都会影响设备选择,sco调用流程是否正常。

一条老狗的博客 2396

live archive 3713 two-sat

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 moo

AC_kereo的专栏 816

opencv 常用函数总结

本文是一份OpenCV图像处理的常用函数总结,详细介绍了图像的读入、显示、保存、像素处理、图像属性获取、基础操作、阈值处理、图像平滑、形态学转换以及直方图处理等关键技术。文章通过代码示例和参数说明,帮助读者快速掌握OpenCV在图像处理领域的应用。

weixin_44063529的博客 1602

uva 1391 - Astronauts(2sat)

题目链接:uva 1391 - Astronauts #include #include #include #include #include using namespace std; const int maxn = 100005; struct TwoSAT { int n; bool mark[maxn * 2]; vector G[maxn * 2]; in

不慌不忙、不急不躁 935

openvpn 安装 (Alibaba Cloud Linux release 3 (Soaring Falcon))

1.错误:configure: error: libnl-genl-3.0 package not found or too old. Is the development package and pkg-config (/usr/bin/pkg-config) installed?# ta.key在/etc/openvpn/server/目录下可以如下配置,否则需要写完整路径。# 配置账号密码登录客户端需要ca证书(可选)# 证书校验算法 配置上面生成的完整路径。# ca证书 配置上面生成的完整路径。

dubhe_zhao的博客 2159

HTML流光爱心(完整代码)

HTML语言实现红蓝色流光爱心效果的完整代码。

AIGC 1万+

uva1391Astronauts【2-SAT】

又是刘汝佳书上的题,貌似书上只有这两个了,确实2-SAT的题也没有太多,看邝斌的分类也才九个,今天加明天上午再A两个就结束~ 做这个题的时候发现自己对于结点的表示还是不够理解,遂把四种情况都列出来 xi为假 或xj为假 2*i+1==>2*j 2*j+1==>2*i xi为真或xj为真 2*i==>2*j+1 2*j==>2*i+1 xi为假或x

MissZhou要努力 625

多源异构数据融合(Kaggle+Google Trends联合分析)

本文详细介绍了如何利用Python实现多源异构数据融合,以Kaggle电商销售数据与Google Trends搜索指数为例,展示了数据清洗、预处理、时间对齐、数据合并、相关性分析、回归建模和可视化全过程。数据预处理与内存优化通过分块加载、数据类型转换和缺失值处理,有效降低了大规模数据在内存中的占用,并确保数据质量。时间对齐与数据融合策略采用重采样与内连接方法对齐不同数据源的时间维度,实现了高质量数据的融合,为后续联合分析奠定基础。模型构建与分析。

闲人编程的博客 1025

UVA 1391 Astronauts 2-sat

题目大意: 有n个宇航员,按照年龄划分,年龄低于平均年龄的是年轻宇航员,而年龄大于等于平均年龄的是老练的宇航员。 现在要分配他们去A,B,C三个空间站,其中A站只有老练的宇航员才能去,而B站是只有年轻的才能去,C站都可以去。 有m对宇航员相互讨厌,不能让他们在同一个空间站工作。 输出每个宇航员应分配到哪个空间站,如果没有则输出No solution.

ACMmaxx的专栏 881

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Astronauts UVA - 1391(2-sat)

Astronauts UVA - 1391 题意: 有n个人,且给出他们的年龄。这些人的平均年龄是x。 假如y【i】>= x。那么这个人可以选择 任务 A 或者 任务C。 反之。这个人可以选择 任务 B 或者 任务C。 现在给出这些人的讨厌关系,互相讨厌的人不可以分配到同一个任务。 问: 是否可以分配任务给这n个人。 思路: 可以先抽象,每个人按照年龄无非就是两种类型 :A∣∣||∣∣C or B∣∣||∣∣C。 所以可以构造限制条件。 假如两个人互相讨厌,如果是同一种类型。那么要满足 一真

qq_45377553的博客 187

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

UVA 1391 Astronauts(2-SAT)

这题其实算是一题水题,但是一开始想错了,一直把每位宇航员的选择分为A和B了,其实应该分成的是C和!C,这样分,很容易就想出来怎么写了。#include #include #include #include #include using namespace std; const int maxn=100000+5; struct TwoSAT{ int n; vector G[max

qq_33901573的博客 341

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

UVA 1391 Astronauts(2-SAT + 输出方案)

【题目链接】 http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=4137 【题目大意】 有n个宇航员,按照年龄划分,年龄低于平均年龄的是年轻宇航员,而年龄大于等于平均年龄的是老练的宇航员。 现在要分配他们去A,B,C

D_Double's Journey 1688

UVA 1391 Astronauts 2-sat

//#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<iostream> #include&l...

weixin_34378767的博客 149

[UVA]1391 Astronauts 2-Sat 朝花夕拾

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 mo

Le Petit Prince 435

UVA1391、LA3713【astronauts...】【2 -SAT】

这题一开始自己想到了3-SAT。。。 照着敲了个试试,好像不太对。。     深入的3-SAT不会,有点囧 然后就积极往2-SAT上想 想分开小于ave和大于等于ave的两部分各自2-SAT不能考虑某些情况,显然。。。 于是呵呵了。。   正解是分开讨论。       如果a和b都小于ave或都是大于等于ave的            或一个小于ave一个大于ave。。        

Beyyes 1050

uva 1391 Astronauts(2-SAT)

/*翻译好题意 n个变量 不超过m*2句话*/ #include<iostream> #include<cstdio> #include<cstring> #include<vector> #define maxn 200010 using namespace std; int n,m,f[maxn],c,s[maxn],age[m...

weixin_30725315的博客 116

UVA1391 Astronauts(ACM - ICPC 2006 Europe - Central)(2 - SAT问题、输出方案)

虽然题目里有A、B、C三种状态,但是每个人只有两个状态可以选择,显然是一道2-SAT; 建图的话,假设选择A(或者B)为i+n,选择C为i;首先当两个人讨厌时,一个人选C,则另一个一定选另一个,连两条边(x,y+n)和(y,x+n),同时若是两个人同类,则还需加上限制使两个人不能同时选A(或同时选B),就再连两条边(x+n,y),(y+n,x);最后跑一边tarjan 输出答案的话就不需要在跑一边拓扑排序了,因为在tarjan时强连通分量被染色的顺序就是拓扑序,所以若col(i)<col(i+n),.

繁凡さん的博客 557

Uva 1391 (LA 3713) Astronauts (2-SAT问题)

今天学了2-SAT问题,就找了这道例题,敲了一下,还好过了。 2-SAT问题应该是把一些布尔变量之间的逻辑关系反映到一个无向图(有时可能是有向图)上来。通过推导的形式(即已经明确不符合题意的两个变量之间的逻辑关系,通过确定其中一个变量的值,来推导出另一变量的值)在这个有向图里面补边。再通过确定一些变量的值,使所有的变量都能符合题意中逻辑关系。补边方式 即如果Xi = true &am...

weixin_30345055的博客 134

关于2-SAT(P4782 【模板】2-SAT 问题+P4171 [JSOI2010] 满汉全席+UVA11294 Wedding+​ UVA1391 Astronauts​+CF1215F)

这样子的题目解决方法:1. 先把一个点拆成两个点,分别表示这个点是1或0(一般表示0的点为x,表示1的点为x+n)2. 根据方程进行推理连边:如通过“ a ​为真或 b​ 为假”可以推至如果 a 是 1 ,那么 b 是 0 ,如果 a 是 0。那么 b 是 1。这样的话,我们就让a+n与b连边,a与b+n连边3. 判断是否有解,我们只需要跑一遍tarjan寻找强联通分量,如果一个点a和a+n在同一个强联通分量中,那么就吴姐,否则有解。

2303_76591444的博客 265

Uva1 1391/LA 3713 - Astronauts 构图2-sat...更正了toposort过程...

Program: #include #include #include #include #include #include #include #include #include #define oo 1000000007 #define MAXN 100005<<1 #define MAXM 100000<<2 #define ll long long using namespace std;

zzyzzy12 1078

利用c#语言解析xml文件,C#中常用的几种读取XML文件的方法

UVa 1391 Astronauts (2SAT)题意:给出一些宇航员他们的年龄,x是他们的平均年龄,其中A任务只能给年龄大于等于x的人,B任务只能给小于x的人,C任务没有限制.再给出m对人,他们不能同任务.现在要你输出一组符合要求的任务安排. 思路 ...cactive信号AXI中C-channel的cactive信号并不仅仅应用在CSYSREQ,CSYSACK交互中. CSYSREQ和CSY...

weixin_35663823的博客 376
上一篇: 2-SAT
下一篇: uva11374 - Airport Express 最短路
小小小小葱
博客等级 码龄14年 22粉丝 266原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值