Codeforces Gym 100610 Problem E. Explicit Formula 水题
Problem E. Explicit Formula
Time Limit: 1 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/gym/100610Description
Consider 10 Boolean variables x1, x2, x3, x4, x5, x6, x7, x8, x9, and x10. Consider all pairs and triplets of distinct variables among these ten. (There are 45 pairs and 120 triplets.) Count the number of pairs and triplets that contain at least one variable equal to 1. Set f(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10) = 1 if this number is odd and f(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10) = 0 if this number is even. Here’s an explicit formula that represents the function f(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10) correctly: f(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10) = (x1 ∨ x2)⊕(x1 ∨ x3)⊕(x1 ∨ x4)⊕(x1 ∨ x5)⊕(x1 ∨ x6)⊕(x1 ∨ x7)⊕ (x1 ∨ x8) ⊕ (x1 ∨ x9) ⊕ (x1 ∨ x10) ⊕ (x2 ∨ x3) ⊕ (x2 ∨ x4) ⊕ (x2 ∨ x5) ⊕ (x2 ∨ x6) ⊕ (x2 ∨ x7) ⊕ (x2 ∨ x8) ⊕ (x2 ∨ x9)⊕(x2 ∨ x10)⊕(x3 ∨ x4)⊕(x3 ∨ x5)⊕(x3 ∨ x6)⊕(x3 ∨ x7)⊕(x3 ∨ x8)⊕(x3 ∨ x9)⊕(x3 ∨ x10)⊕ (x4 ∨ x5) ⊕ (x4 ∨ x6) ⊕ (x4 ∨ x7) ⊕ (x4 ∨ x8) ⊕ (x4 ∨ x9) ⊕ (x4 ∨ x10) ⊕ (x5 ∨ x6) ⊕ (x5 ∨ x7) ⊕ (x5 ∨ x8) ⊕ (x5 ∨ x9)⊕(x5 ∨ x10)⊕(x6 ∨ x7)⊕(x6 ∨ x8)⊕(x6 ∨ x9)⊕(x6 ∨ x10)⊕(x7 ∨ x8)⊕(x7 ∨ x9)⊕(x7 ∨ x10)⊕ (x8 ∨ x9) ⊕ (x8 ∨ x10) ⊕ (x9 ∨ x10) ⊕ (x1 ∨ x2 ∨ x3) ⊕ (x1 ∨ x2 ∨ x4) ⊕ (x1 ∨ x2 ∨ x5) ⊕ (x1 ∨ x2 ∨ x6) ⊕ (x1 ∨ x2 ∨ x7) ⊕ (x1 ∨ x2 ∨ x8) ⊕ (x1 ∨ x2 ∨ x9) ⊕ (x1 ∨ x2 ∨ x10) ⊕ (x1 ∨ x3 ∨ x4) ⊕ (x1 ∨ x3 ∨ x5) ⊕ (x1 ∨ x3 ∨ x6) ⊕ (x1 ∨ x3 ∨ x7) ⊕ (x1 ∨ x3 ∨ x8) ⊕ (x1 ∨ x3 ∨ x9) ⊕ (x1 ∨ x3 ∨ x10) ⊕ (x1 ∨ x4 ∨ x5) ⊕ (x1 ∨ x4 ∨ x6) ⊕ (x1 ∨ x4 ∨ x7) ⊕ (x1 ∨ x4 ∨ x8) ⊕ (x1 ∨ x4 ∨ x9) ⊕ (x1 ∨ x4 ∨ x10) ⊕ (x1 ∨ x5 ∨ x6) ⊕ (x1 ∨ x5 ∨ x7) ⊕ (x1 ∨ x5 ∨ x8) ⊕ (x1 ∨ x5 ∨ x9) ⊕ (x1 ∨ x5 ∨ x10) ⊕ (x1 ∨ x6 ∨ x7) ⊕ (x1 ∨ x6 ∨ x8) ⊕ (x1 ∨ x6 ∨ x9) ⊕ (x1 ∨ x6 ∨ x10) ⊕ (x1 ∨ x7 ∨ x8) ⊕ (x1 ∨ x7 ∨ x9) ⊕ (x1 ∨ x7 ∨ x10) ⊕ (x1 ∨ x8 ∨ x9) ⊕ (x1 ∨ x8 ∨ x10) ⊕ (x1 ∨ x9 ∨ x10) ⊕ (x2 ∨ x3 ∨ x4) ⊕ (x2 ∨ x3 ∨ x5) ⊕ (x2 ∨ x3 ∨ x6) ⊕ (x2 ∨ x3 ∨ x7) ⊕ (x2 ∨ x3 ∨ x8) ⊕ (x2 ∨ x3 ∨ x9) ⊕ (x2 ∨ x3 ∨ x10) ⊕ (x2 ∨ x4 ∨ x5) ⊕ (x2 ∨ x4 ∨ x6) ⊕ (x2 ∨ x4 ∨ x7) ⊕ (x2 ∨ x4 ∨ x8) ⊕ (x2 ∨ x4 ∨ x9) ⊕ (x2 ∨ x4 ∨ x10) ⊕ (x2 ∨ x5 ∨ x6) ⊕ (x2 ∨ x5 ∨ x7) ⊕ (x2 ∨ x5 ∨ x8) ⊕ (x2 ∨ x5 ∨ x9) ⊕ (x2 ∨ x5 ∨ x10) ⊕ (x2 ∨ x6 ∨ x7) ⊕ (x2 ∨ x6 ∨ x8) ⊕ (x2 ∨ x6 ∨ x9) ⊕ (x2 ∨ x6 ∨ x10) ⊕ (x2 ∨ x7 ∨ x8) ⊕ (x2 ∨ x7 ∨ x9) ⊕ (x2 ∨ x7 ∨ x10) ⊕ (x2 ∨ x8 ∨ x9) ⊕ (x2 ∨ x8 ∨ x10) ⊕ (x2 ∨ x9 ∨ x10) ⊕ (x3 ∨ x4 ∨ x5) ⊕ (x3 ∨ x4 ∨ x6) ⊕ (x3 ∨ x4 ∨ x7) ⊕ (x3 ∨ x4 ∨ x8) ⊕ (x3 ∨ x4 ∨ x9) ⊕ (x3 ∨ x4 ∨ x10) ⊕ (x3 ∨ x5 ∨ x6) ⊕ (x3 ∨ x5 ∨ x7) ⊕ (x3 ∨ x5 ∨ x8) ⊕ (x3 ∨ x5 ∨ x9) ⊕ (x3 ∨ x5 ∨ x10) ⊕ (x3 ∨ x6 ∨ x7) ⊕ (x3 ∨ x6 ∨ x8) ⊕ (x3 ∨ x6 ∨ x9) ⊕ (x3 ∨ x6 ∨ x10) ⊕ (x3 ∨ x7 ∨ x8) ⊕ (x3 ∨ x7 ∨ x9) ⊕ (x3 ∨ x7 ∨ x10) ⊕ (x3 ∨ x8 ∨ x9) ⊕ (x3 ∨ x8 ∨ x10) ⊕ (x3 ∨ x9 ∨ x10) ⊕ (x4 ∨ x5 ∨ x6) ⊕ (x4 ∨ x5 ∨ x7) ⊕ (x4 ∨ x5 ∨ x8) ⊕ (x4 ∨ x5 ∨ x9) ⊕ (x4 ∨ x5 ∨ x10) ⊕ (x4 ∨ x6 ∨ x7) ⊕ (x4 ∨ x6 ∨ x8) ⊕ (x4 ∨ x6 ∨ x9) ⊕ (x4 ∨ x6 ∨ x10) ⊕ (x4 ∨ x7 ∨ x8) ⊕ (x4 ∨ x7 ∨ x9) ⊕ (x4 ∨ x7 ∨ x10) ⊕ (x4 ∨ x8 ∨ x9) ⊕ (x4 ∨ x8 ∨ x10) ⊕ (x4 ∨ x9 ∨ x10) ⊕ (x5 ∨ x6 ∨ x7) ⊕ (x5 ∨ x6 ∨ x8) ⊕ (x5 ∨ x6 ∨ x9) ⊕ (x5 ∨ x6 ∨ x10) ⊕ (x5 ∨ x7 ∨ x8) ⊕ (x5 ∨ x7 ∨ x9) ⊕ (x5 ∨ x7 ∨ x10) ⊕ (x5 ∨ x8 ∨ x9) ⊕ (x5 ∨ x8 ∨ x10) ⊕ (x5 ∨ x9 ∨ x10) ⊕ (x6 ∨ x7 ∨ x8) ⊕ (x6 ∨ x7 ∨ x9) ⊕ (x6 ∨ x7 ∨ x10) ⊕ (x6 ∨ x8 ∨ x9) ⊕ (x6 ∨ x8 ∨ x10) ⊕ (x6 ∨ x9 ∨ x10) ⊕ (x7 ∨ x8 ∨ x9) ⊕ (x7 ∨ x8 ∨ x10) ⊕ (x7 ∨ x9 ∨ x10) ⊕ (x8 ∨ x9 ∨ x10) In this formula ∨ stands for logical or, and ⊕ stands for exclusive or (xor). Remember that in C++ and Java these two binary operators are denoted as “||” and “^”. Given the values of x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, calculate the value of f(x1, x2, . . . , x10).
Input
The input file contains 10 numbers x1, x2, x3, x4, x5, x6, x7, x8, x9, and x10. Each of them is either 0 or 1.
Output
Output a single value — f(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10).
Sample Input
1 0 0 1 0 0 1 0 0 1
Sample Output
0
HINT
题意
就求题目给的那个式子的答案是多少
题解:
ctrl+f 把符号替换一下就好了……
代码:
//qscqesze #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <bitset> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> #include <map> #include <stack> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define maxn 110000 #define mod 10007 #define eps 1e-9 #define pi 3.1415926 int Num; //const int inf=0x7fffffff; //§ß§é§à§é¨f§³ const ll Inf=0x3f3f3f3f3f3f3f3fll; inline ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } //************************************************************************************* ll x1,x2,x3,x4,x5,x6,x7,x8,x9,x10; int main() { freopen("explicit.in","r",stdin); freopen("explicit.out","w",stdout); cin>>x1>>x2>>x3>>x4>>x5>>x6>>x7>>x8>>x9>>x10; cout<<((x1 || x2)^(x1 || x3)^(x1 || x4)^(x1 || x5)^(x1 || x6)^(x1 || x7)^ (x1 || x8) ^ (x1 || x9) ^ (x1 || x10) ^ (x2 || x3) ^ (x2 || x4) ^ (x2 || x5) ^ (x2 || x6) ^ (x2 || x7) ^ (x2 || x8) ^ (x2 || x9)^(x2 || x10)^(x3 || x4)^(x3 || x5)^(x3 || x6)^(x3 || x7)^(x3 || x8)^(x3 || x9)^(x3 || x10)^ (x4 || x5) ^(x4 || x6) ^ (x4 || x7) ^ (x4 || x8) ^ (x4 || x9) ^ (x4 || x10) ^ (x5 || x6) ^ (x5 || x7) ^ (x5 || x8) ^ (x5 || x9)^(x5 || x10)^(x6 || x7)^(x6 || x8)^(x6 || x9)^(x6 || x10)^(x7 || x8)^(x7 || x9)^(x7 || x10)^ (x8 || x9) ^ (x8 || x10) ^(x9 || x10) ^ (x1 || x2 || x3) ^ (x1 || x2 || x4) ^ (x1 || x2 || x5) ^ (x1 || x2 || x6) ^ (x1 || x2 || x7) ^ (x1 || x2 || x8) ^ (x1 || x2 || x9) ^ (x1 || x2 || x10) ^ (x1 || x3 || x4) ^ (x1 || x3 || x5) ^ (x1 || x3 || x6) ^ (x1 || x3 || x7) ^ (x1 || x3 || x8) ^ (x1 || x3 || x9) ^ (x1 || x3 || x10) ^ (x1 || x4 || x5) ^ (x1 || x4 || x6) ^ (x1 || x4 || x7) ^ (x1 || x4 || x8) ^ (x1 || x4 || x9) ^ (x1 || x4 || x10) ^ (x1 || x5 || x6) ^ (x1 || x5 || x7) ^ (x1 || x5 || x8) ^ (x1 || x5 || x9) ^ (x1 || x5 || x10) ^ (x1 || x6 || x7) ^ (x1 || x6 || x8) ^ (x1 || x6 || x9) ^ (x1 || x6 || x10) ^ (x1 || x7 || x8) ^ (x1 || x7 || x9) ^ (x1 || x7 || x10) ^ (x1 || x8 || x9) ^ (x1 || x8 || x10) ^ (x1 || x9 || x10) ^ (x2 || x3 || x4) ^ (x2 || x3 || x5) ^ (x2 || x3 || x6) ^ (x2 || x3 || x7) ^ (x2 || x3 || x8) ^ (x2 || x3 || x9) ^ (x2 || x3 || x10) ^ (x2 || x4 || x5) ^ (x2 || x4 || x6) ^ (x2 || x4 || x7) ^ (x2 || x4 || x8) ^ (x2 || x4 || x9) ^ (x2 || x4 || x10) ^ (x2 || x5 || x6) ^ (x2 || x5 || x7) ^ (x2 || x5 || x8) ^ (x2 || x5 || x9) ^ (x2 || x5 || x10) ^ (x2 || x6 || x7) ^ (x2 || x6 || x8) ^ (x2 || x6 || x9) ^ (x2 || x6 || x10) ^ (x2 || x7 || x8) ^ (x2 || x7 || x9) ^ (x2 || x7 || x10) ^ (x2 || x8 || x9) ^ (x2 || x8 || x10) ^ (x2 || x9 || x10) ^ (x3 || x4 || x5) ^ (x3 || x4 || x6) ^ (x3 || x4 || x7) ^ (x3 || x4 || x8) ^ (x3 || x4 || x9) ^ (x3 || x4 || x10) ^ (x3 || x5 || x6) ^ (x3 || x5 || x7) ^ (x3 || x5 || x8) ^ (x3 || x5 || x9) ^ (x3 || x5 || x10) ^ (x3 || x6 || x7) ^ (x3 || x6 || x8) ^ (x3 || x6 || x9) ^ (x3 || x6 || x10) ^ (x3 || x7 || x8) ^ (x3 || x7 || x9) ^ (x3 || x7 || x10) ^ (x3 || x8 || x9) ^ (x3 || x8 || x10) ^ (x3 || x9 || x10) ^ (x4 || x5 || x6) ^ (x4 || x5 || x7) ^ (x4 || x5 || x8) ^ (x4 || x5 || x9) ^ (x4 || x5 || x10) ^ (x4 || x6 || x7) ^ (x4 || x6 || x8) ^ (x4 || x6 || x9) ^ (x4 || x6 || x10) ^ (x4 || x7 || x8) ^ (x4 || x7 || x9) ^ (x4 || x7 || x10) ^ (x4 || x8 || x9) ^ (x4 || x8 || x10) ^ (x4 || x9 || x10) ^ (x5 || x6 || x7) ^ (x5 || x6 || x8) ^ (x5 || x6 || x9) ^ (x5 || x6 || x10) ^ (x5 || x7 || x8) ^ (x5 || x7 || x9) ^ (x5 || x7 || x10) ^ (x5 || x8 || x9) ^ (x5 || x8 || x10) ^ (x5 || x9 || x10) ^ (x6 || x7 || x8) ^ (x6 || x7 || x9) ^ (x6 || x7 || x10) ^ (x6 || x8 || x9) ^ (x6 || x8 || x10) ^ (x6 || x9 || x10) ^ (x7 || x8 || x9) ^ (x7 || x8 || x10) ^ (x7 || x9 || x10) ^ (x8 || x9 || x10)) <<endl; }