Time Limit: 1000MS | Memory Limit: 65536K | |||
Total Submissions: 7920 | Accepted: 2394 | Special Judge |
Description
Up to thirty couples will attend a wedding feast, at which they will be seated on either side of a long table. The bride and groom sit at one end, opposite each other, and the bride wears an elaborate headdress that keeps her from seeing people on the same side as her. It is considered bad luck to have a husband and wife seated on the same side of the table. Additionally, there are several pairs of people conducting adulterous relationships (both different-sex and same-sex relationships are possible), and it is bad luck for the bride to see both members of such a pair. Your job is to arrange people at the table so as to avoid any bad luck.
Input
The input consists of a number of test cases, followed by a line containing 0 0. Each test case gives n, the number of couples, followed by the number of adulterous pairs, followed by the pairs, in the form "4h 2w" (husband from couple 4, wife from couple 2), or "10w 4w", or "3h 1h". Couples are numbered from 0 to n - 1 with the bride and groom being 0w and 0h.
Output
For each case, output a single line containing a list of the people that should be seated on the same side as the bride. If there are several solutions, any one will do. If there is no solution, output a line containing "bad luck".
Sample Input
10 6 3h 7h 5w 3w 7h 6w 8w 3w 7h 3w 2w 5h 0 0
Sample Output
1h 2h 3w 4h 5h 6h 7h 8h 9h
题意:
给出 N(<= 30)对夫妇 和 M 对通奸关系。现在这些人要和一堆新婚夫妇在饭桌前吃饭,饭桌面对着共有两边。夫妻必须面对面做,新娘能望见对面的所有人,新娘不能同时看见一对通奸关系的人。现要安排座位,是否能按要求分配座位。
思路:
2 - sat。新娘新郎的位置要判矛盾,故要增加两条边。
AC:
#include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include <vector> #include <stack> using namespace std; const int NMAX = 65 * 2; int n, m; vector<int> G[NMAX]; int res[NMAX]; int pre[NMAX], low[NMAX], cmp[NMAX]; int dfs_clock, scc_cnt; stack<int> s; void dfs(int u) { pre[u] = low[u] = ++dfs_clock; s.push(u); for (int i = 0; i < G[u].size(); ++i) { int v = G[u][i]; if (!pre[v]) { dfs(v); low[u] = min(low[u], low[v]); } else if (!cmp[v]) { low[u] = min(low[u], pre[v]); } } if (pre[u] == low[u]) { ++scc_cnt; for ( ;;) { int x = s.top(); s.pop(); cmp[x] = scc_cnt; if (x == u) break; } } } void scc() { dfs_clock = scc_cnt = 0; memset(pre, 0, sizeof(pre)); memset(cmp, 0, sizeof(cmp)); for (int i = 0; i < 2 * n; ++i) { if (!pre[i]) dfs(i); } } int main() { while (~scanf("%d%d", &n, &m) && (n + m)) { n *= 2; for (int i = 0; i < 2 * n; ++i) G[i].clear(); for (int i = 0; i < n; i += 2) { G[i].push_back(i + 1 + n); G[i + n].push_back(i + 1); G[i + 1].push_back(i + n); G[i + 1 + n].push_back(i); } G[n + 0].push_back(0); //固定新娘只能在一边坐 G[1].push_back(1 + n); //固定新郎只能在对面坐 while (m--) { int A, B; char sex; scanf("%d%c", &A, &sex); A = A * 2 + (sex == 'h'); scanf("%d%c", &B, &sex); B = B * 2 + (sex == 'h'); G[A + n].push_back(B); G[B + n].push_back(A); } scc(); int temp = 0; for (int i = 0; i < n; ++i) { if (cmp[i] == cmp[i + n]) { printf("bad luck\n"); temp = 1; break; } } if (!temp) { int ans = 0; for (int i = 2; i <= n; ++i) if (cmp[i] < cmp[i + n]) res[ans++] = i; for (int i = 0; i < ans; ++i) { printf("%d", res[i] / 2); res[i] % 2 ? printf("h") : printf("w"); i == ans - 1 ? printf("\n") : printf(" "); } } } return 0; }
相关推荐
【标题】"7701 Wedding Intro-玫瑰花瓣婚礼相册片头.rar"是一个压缩包文件,其中包含了一个AE(After Effects)模板,专门用于创建浪漫的婚礼相册片头,其主题为“玫瑰花瓣婚礼”。这个模板可以为新人的婚礼视频增添...
【标题】"wedding-marta-daniele-源码.rar" 暗示这是一个与婚礼相关的项目源代码压缩包。通常,这样的项目可能涉及到网站、应用程序或者某种互动媒体设计,用于展示婚礼信息、照片、视频或者供宾客互动使用。源码是...
【标题】"wedding-fair-pure-html-css-js"是一个基于纯HTML、CSS和JavaScript的项目,它展示了如何使用这些核心技术来创建一个婚礼展览相关的网页应用。这个项目可能是一个在线平台,供人们浏览和了解婚礼服务,或者...
2. **供应商搜索**:集成一个数据库,用户可以搜索并查看喀拉拉邦的婚礼服务商,对比服务质量和价格。 3. **灵感画廊**:展示不同风格的喀拉拉邦婚礼图片,为用户提供创意和灵感。 4. **日程规划**:帮助用户规划...
该项目为Java驱动的WeeDay-Wedding-Web婚礼模板设计源码,包含65个文件,包括25个JPG图片、7个CSS样式表、6个JavaScript脚本、4个WOFF字体、4个PNG图片、3个XML配置文件、3个EOT字体以及2个偏好设置和1个classpath...
婚礼照相应用程序 相依性 版本 苹果系统 卡塔琳娜10.15.7 节点 v15.4.0 npm 7.0.15 Nuxt ...git clone https://github.com/taiga-tech/wedding-photo-nuxt/ cd wedding-photo-nuxt npm install npm run dev 参考
本压缩包包含了四款针对人像摄影的独特预设,分别是“bynatali_sweet_wedding_lightroom_preset”和三款以婚礼为主题的预设:“Wedding Pink-2”,“Wedding Blue-2”以及“Wedding Green-2”。 1. **bynatali_...
数据集-目标检测系列- 婚纱 检测数据集 wedding_dress >> DataBall 标注文件格式:xml 项目地址:https://github.com/XIAN-HHappy/ultralytics-yolo-webui 通过webui 方式对ultralytics 的 detect 检测任务 ...
本篇文章将深入探讨“Wedding-Dress-Boxes”项目的源代码,这是一款与婚礼礼服相关的系统开源项目。通过对该项目源代码的解析,我们将揭示其中的技术架构、设计模式以及实现原理,旨在帮助读者理解和应用开源技术。 ...
"wedding-line-bot"是一个基于JavaScript的项目,主要用于创建一个婚礼主题的Line聊天机器人。Line是一款流行的即时通讯软件,尤其在日本、台湾和泰国等地广泛使用。这个机器人节点旨在为用户提供与婚礼相关的互动...
2. **RSVP追踪**:通过集成的RSVP功能,宾客可以在线确认出席与否,实时更新出席情况,减少手动跟踪的困扰。 3. **到达时间设定**:为避免婚礼现场的混乱,系统能帮助设定每个宾客的预计到达时间,便于合理规划接待...
Wedding-invitation婚礼邀请函微信小程序,前端+后端+数据库 小程序前端是fork的 现在已经迁移到云开发,不需要域名和服务器。前提申请一个小程序账号入门clone本项目,并通过微信开发工具导入,导入时填入你的appid...
"wedding-web-apps"是一个由开发者Panji Ramadhan和Bagas Tri Wibowo创建的项目,专注于构建用于婚礼的网页应用。这个项目在2021年完成,主要技术栈是JavaScript,这是一种广泛应用于网页开发的编程语言,特别适合...
【wedding-site-redux】是一个项目名称,从描述中我们可以推断,这可能是一个为劳伦和斯科特的婚礼创建的网站的源代码仓库。这个项目可能是为了展示婚礼的细节,如时间、地点、新人故事、婚纱照、婚礼流程等,并可能...
Wedding-RSVP-网站
【压缩包子文件的文件名称列表】"wedding-gallery-wall-master"暗示了这是一个GitHub仓库的默认分支名称,通常包含了项目的源代码、资源文件、配置文件等。在这个目录下,我们可能会找到如"pages"、"components"、...
小鹰正在为自己的婚礼做准备,她所有的朋友都被邀请参加婚礼。帮助小鹰为她的梦想婚礼做准备,图片 小鹰正在为自己的婚礼做准备,并邀请所有朋友参加婚礼。帮助小鹰为自己的梦想婚礼做准备,挑选最好的婚纱,漂亮的...
最好的婚礼摄影师,你的钱,期间。 Pixelicious是一位来自加拿大蒙特利尔的婚礼摄影师,它迎合那些希望在婚礼当天获得不妥协体验的最独特,最特权的新娘。 通过提供优质的图像,出色的客户服务和难忘的体验,...