给出一个四个规则

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. 反射生成 INSERT 多个对象的 SQL 语句(批量插入)

    + View code private static void insertObject(List<?> objectList) throws IllegalAccessException ...

  2. AI学习---回归和聚类算法

    其他 资料链接:https://pan.baidu.com/s/1ofN2QFxpzC-OtmTFE2fHfw 提取码:o4c2

  3. Lua-pb 升级到Lua5.3

    项目lua库升级到5.3版本后,最头疼的就是原先的一些第三方库原先只是基于lua5.1设计的,比如protobuff 相关的的. 之前项目引入Lua-pb 实现protobuf的解析和使用,但是这个库 ...

  4. 聚类——GAKFCM的matlab程序

    聚类——GAKFCM的matlab程序 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 在聚类——GAKFCM文章中已介绍了GAKFCM算法的理论知识, ...

  5. webpack模块定义和使用的模式

    在使用webpack作为模块加载工具时,我在想module.exports的模块应该是一种什么模式,最直接地思考是单例.不太确定,所以写一个简单例子做测试. 测试代码 singleton.js: va ...

  6. Windows Live Writer 2012在Blogjava管理和发布博客

    下载Windows Live Writer 2012的完整版本(wlsetup-all.exe),安装的时候减少网络下载消耗的时间.注:有些平台可能还需要下载DotNet3.5(dotnetfx35. ...

  7. CSS 简介、 选择器、组合选择器

    #CSS 装饰器引入<!DOCTYPE html> <html> <head> <meta charset="utf-8"> < ...

  8. C#基础知识之托管代码和非托管代码

    什么是托管代码(managed code)? 托管代码(Managed Code)就是中间语言(IL)代码,在公共语言运行库(CLR)中运行.编译器把代码编译成中间语言,当方法被调用时,CLR把具体的 ...

  9. 在django中如何通过已有的mysql表生成django的model

    第一步:先是在项目中建立一个app:python manage.py startapp app01 第二步:python manage.py inspectdb > app01/models.p ...

  10. ElasticSearch(一):CentOS7 安装 ElasticSearch6.4.0

    一.安装jre支持 在CentOS中安装ElasticSearch需要Java1.8.0,可执行命令#  java -version查看当前系统所安装Java版本是否为1.8.0版本. 若非1.8.0 ...