Codeforces 550E Brackets in Implications (construction)

Source: Internet
Author: User

" 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.