`
Simone_chou
  • 浏览: 195918 次
  • 性别: Icon_minigender_2
  • 来自: 广州
社区版块
存档分类
最新评论

Astronauts(2 - sat)

    博客分类:
  • UVA
 
阅读更多

1391 - Astronauts

Time limit: 3.000 seconds

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 <tex2html_verbatim_mark>and 1$ \le$m$ \le$100000 <tex2html_verbatim_mark>. The number n <tex2html_verbatim_mark>is the number of astronauts. The next n <tex2html_verbatim_mark>lines specify the age of then <tex2html_verbatim_mark>astronauts; each line contains a single integer number between 0 and 200. The next m <tex2html_verbatim_mark>lines contains two integers each, separated by a space. A line containing i <tex2html_verbatim_mark>and j <tex2html_verbatim_mark>(1$ \le$ij$ \le$n) <tex2html_verbatim_mark>means that the i <tex2html_verbatim_mark>-th astronaut and the j <tex2html_verbatim_mark>-th astronaut hate each other.

The input is terminated by a block with n = m = 0 <tex2html_verbatim_mark>.

 

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 <tex2html_verbatim_mark>-th line describes which mission the i <tex2html_verbatim_mark>-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

 

       题意:

       给出 N(1 ~ 100000) 个人,M (1 ~ 100000)条互相讨厌的两个人。后给出这 N 个人的年龄(0 ~ 200),每个人都必须完成 A,B,C 中的其中一个任务,A任务条件为 年龄 大于等于年龄平均值,B任务条件为小于年龄平均值,C任务没有特殊条件。互相讨厌的两个人不能同时做同一个任务。问能否合适安排的任务内容满足所有的条件,能则输出每个人的任务。不能则输出 No solution. 。

 

       思路:

       2 - sat。根据 a 和 b的讨厌关系可以确定一种确定的关系,若 a 和 b 在相同的年龄段(两个时间段),则 a 选 A 或者 B 的话,则 b 必须选 C;b 选 A 或者 B 的话,则 a 必须选 C;a 选 C 的话,b 必须选 A 或者 B;b 选 C 的话,a 必须选 A 或者 B;可以确定四种关系。若 a 和 b 不在同一个年龄段,则 a  选 C 的话,b 必须选 A 或者 B; b 选 C 的话,b 必须选 A 或者 B;可以确定两种关系。根据这个就可以建图了。最后 2 - sat 求出答案即可。

       另外,判断年龄是否大于平均值,必须要用 age [ i ] * N > sum ,直接除以取平均值是不够准确的。

 

       AC:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <stack>

using namespace std;

const int NMAX = 100005 * 2;
const int EMAX = NMAX * 4;

int n, m, x;
int age[NMAX];
vector<int> v[NMAX];

int scc_cnt, dfs_clock;
int pre[NMAX], low[NMAX], cmp[NMAX];
stack<int> s;

void dfs (int u) {
        pre[u] = low[u] = ++dfs_clock;
        s.push(u);

        for (int i = 0; i < v[u].size(); ++i) {
                if (!pre[ v[u][i] ]) {
                        dfs( v[u][i] );
                        low[u] = min(low[u], low[ v[u][i] ]);
                } else if (!cmp[ v[u][i] ]) {
                        low[u] = min(low[u], pre[ v[u][i] ]);
                }
        }

        if (low[u] == pre[u]) {
                ++scc_cnt;
                for ( ;;) {
                        int x = s.top(); s.pop();
                        cmp[x] = scc_cnt;
                        if (x == u) break;
                }
        }
}

void scc() {
        scc_cnt = dfs_clock = 0;
        memset(pre, 0, sizeof(pre));
        memset(cmp, 0, sizeof(cmp));

        for (int i = 1; i <= 2 * n; ++i) {
                if (!pre[i]) dfs(i);
        }
}

int main() {
        while (~scanf("%d%d", &n, &m) && (n + m)) {
                x = 0;
                for (int i = 1; i <= 2 * n; ++i)
                        v[i].clear();

                for (int i = 1; i <= n; ++i) {
                        scanf("%d", &age[i]);
                        x += age[i];
                }

                while (m--) {
                        int a, b;
                        scanf("%d%d", &a, &b);
                        if ( (age[a] * n >= x && age[b] * n >= x) ||
                             (age[a] * n < x && age[b] * n < x) ) {
                                v[a].push_back(n + b);
                                v[b].push_back(n + a);
                                v[n + a].push_back(b);
                                v[n + b].push_back(a);
                        } else {
                                v[n + a].push_back(b);
                                v[n + b].push_back(a);
                        }
                }

                scc();

                int temp = 0;
                for (int i = 1; i <= n; ++i) {
                        if (cmp[i] == cmp[i + n]) {
                                printf("No solution.\n");
                                temp = 1;
                                break;
                        }
                }

                if (!temp) {
                        for (int i = 1; i <= n; ++i) {
                                if (cmp[i] < cmp[i + n]) {
                                        if (age[i] * n >= x) printf("A\n");
                                        else printf("B\n");
                                } else printf("C\n");
                        }
                }
        }
        return 0;
}

 

 

分享到:
评论

相关推荐

    2017_2018学年八年级英语下册Module3JourneytospaceUnit1Hasitarrivedyet同步练习新

    - 航天员(astronauts) - 发现(discover) - 到达(arrive) - 项目(projects) - 地球(Earth) 2. 语法结构: - 复数形式:如"models"、"astronauts" - 现在进行时:如"What are you doing?"中的"are doing" - ...

    astronauts-py

    第一步是浏览该存储库中的代码,尤其是所有主要逻辑所在的astronauts.py中的代码。 请注意,您认为应该得到特别赞赏的任何代码行都非常清晰,或者您认为应该以任何方式对其进行改进-以便使含义更清楚或修复发现的...

    astronauts

    自述文件 该自述文件通常会记录启动和运行应用程序所需的所有步骤。 您可能要讲的内容: Ruby版本 系统依赖 配置 数据库创建 数据库初始化 如何运行测试套件 服务(作业队列,缓存服务器,搜索引擎等) ...

    Astronauts New Tab Space Theme-crx插件

    在每个新选项卡上都包括宇航员的高清图像。...通过我们的扩展程序,您可以获得:1:高分辨率的新标签页体验2:简单,干净的视图-无图块! 3:没有广告或烦人的弹出窗口 语言:English (United States)

    江苏省连云港市赣榆县智贤中学高中英语 Unit 3 Amazing people同步练习(七)牛津译林版必修2

    - 当宇航员的必修课目:compulsory subjects for astronauts - 十四个中的三个:three out of fourteen - 一个合格的医生:a qualified doctor - 载入史册:go down in history - 实现梦想:fulfill one's ...

    Space Suit Evolution From Custom Tailored To Off-The-Rack

    Apollo Space Suits Were Custom Tailored The Apollo space suit was basically a one-piece suit. Each suit was made to fit (custom ... The astronaut corps at that time included between 25 and 27 astronauts.

    2018_2019学年九年级英语下册Unit10GetReadyfortheFuture随堂练习二新版冀教版2018081742

    4. astronauts - "astronaut"的复数形式,表示“宇航员”。 5. period - 表示“时期”,此处为单数形式。 II. 用适当的介词填空: 1. to - "pay attention to"是固定搭配,意为“注意”。 2. for - "get ready for...

    21世纪大学英语读写教程(第二册)课后翻译答案1-8单元[借鉴].pdf

    2. 使用过去完成时态表示过去的动作在过去的某个时间点之前已经完成,如“When seven astronauts died in the Challenger disaster in the mid-1980s, it plunged the whole world into shock and grief.”中使用了...

    武汉中考高频词汇练习题.doc

    它可以指语言或其他方式传达的思想,如"Language is a means for the expression of thought.",也可以指人脸上的神情,如"Levin sat there, an expression of sadness on his face." **拓展**: - **express** - ...

    debian-handbook.pdf

    the work of ISS astronauts, maybe via the social network presence of NASA or other interna- tional organizations? Both the work in itself and the posts about it have been made possible by Debian. ...

    八年级英语Languageinuse5PPT学习教案.pptx

    - "Many astronauts have already visited the space station." 表示许多宇航员已经参观过空间站。 - "The space craft has just reached Mars." 表示宇宙飞船刚刚到达火星。 - "We’ve already known that there...

    陕西省渭南市2012-2013学年高一英语下学期第一次月考试题新人教版

    - 在选择题中,我们需要对句子成分有清晰的理解,例如题目1中的"What our astronauts desire to do"是主语从句,what作为从句的宾语,表示宇航员想要做的事情。 - 题目2考察了不定式和宾语从句的用法,"all that I...

    2020新教材高中英语Unit4SPACEEXPLORATIONSectionAListeningandSpeaking练习新人

    - "astronauts" 是astronaut的复数形式,表示“宇航员”。 - "related to" 表示“与...有关”,是固定搭配。 - "similar to" 表示“与...相似”,也是固定搭配。 - "to go" 是不定式短语作后置定语,修饰the ...

    八年级英语下册Module3JourneytospaceUnit1Hasitarrivedyet同步练习含解析新版外研版

    - "Lots of scientists are working hard in order to send astronauts to Mars one day.":表达目的的句型,用"in order to"引导。 4. 单项选择题策略: - 了解动词短语搭配,如"be up to"(忙于),"on"与...

    八下动词.pdf

    如例子所示,Astronauts have discovered many galaxies in the universe so far. 这表明发现银河系的动作在过去发生,至今仍在影响着我们。 2. **并列连词And的时态一致**:当And连接两个句子时,前后动词时态通常...

    高中英语选修UnitwordsandexpressionsPPT学习教案.pptx

    - The astronauts were training hard so that they could be suited for the exploration of Mars. 3. **suit, match, fit** - 这三个词都有“适合”的含义,但用法上有所区别: - **suit** 主要强调主观上的...

    英语单词考研的70天背单词

    - The astronauts said that the Great Wall is the only man-made object that can be seen from the moon.(宇航员说,长城是唯一能从月球上看到的人工建筑物。) ##### atom - **词性**:名词 - **词根分析**:...

    Cloud Computing_Concepts and Practices-Springer(2018).pdf

    This is amazing, espe- cially considering that even a smartphone has more memory and compute than was present on the entire Saturn V rocket that carried astronauts to the Moon and back. This implies ...

    unity迷你太空射击游戏源码

    You can choose what game you want to play: killing enemies in Space War, or rescuing astronauts in Space Rescue. This is a complete game with fully commented sc ripts in C#. In this game you can see...

Global site tag (gtag.js) - Google Analytics