给出一个四个规则

0->0=1  0->1=1

1->0=0  1->1=0

我自己当时一味的去找规律,没有把式子好好推一推。

当然每个人都能想到a[n]=0是必须的

当a[n-1]=1的时候,直接输出即可,因为前面无论到0还是1,最后与n-1结合都是1,而这正式我们需要的

那么问题来了,a[n-1]=0时,我们该如何操作呢?

思考这样我们以及知道的条件,考虑某一段010101010000111....1,只要是以1为结尾的,按顺序计算都是1。

再思考如何有两个0,我们发现(0(111...0))这个式子是恒等于1的,无论中间1是多少个,而只要这等于1后,无论(0(111...0))的前面位置按顺序计算是什么,答案都是1,然后再和0计算,答案就是0

反思:自己思考的时候,一味的僵化,没有把式子进行本质扩展和分析。同时脑子很乱,对于这种思维题,是大忌

#include<iostream>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<map>
#define LL long long
using namespace std;
int a[];
int main()
{
int n;
while(~scanf("%d",&n))
{ for (int i=; i<=n; i++)
{
scanf("%d",&a[i]);
}
if (n==)
{
if(a[]==)
{
printf("YES\n0\n");
}
else
{
printf("NO\n");
}
}
else if (n==)
{
if (a[]== && a[]==)
{
printf("YES\n1->0\n");
}
else
{
printf("NO\n");
}
}else if (a[n]==){
printf("NO\n");
}
else
{
if (a[n-]==)
{
printf("YES\n");
for (int i=; i<=n; i++)
{
if (i-)
{
printf("->");
}
printf("%d",a[i]);
}
printf("\n");
}
else
{
int pos=-;
if (a[n]==)
{
for (int i=n-; i>=; i--)
{
if (a[i]==)
{
pos=i;
break;
}
}
if (pos==-)
{
printf("NO\n");
continue;
}
printf("YES\n");
for (int i=; i<pos; i++)
{
printf("%d->",a[i]);
}
printf("(0->(");
for (int i=pos+; i<=n-; i++)
{
printf("%d->",a[i]);
}
printf("0))->0\n");
}
else
{
printf("NO\n");
}
}
} }
return ;
}

CodeForces 550E Brackets in Implications 推理的更多相关文章

  1. codeforces #550E Brackets in Implications 结构体

    标题效果:定义集合中{0,1}\{0,1\}上的运算符"→\rightarrow",定义例如以下: 0→0=10\rightarrow 0=1 0→1=10\rightarrow ...

  2. CodeForces 550E Brackets in Implications(构造)

    [题目链接]:click here~~ [题目大意]给定一个逻辑运算符号a->b:当前仅当a为1b为0值为0,其余为1,构造括号.改变运算优先级使得最后结果为0 [解题思路]: todo~~ / ...

  3. Codeforces Round #306 (Div. 2) E. Brackets in Implications 构造

    E. Brackets in Implications Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...

  4. 「日常训练」Brackets in Implications(Codeforces Round 306 Div.2 E)

    题意与分析 稍微复杂一些的思维题.反正这场全是思维题,就一道暴力水题(B).题解直接去看官方的,很详尽. 代码 #include <bits/stdc++.h> #define MP ma ...

  5. Codeforces Round #306 (Div. 2)

    A. Two Substrings You are given string s. Your task is to determine if the given string s contains t ...

  6. Codeforces Round #306 (Div. 2) ABCDE(构造)

    A. Two Substrings 题意:给一个字符串,求是否含有不重叠的子串"AB"和"BA",长度1e5. 题解:看起来很简单,但是一直错,各种考虑不周全, ...

  7. Codeforces Round #306 (Div. 2) D.E. 解题报告

    D题:Regular Bridge 乱搞. 构造 这题乱搞一下即可了.构造一个有桥并且每一个点的度数都为k的无向图. 方法非常多.也不好叙述.. 代码例如以下: #include <cstdio ...

  8. XJTU Summer Holiday Test 1(Brackets in Implications-构造)

    B - Brackets in Implications Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  9. Codeforces Round #223 (Div. 2) E. Sereja and Brackets 线段树区间合并

    题目链接:http://codeforces.com/contest/381/problem/E  E. Sereja and Brackets time limit per test 1 secon ...

随机推荐

  1. java----JSTL学习笔记(转)

    Java容器类包含List.ArrayList.Vector及map.HashTable.HashMap.Hashset ArrayList和HashMap是异步的,Vector和HashTable是 ...

  2. 转自:stuff字符串拼接方法

    下文讲述数据表中将多列合并到一列的方法分享 转自:http://www.maomao365.com/?p=6796

  3. scrapy入门:安装scrapy

    1.安装Scrapy pip 安装: pip install scrapy 要求pip至少是18.1版本的,10.x版本会提示更新pip 更新pip命令: python -m pip install ...

  4. 登录views

    import osimport hashlibfrom django.shortcuts import render,render_to_response,redirect,HttpResponseR ...

  5. memset memcmp memcpy memmove 自己实现

    memset memcmp memcpy memmove 自己实现 memset #include <stdio.h> #include <memory.h> #include ...

  6. 文件服务器HFS

    用途:用于文件共享(类似FTP) 官网:http://www.rejetto.com/hfs/?f=ss 优点:比起apache,它有界面方便查看当前正连接的主机 如果在内网环境下进行文件共享的话,可 ...

  7. ASP.NET -- WebForm -- .aspx与.aspx.cs文件

    ASP.NET -- WebForm --  .aspx与.aspx.cs文件 1. ASP.NET -- WebForm(C#)文件 .aspx文件:是Html页面,页面的布局,样式在该文件中设计. ...

  8. June 3. 2018 Week 23rd Sunday

    You only get one shot; do not miss your chance to blow. 机会只有一次,不要错过. From Eminem, "Lose Yoursel ...

  9. JavaScript数据类型之布尔类型

    引言 布尔值指代真或假.开或关.是或否.这个类型只有两个值,保留字true和false.JavaScript程序中的比较语句的结果通常都是布尔值.布尔值通常用于JavaScript中的控制结构中. 真 ...

  10. WPFの阴影效果

    UI实现过程中有的需要实现投影效果,那么怎么实现呢?整理了几种方式,供参考和查阅 1.图片做成阴影效果的,这个不多说了,和美工小姐姐多共同就好了 2.控件的DropShadowEffect属性 < ...