开发者

Boolean system ( for C++/ C#/java)

How can I programatically resolve this type of system :

A = !B
B = !C
D = !B
E = !A
E = !B

so I can get by substituting A = C = D (3) and E = B (2). I only need the number of the 2开发者_StackOverflow groups. If it's not possible to get 2 groups, I display an error message.


In case, this is not closed as a dupe, from my answer in your previous question:

To solve equations of the form

X1 = NOT X 3

X5 = NOT X 2

etc

Form a graph with nodes as Xi and connecting Xi and X j iff the equation Xi = NOT X j appears.

Now try to 2-colour the graph using Breadth First Search.


Consider a string of bits ABCDE. For each subset of this string, set all the variables in that subset to true and all the variables not in the subset to false. See which subset matches your conditions.

You can implement this by counting in binary from 0 to 2^(num variables) - 1. For each number, its binary representation gives you which variables are true and which are false. So you just need to get all the bits of a number and do your checks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜