POJ1747 Expression水题

Posted 海岛Blog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了POJ1747 Expression水题相关的知识,希望对你有一定的参考价值。

Expression
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 917 Accepted: 530

Description

It is known that Sheffer stroke function (NOT-AND) can be used to construct any Boolean function. The truth table for this function is given below:
Truth table for Sheffer stroke function

xyx|y
001
011
101
110

Consider the problem of adding two binary numbers A and B, each containing N bits. The individual bits of A and B are numbered from 0 (the least significant) to N-1 (the most significant). The sum of A and B can always be represented by N+1 bits. Let’s call most significant bit of the sum (bit number N) the overflow bit.

Your task is to construct a logical expression using the Sheffer stroke function that computes the value of the overflow bit for arbitrary values of A and B. Your expression shall be constructed according to the following rules:
Ai is an expression that denotes value of ith bit of number A.
Bi is an expression that denotes value of ith bit of number B.
(x|y) is an expression that denotes the result of Sheffer stroke function for x and y, where x and y are expressions.

When writing the index, i, for bits in A and B, the index shall be written as a decimal number without leading zeros. For example, bit number 12 of A must be written as A12. The expression should be completely parenthesized (according to the 3rd rule). No blanks are allowed inside the expression.

Input

The input contains a single integer N (1 <= N <= 100).

Output

Write to the output an expression for calculating overflow bit of the addition of two N-bit numbers A and B according to the rules given in the problem statement.
Note: The stroke symbol ( | ) is an ASCII character with code 124 (decimal).

The output size shall not exceed 50*N bytes.

Sample Input

2

Sample Output

((A1|B1)|(((A0|B0)|(A0|B0))|((A1|A1)|(B1|B1))))

Source

Northeastern Europe 1999

问题链接POJ1747 Expression
问题简述:(略)
问题分析:简单题,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* POJ1747 Expression */

#include <iostream>
#include <cstdio>

using namespace std;

const int N = 100;
char s[N + 1][5000];

int main()
{
    int n;
    scanf("%d", &n);

    sprintf(s[0], "((A0|B0)|(A0|B0))");
    for (int i = 1; i < n; i++)
        sprintf(s[i], "((A%d|B%d)|(%s|((A%d|A%d)|(B%d|B%d))))", i, i, s[i-1], i, i, i, i);

    puts(s[n - 1]);

    return 0;
}

以上是关于POJ1747 Expression水题的主要内容,如果未能解决你的问题,请参考以下文章

P1747 好奇怪的游戏

A. Expression1000 / 水题

POJ 3685 二分套二分(水题

POJ 2545+2591+2247+1338简单水题

POJ 2503Babelfish(水题)stl map存取即可

POJ 2386 Lake Counting (水题,DFS)