CodeForces 550E Brackets in Implications 推理
给出一个四个规则
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 推理的更多相关文章
- codeforces #550E Brackets in Implications 结构体
标题效果:定义集合中{0,1}\{0,1\}上的运算符"→\rightarrow",定义例如以下: 0→0=10\rightarrow 0=1 0→1=10\rightarrow ...
- CodeForces 550E Brackets in Implications(构造)
[题目链接]:click here~~ [题目大意]给定一个逻辑运算符号a->b:当前仅当a为1b为0值为0,其余为1,构造括号.改变运算优先级使得最后结果为0 [解题思路]: todo~~ / ...
- 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 ...
- 「日常训练」Brackets in Implications(Codeforces Round 306 Div.2 E)
题意与分析 稍微复杂一些的思维题.反正这场全是思维题,就一道暴力水题(B).题解直接去看官方的,很详尽. 代码 #include <bits/stdc++.h> #define MP ma ...
- 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 ...
- Codeforces Round #306 (Div. 2) ABCDE(构造)
A. Two Substrings 题意:给一个字符串,求是否含有不重叠的子串"AB"和"BA",长度1e5. 题解:看起来很简单,但是一直错,各种考虑不周全, ...
- Codeforces Round #306 (Div. 2) D.E. 解题报告
D题:Regular Bridge 乱搞. 构造 这题乱搞一下即可了.构造一个有桥并且每一个点的度数都为k的无向图. 方法非常多.也不好叙述.. 代码例如以下: #include <cstdio ...
- XJTU Summer Holiday Test 1(Brackets in Implications-构造)
B - Brackets in Implications Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & ...
- 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 ...
随机推荐
- 完全数java
完全数:小于本身的所有因子的和(包括1) public class test01 { public static void main(String[] args) { Scanner scanner= ...
- python len()函数的用法
函数:len() 返回字符串.列表.字典.元组等长度. 语法:len(str) str:要计算的字符串.列表.字典.元组等 返回值:字符串.列表.字典.元组等元素的长度. Test: 1:计算字符串的 ...
- web前端(9)—— CSS属性
属性 终于到css属性,前面就零零散散的用了什么color,font-size之类,本篇博文就专项的介绍它了 字体属性 font-family 此属性是设置字体样式的,比如微软雅黑,方正书体,华文宋体 ...
- Sql Full-Text Filter
SQL Server 全文索引介绍(转载) 概述 全文引擎使用全文索引中的信息来编译可快速搜索表中的特定词或词组的全文查询.全文索引将有关重要的词及其位置的信息存储在数据库表的一列或多列中.全文索引是 ...
- Redis高可用 Sentinel
官网: https://redis.io/topics/sentinel Redis的主从只能实现数据热备份的功能,主宕机后从无法自动接管服务,因此Redis推出了Sentinel的主从监控模式. S ...
- monkey_recorder录制monkeyrunner脚本
转载:monkey_recorder录制monkeyrunner脚本 1. 你必须有android sdk, sdk的tools文件家里有一个monkeyrunner.bat.2. 将如下内容拷贝 ...
- celery 定时任务
用celery定时任务,定时删除文件夹 tasks.py from celery import Celery import os import shutil app = Celery('demo') ...
- Go学习笔记05-指针
目录 参数传递 var a int = 2 var pa *int = &a *pa = 3 fmt.Println(a) Go语言中 指针不能运算 参数传递 不像C++.Java.Pytho ...
- PHP服务器Apache与Nginx的对比分析
PHP服务器Apache与Nginx的对比分析 本篇文章给大家带来的内容是关于PHP服务器Apache与Nginx的对比分析,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. Apach ...
- Oracle hint之ORDERED和USE_NL
Hint:ORDERED和USE_NL ORDERED好理解,就是表示根据 from 后面表的顺序join,从左到右,左边的表做驱动表 use_nl(t1,t2):表示对表t1.t2关联时采用嵌套循环 ...