" topic link ": Click here~~
" The main idea" given a logical operation symbol A->B: Currently only if A is 1b for 0 value is 0, the remainder is 1, construct parentheses, change the priority of the operation to make the final result is 0
" problem-solving ideas ":
todo~~
/*
Ideas:
1. If the last digit is 1, the result will not be 0.puts ("no");
2. In the case of a solution, the last one must be 0.
2.1. Further discovery, in fact, the second-to-last must be 1, only 1 of the preceding results and the bit 1 combined to equal 1, further 1->0=0;
2.2. If the 1 front is 0, then merge the two digits, make up 1, recursion 2.1
*/
Code:
#include <bits/stdc++.h>using namespace Std;const int n=1e5+10;typedef long long ll;typedef unsigned long long Llu;int num[n];int n,m,l,r,ans,cnt,top;int zero,one;int Main () { while (cin>>n) { zero=one=0; for (int i=0; i<n; ++i) { scanf ("%d", &num[i]); if (num[i]==0) ++zero; else ++one; } int a3=num[n-1]; int a2=num[n-2]; int a1=num[n-3]; if (a3==0&& (a2==1| | zero!=2)//Ensure that the last one is 0, and the penultimate digit is 1 { puts ("yes"); printf ("("); for (int i=0; i<=n-3; ++i) { printf ("(%d->", Num[i]); } printf ("%d", a2); for (int i=0; i<=n-3; ++i) printf (")"); if (n-1) printf ("->0"); printf (")"); Puts (""); } Else puts ("NO"); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Codeforces 550E Brackets in Implications (construction)