博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Algernon's Noxious Emissions POJ1121 zoj1052
阅读量:7226 次
发布时间:2019-06-29

本文共 6062 字,大约阅读时间需要 20 分钟。

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 
#include
const int MAXN = 51;int main(){ int i, j; int mask[32]; for (i = 0; i < 32; i++) mask[i] = 1<
= 'A') temp |= mask[c-'A']; } while (c != ' '); dump[i] = output[i] = temp; temp = 0; 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, 0, sizeof(graph)); for (i = 1; 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 = 1; i <= n; i++) if (table[i]) { table[i] = false; int temp = output[i]; for (j = 1; 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 = 1; i <= n; i++) { printf(":"); for (j = 0; j <= 25; j++) if ((output[i] & mask[j]) != 0) printf("%c", char(j+'A')); printf(":\n"); } } return 0;}

 

转载于:https://www.cnblogs.com/767355675hutaishi/p/3913761.html

你可能感兴趣的文章
LinkedHashSet 元素唯一,存储取出有序
查看>>
!!!四种常见的 POST 提交数据方式(含application/json)
查看>>
vim的用法简介
查看>>
Docker快速入门
查看>>
Linux运维常见面试题之精华收录
查看>>
Open Source的一些网站,自己收集来的
查看>>
导入ubuntu虚机配置,基于XEN4.0
查看>>
Script:收集UNDO诊断信息
查看>>
jmeter连接数据库-华山
查看>>
opencv 源码编译
查看>>
将旧硬盘的内容克隆到新硬盘
查看>>
Linux文件管理类命令之rm
查看>>
如何在Kubernetes中暴露服务访问
查看>>
NTP常见问题和解决方案&配置文件详解
查看>>
crontab计划任务补充知识
查看>>
数据库备份
查看>>
独家 | 图灵奖得主Raj Reddy:通用AI还很遥远,人类将成宠物
查看>>
java中自动生成XML文件
查看>>
Docker 数据卷,数据卷容器详细介绍
查看>>
VS2015编译Live555流媒体服务器
查看>>