#P1745. [CERC2016] Lost Logic
[CERC2016] Lost Logic
题目描述
Gustav is reading about 2-satisfiability, a well known problem of assigning truth values to boolean variables in order to satisfy a list of constraints — simple logical formulas involving two variables each.
We are using variables that can take on values (false) and (true). A constraint is a formula of the form where both and are possibly negated variables. As usual, denotes logical implication: is only when is and is . The negation of variable is denoted by .
Given an assignment of values to variables, we say that the constraint is satisfied if it evaluates to . Gustav has constructed a list of constraints and correctly concluded that there are exactly three different assignments of values to variables that satisfy all the constraints. Gustav has wrote down all three assignments but has, unfortunately, lost the list of constraints. Given three assignments of values to variables, find any list consisting of at most constrains such that the three given assignments are the only assignments that satisfy all the constraints.
输入格式
The first line contains an integer — the number of variables. Three lines follow, each describing one assignment. The -th line contains space-separated integers , where each is either or and denotes the value of the variable in the -th assignment. All three assignments will be different.
输出格式
If there is no solution output a single line containing the integer . Otherwise, the first line should contain an integer where — the number of constraints in your solution. The -th of the following lines should contain the -th constraint. Each constraint should be a string constructed according to the following rules:
- A variable is a string of the form “” where is an integer between and inclusive written without leading zeros.
- A literal is a string consisting of a variable possibly preceded by the “” character.
- A constraint is a string of the form “” where both and are literals. The implication sign consists of the “minus” character and the “greater-than” character and there is a single space character both before and after the implication sign.
3
0 0 0
0 1 0
1 0 0
3
x1 -> !x2
x3 -> x1
x3 -> x2
4
0 0 1 0
1 0 0 0
1 0 1 1
-1