#P4106. [HEOI2014] 逻辑翻译
[HEOI2014] 逻辑翻译
Description
In the human nervous system, each signal can be represented by or . These signals combine to eventually form complex information such as joy, anger, sorrow, and happiness; sour, sweet, bitter, and spicy; red, yellow, green, and blue. Breakthroughs in nano-probing technology have enabled biologists to measure the complete logical function of specific regions of the brain. However, processing ultra-large data has always been a headache for Professor H.
Suppose a logical unit accepts signal inputs and produces a real value representing some meaning. Then there are possible cases in total. Through long-term cumulative measurements, Professor H can accurately obtain the mapping between input signals and :
Further research has found that the neuron’s computation can be modeled as a well-known polynomial. Since the square of an input signal value is always , we can uniquely represent any logic by a polynomial without powers consisting of terms.
For example x1=+1; x2=+1 -> 0
x1=+1; x2=-1 -> 1
x1=-1; x2=+1 -> 2
x1=-1; x2=-1 -> 3
can be written as
Studying the polynomial form of a logical unit is very meaningful for understanding how the brain works, so Xiao M decided to help Professor H convert all measured logic tables into polynomial form. Such a simple task should be no problem for the coding ace Xiao M, right?
Input Format
The first line is (). Then there are lines. Each line contains one set of logical inputs and one corresponding value, representing the signs of and the corresponding . See the sample. The testdata guarantees that the absolute value of every logical value does not exceed , and it contains no more than decimal places. All logical input strings are guaranteed to be pairwise distinct.
Output Format
Up to lines, representing the coefficient of each term in the polynomial. If a coefficient is an integer, output it in integer form; otherwise, output it as an irreducible fraction. If a coefficient is exactly , omit the entire line. Separate variables and the coefficient with a space; the constant term should not have a space.
Order by the polynomial’s lexicographic order:
-
The constant term comes first.
-
Among non-constant terms, the term with the smaller smallest index comes first.
-
If two terms share the same smallest index, remove that smallest-indexed and compare recursively using the same rule.
Example: , , , , , , , . See the sample.
2
++ 0
+- 1
-+ 2
-- 3
3/2
-1 x1
-1/2 x2
3
--- -1.0
-++ -1.0
+-+ -1.0
++- -1.0
--+ 1.0
-+- 1.0
+-- 1.0
+++ 1.0
1 x1x2x3
Hint
This problem has testdata.
For the st testdata, ; for the nd testdata, ; for the rd and th testdata, ; for the th and th testdata, the answer polynomial has only one nonzero term, as in Sample #2; for the th and th testdata, the answer polynomial has at most nonzero terms.
For of the testdata, .
Friendly reminder
Please pay attention to input and output efficiency.
Translated by ChatGPT 5
京公网安备 11011102002149号