#P9927. [NFLSPC #6] 真理祭坛
[NFLSPC #6] 真理祭坛
Background
It was getting late, and the crowd of onlookers had mostly dispersed. People probably did not notice that there was still a thin figure running toward the Altar of Truth.
“Which field are you a scientist in? Why are you alone?” The risk remover tilted his head and asked little Y in front of him.
“I’m not a scientist. I’m just a high school student.”
“A student?” The risk remover was confused. “Then what do you want to ask?”
“I want to know the ultimate law of the universe.”
“Since you’re just a student, how do you think I should help you understand the laws of the universe?”
“Huh?” Little Y seemed surprised. After a moment, a bit of disappointment appeared on his face. “Shouldn’t the truth of the universe be so simple that everyone can understand it... Shouldn’t it?”
“Truth is not that simple. Leaving the universe aside, I’ll casually give you some ‘principles’ here. Can you describe them in concise language?”
Little Y raised his head, looked at the dense strings of zeros and ones displayed in the sky by holographic projection, and fell into deep thought.
Problem Description
There are propositional variables, denoted as . Their truth values are Boolean values: either or .
We call a principle a function that takes Boolean values as input and outputs one Boolean value, i.e., a mapping .
Strings that satisfy certain conditions are called Well-Formed Formulas (WFF). Each WFF corresponds to exactly one principle, called the formula’s truth table. Specifically:
- A propositional variable is a WFF. Its truth table always outputs the -th input value it receives (the indices of the input values are ).
- If strings () are all WFFs, then is also a WFF. When its truth table receives an input , its output is the minimum of the outputs of the truth tables of on input .
- If strings () are all WFFs, then is also a WFF. When its truth table receives an input , its output is the maximum of the outputs of the truth tables of on input .
- If is a WFF, then is also a WFF. Suppose the truth table of outputs on input , then the truth table of outputs on input .
Define the size of a WFF as the number of and it contains. Now, given a principle, find a WFF whose truth table equals that principle, and under this condition make the formula’s size as small as possible.
Input Format
This is an output-only problem. All testdata formula1.in to formula10.in are provided in the attached files.
The first line of the input contains an integer .
The second line contains a string of length , describing the given principle: if for any , the -th input value is , then the output of the principle is .
The third line contains scoring parameters; their specific use is described in “Hint”.
Output Format
For the given input files, you need to submit your output files formula1.out to formula10.out respectively.
Each output file contains one line, representing the WFF you provide. Parentheses are written as (). Propositional variable is written as the digit i (since , this is guaranteed to be a single character). is written as &, is written as |, and is written as !. Do not omit parentheses on your own.
2
1101
1 1 1 1 1 1 1 1 1 1
(!1|0)
Hint
For all testdata, .
For each test case, we score as follows:
- If your output length is greater than , you get points.
- If your output is not a WFF, you get points.
- If the truth table of your WFF is different from the input principle, you get points.
- If none of the above happens, let be the scoring parameters, and let be the size of your formula. Your score is .
Each test case has a full score of points. There are test cases, so the total is points (before multiplying by the score coefficient). It is guaranteed that a full-score solution exists.
We provide a tool to test your output.
Download the attached file checker.cpp and compile it to get an executable checker.exe (Windows) or checker (Linux). Its usage is as follows:
- Enter
checker.exe X(Windows) or./checker X(Linux) in the terminal, or run it directly and then inputXfollowed by a newline, to test the -th test caseformulaX.in/out. - Enter
checker.exe A B(Windows) or./checker A B(Linux) in the terminal, or run it directly and then inputA Bfollowed by a newline, to test with input filename and output filename . - If the input is invalid or the output has errors, there will be corresponding messages.
- If there are no errors, it will output the size of your WFF.
- The input file may match the input format description exactly, or omit the line of scoring parameters. If the checker detects that the line of scoring parameters exists, it will also output your score.
Source: NFLSPC #6 C by chenxia25.
Translated by ChatGPT 5