Gym - 100623I Important Wires-翻译题。水题

Nick bought a new motherboard for his computer and it seems
耐克给他电脑买了一个电路板但是这个电脑好像坏了,
that it does not work properly. The
并且主板(motherboard)非常复杂,就像一团面条,只有几个非常非常重要的线头,这些线头 有两种状态,真或者假。
motherboard is pretty complicated but it has only few important wires that have binary states: live or
dead. Nick wants to know the states of these wires.
耐克想搞明白这些线的状态
Unfortunately, important wires are not directly accessible. But
不幸的是,不好弄啊,于是耐克发现了一个面包板(maintenance socket)之类的东西。
Nick found a maintenance socket. Each
output pin of this socket is connected to some of important wires via an integrated circuit.
这些面包板有引脚,然后他发现了这些引脚和重要的线之间的关系。
和离散数学一样。
Fortunately,
Nick found the circuit layout in the Internet. To specify it, he marked important wires by lowercase
letters and socket’s output pins by uppercase letters. After that he wrote down Boolean formula for each
output pin. In these formulae live wires and pins are represented by true and dead wires — by false.
Nick used following notation for formulae (operations are listed from the highest priority to the lowest):
• Pin names — letters from ‘a’ to ‘k’;
• Parentheses — if E is a formula, then (E) is another;
• Negation — ¬E is a formula for any formula E;
• Conjunction — E1 ∧ E2 ∧ · · · ∧ En;
• Disjunction — E1 ∨ E2 ∨ · · · ∨ En;
• Implication — E1 ⇒ E2 ⇒ · · · ⇒ En. Implication is evaluated from right to left: E1 ⇒ E2 ⇒ E3
means E1⇒(E2⇒E3);
• Equivalence — E1 ≡ E2 ≡ · · · ≡ En. This expression is by definition computed as follows:
(E1 ≡ E2) ∧ (E2 ≡ E3) ∧ · · · ∧ (En−1 ≡ En).
发现了规律之后,耐克想装逼了,想造一个新的电路板,并且享用到所有他的发现的公式。
Nick has lots of various gates at hand, so he can build a new circuit that implements any formula. The
variables of this formula are states of maintenance socket’s pins. 大量的这种公式和面包板的输出引脚一一对应
First of all, Nick wants to construct a
circuit that takes all maintenance socket’s pins as inputs and
现在他想把这些引脚用了(两层封装相当于。。),并且让电路永远是真。
has a single output wire that is always live.
Write a program to help him.
Input
The first line of the input file contains a single integer number n — the number of pins in the maintenance
socket (1 ≤ n ≤ 10). The following n lines contain description of one pin each.
Each pin description consists of a pin name and corresponding formula delimited by ‘:=’ token. Pin
name is a uppercase English letter. Formula is represented by a string consisting of tokens ‘a’..‘k’, ‘(’,
‘)’, ‘~’, ‘&’, ‘|’, ‘=>’, and ‘<=>’. The last five tokens stand for ¬, ∧, ∨,⇒and ≡ respectively. Tokens can
be separated by an arbitrary number of spaces. Each pin description contains 1 000 characters at most.
Output
The first line of the output file must contain “Yes” if there exists a circuit which output wire is always
live and “No” otherwise.
In the former case the following line must contain the formula for the constructed circuit in the same
format as in the input file. Remember that the formula must contain each of pin names at least once
and it must not contain the wire names. The line must not exceed 1 000 characters.

耐克有病。。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
using namespace std;
const int maxn = 1e6+100;
const int inf = 0x7fffffff;
char a[15][1005];
int main(void)
{
    freopen("important.in","r",stdin);
    freopen("important.out","w",stdout);
    int n;
    scanf("%d",&n);
    getchar();
    for(int i=0;i<n;i++)
        gets(a[i]);
    puts("Yes");
    for(int i=0;i<n;i++)
        printf("%c|",a[i][0]);
    printf("~%c",a[0][0]);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值