Algernon's Noxious Emissions POJ1121 zoj1052

One of the greatest alchemists of the lower Middle Renaissance, Algernon da Vinci (one of Leonardo's lesserknown cousins), had the foresight to construct his chemical works directly over a fast-running stream. Through a series of clever pipes and sluices, he routed portions of the stream past each of the tables where his alchemists prepared their secret brews, allowing them to dispose of their chemical byproducts into the waters flowing by the table.
As Algernon's business grew, he even added additional floors to his
factory, with water lifted to the higher floors by treadmill-powered pumps (much
to the dismay of the apprentices who found themselves assigned to pump duty).
The pipework for the entire disposal system became quite complex. It was even
rumored by some that the pipes actually circled back in some places, so that a
particularly odorous compound flushed away from one table might return to that
very same spot a few minutes later.
All was not well, however.
Algernon's factory suffered from a series of mishaps, minor explosions, gas
clouds, etc. It became obvious that chemicals dumped at one table might react
violently with other chemicals dumped from another table downstream. Algernon
realized that he needed to trace the possible chemical flows through his
factory.
Write a program to aid Algernon in this task. To preserve the
secrecy of the chemical processes that are Algernon's stock in trade, all
chemicals will be identified by a single upper-case letter. All tables are
identified by positive numbers in the range 1��N, where N is the number of
tables.
Input Format:
Line 1:
# of work tables, integer
(henceforth referred to as N). N < 50
Lines 2��N+1
For each
table:
- a list of chemicals dumped into the stream at that table, followed by
- a list of chemicals that, if they appeared at that table, would be
harmlessly neutralized by the reactions at that table, allowing no further trace
of that chemical to flow downstream (we will assume that the rate of work at
each table can be adjusted as necessary to guarantee total neutralization of
whatever amount of these chemicals arrive from upstream).
Each
of these lists is given as a series of upper-case alphabetic characters. The
only exception is that a special list, consisting of a single '.' character,
will be used to denote an empty list. The two lists are separated from one other
by one or more blanks. The same chemical will never appear in both lists.
Lines N+2��?
These lines provide a description of the pipeworks.
Each line contains a pair of integers in the range 1��N, separated by one or
more blanks:
I J
meaning that the table number I is upstream of table
number J - anything dumped into the stream at table I or that arrives in the
stream at table I and is not neutralized can then be counted on to arrive at
table J.
No (I,J) pair will be listed more than once, but the pairs may occur in any
order. I and J will never be the same number.
The end of input is
signaled by a pair of zeros:
0 0
Note that if a table only receives
water directly from the stream entering the building, that table will never
occur in the second position of a pair. Similarly, any table that discharges
only into the stream leaving the building will never occur in the first position
of a pair.
Output Format:
There will be N lines of output, one for each
table, in the same order as they appeared in the program input. Each line will
contain the list of chemicals that can be expected at that table's output. This
list will be printed as a (possibly empty) list of upper-case alphabetic
characters between two colons (:). No empty spaces should be printed on the
line. The characters in the list should be sorted in alphabetic order.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line
followed by N input blocks. Each input block is in the format indicated in the
problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between
output blocks.

Sample Input:
For the figure at the right, an input would be:
1
4
AB C
C BDA
BCD .
. A
1 2
2 4
3 1
1 3
3 4
0 0
Sample Output:
:ABD:
:C:
:ABCD:
:BCD:
POJ是一个测试案例,只需注释Line 和ICase这几行就行。
#include <stdio.h>
#include <memory.h> const int MAXN = ; int main()
{
int i, j;
int mask[];
for (i = ; i < ; i++)
mask[i] = <<i;
int iCase;
scanf("%d", &iCase);
int line = ;
while (iCase--)
{
if (line) printf("\n");
line = ;
int output[MAXN];
int dump[MAXN];
int neutra[MAXN];
char c;
int n;
scanf("%d\n", &n);
for (i = ; i <= n; i++)
{
int temp = ;
do {
c = getc(stdin);
if (c >= 'A') temp |= mask[c-'A'];
} while (c != ' ');
dump[i] = output[i] = temp;
temp = ;
while((c = getc(stdin)) != '\n')
if (c >= 'A') temp |= mask[c-'A'];
neutra[i] = temp;
dump[i] &= ~temp;
output[i] &= ~temp;
}
bool graph[MAXN][MAXN];
bool table[MAXN];
memset(graph, , sizeof(graph));
for (i = ; i <= n; i++)
table[i] = true;
int a, b;
while(scanf("%d %d", &a, &b) && (a || b))
graph[a][b] = true;
bool flag;
do {
flag = false;
for (i = ; i <= n; i++)
if (table[i])
{
table[i] = false;
int temp = output[i];
for (j = ; j <= n; j++)
if (graph[i][j])
{
int newOut = (output[j] | temp) & (~neutra[j]);
if (output[j] != newOut)
{
output[j] = newOut;
table[j] = true;
}
}
flag = true;
break;
}
} while (flag);
for (i = ; i <= n; i++)
{
printf(":");
for (j = ; j <= ; j++)
if ((output[i] & mask[j]) != )
printf("%c", char(j+'A'));
printf(":\n");
}
}
return ;
}
Algernon's Noxious Emissions POJ1121 zoj1052的更多相关文章
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- algernon 基于golang 的独立的支持redis lua pg。。。 的web server
algernon 看到github 的介绍很很强大,一下子想到了openresty,功能看着很强大,支持 redis pg lua markdown quic http2 mysql 限速 pongo ...
- 38 Cell-phone Emissions can change Brain Activity 手机辐射有可能改变大脑活动
Cell-phone Emissions can change Brain Activity 手机辐射有可能改变大脑活动 So many people use the cell phone so fr ...
- Lesson 11 Not guilty
Lesson 11 Not guilty guilty ['gɪlti] adj. 有罪的:内疚的 be guilty of - He is guilty of murder. be innocent ...
- RXJava by Example--转
原文地址:https://www.infoq.com/articles/rxjava-by-example Key takeaways Reactive programming is a specif ...
- Android Weekly Notes Issue #223
Android Weekly Issue #223 September 18th, 2016 Android Weekly Issue #223 本期内容包括: Offline时间戳处理; Acces ...
- rxjs5.X系列 —— transform系列 api 笔记
欢迎指导与讨论:) 前言 本文是笔者翻译 RxJS 5.X 官网各类operation操作系列的的第一篇 -- transform转换.如有错漏,希望大家指出提醒O(∩_∩)O.更详细的资料尽在rxj ...
- 安卓中的Model-View-Presenter模式介绍
转载自:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0425/2782.html 英文原文:Introduction to M ...
随机推荐
- 2016 Multi-University Training Contest 5 1012 World is Exploding 树状数组+离线化
http://acm.hdu.edu.cn/showproblem.php?pid=5792 1012 World is Exploding 题意:选四个数,满足a<b and A[a]< ...
- Tkinter教程之Event篇(1)'
本文转载自:http://blog.csdn.net/jcodeer/article/details/1823544 ''Tkinter教程之Event篇(1)'''# 事件的使用方法'''1.测试鼠 ...
- 【转】VC6.0附带小工具软件一览
)ActiveX Control Test Container称为"ActiveX 控件测试容器",顾名思义,此工具的主要功能就是测试ActiveX 控件,可以通过改变Active ...
- python编码问题的理解与解决
错误:'ascii' codec can't encode characters in position 0-1: ordinal not in range(128) 看到网上很多都不清楚,做了一天的 ...
- Oracle 查看表空间大小及其扩展
在ORACLE数据库中,所有数据从逻辑结构上看都是存放在表空间当中,当然表空间下还有段.区.块等逻辑结构.从物理结构上看是放在数据文件中.一个表空间可由多个数据文件组成.系统中默认创建的几个表空间:S ...
- VMware搭建12.0搭建Mac OS10.11详细过程
1.软件准备 1.1VMware12.0 1.2VMware增强包 1.3Mac OS10.11 cdr(相当于dmg) 1.4securable.exe 2.软件破解 2.1VMware输入序列号破 ...
- 模板引擎doT.js介绍及如何判断对象为空、如何嵌套循环···
doT.js 灵感来源于搜寻基于 V8 和 Node.js ,强调性能,最快速最简洁的 JavaScript 模板函数 引入 javascript 文件: <script type=" ...
- 8086、80x86(IA-32)、64(IA-64)位CPU发展
众所周知,CPU(中央处理单元)是计算机的核心部分,CPU在单位时间内能一次处理的二进制数的位数叫字长,从386.486直到奔腾系列的CPU都是32位,大多数情况32位计算已经能满足现阶段人们的需要. ...
- 剑指OFFER之跳台阶(九度OJ1388)
题目描述: 一只青蛙一次可以跳上1级台阶,也可以跳上2级.求该青蛙跳上一个n级的台阶总共有多少种跳法. 输入: 输入可能包含多个测试样例,对于每个测试案例, 输入包括一个整数n(1<=n< ...
- 十,选择cfee编辑器并学会调试程序。以及结束语。
为什么推荐用cfree呢?因为我认为这个编辑器界面友好,用起来方便. 你也许会问,调试程序是什么? 那么下面思考几个问题:对于前面讲的分支结构和循环结构有点不懂怎么办?如果写的程序语法没有错误但是运算 ...