Regular Bracket Sequence

time limit per test:1 second

memory limit per test:256 megabytes

input:standard input

output:standard output

A string is called bracket sequence if it does not contain any characters other than “(” and “)”. A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters “+” and “1” into this sequence. For example, “”, “(())” and “()()” are regular bracket sequences; “))” and “)((” are bracket sequences (but not regular ones), and “(a)” and “(1)+(1)” are not bracket sequences at all.

You have a number of strings; each string is a bracket sequence of length 222. So, overall you have cnt1cnt1cnt1 strings “((”, cnt2cnt2cnt2 strings “()”, cnt3cnt3cnt3 strings “)(” and cnt4cnt4cnt4 strings “))”. You want to write all these strings in some order, one after another; after that, you will get a long bracket sequence of length 2(cnt1+cnt2+cnt3+cnt4)2(cnt1+cnt2+cnt3+cnt4)2(cnt1+cnt2+cnt3+cnt4). You wonder: is it possible to choose some order of the strings you have such that you will get a regular bracket sequence? Note that you may not remove any characters or strings, and you may not add anything either.

Input

The input consists of four lines, iii-th of them contains one integer cnticnt_icnti​ (0≤cnti≤109)(0≤cnt_i≤10^9)(0≤cnti​≤109).

Output

Print one integer: 111 if it is possible to form a regular bracket sequence by choosing the correct order of the given strings, 000 otherwise.

Examples

input

3
1
4
3

output

1

input

0
0
0
0

output

1

input

1
2
3
4

output

0

Note

In the first example it is possible to construct a string “(())()(()((()()()())))”, which is a regular bracket sequence.

In the second example it is possible to construct a string “”, which is a regular bracket sequence.

Solve

你有四种括号,"((","()",")(","))", 给出四种括号的数量, 问能否将这些括号以某种顺序连接起来, 使得每个左括号都有与之匹配的右括号。

观察可以发现:如果要完全匹配,()是不会对结果产生影响的,然后可以推出一个关系式:cnt1=2×cnt3+cnt4,cnt4=2×cnt3+cnt1cnt1=2\times cnt3+cnt4,cnt4=2\times cnt3+cnt1cnt1=2×cnt3+cnt4,cnt4=2×cnt3+cnt1

即:当cnt3≠0,cnt1=cnt4≠0cnt3\neq0,cnt1=cnt4\neq0cnt3̸​=0,cnt1=cnt4̸​=0或cnt3=0,cnt1=cnt2cnt3=0,cnt1=cnt2cnt3=0,cnt1=cnt2时,才会完全匹配

Code

/*************************************************************************

	 > Author: WZY
> School: HPU
> Created Time: 2019-03-15 10:34:53 ************************************************************************/
#include <cmath>
#include <cstdio>
#include <time.h>
#include <cstring>
#include <limits.h>
#include <iostream>
#include <algorithm>
#include <random>
#include <iomanip>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <random>
#define ll long long
#define ull unsigned long long
#define lson o<<1
#define rson o<<1|1
#define ms(a,b) memset(a,b,sizeof(a))
#define SE(N) setprecision(N)
#define PSE(N) fixed<<setprecision(N)
#define bug cerr<<"-------------"<<endl
#define debug(...) cerr<<"["<<#__VA_ARGS__":"<<(__VA_ARGS__)<<"]"<<"\n"
#define LEN(A) strlen(A)
const double E=exp(1);
const double eps=1e-9;
const double pi=acos(-1.0);
const int mod=1e9+7;
const int maxn=1e6+10;
const int maxm=1e3+10;
const int moha=19260817;
const int inf=1<<30;
const ll INF=1LL<<60;
using namespace std;
inline void Debug(){cerr<<'\n';}
inline void MIN(int &x,int y) {if(y<x) x=y;}
inline void MAX(int &x,int y) {if(y>x) x=y;}
inline void MIN(ll &x,ll y) {if(y<x) x=y;}
inline void MAX(ll &x,ll y) {if(y>x) x=y;}
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
cerr<<arg<<"";Debug(rest...);}
int main(int argc, char const *argv[])
{
ios::sync_with_stdio(false);cin.tie(0);
cout.precision(20);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
srand((unsigned int)time(NULL));
#endif
int cnt1,cnt2,cnt3,cnt4;
while(cin>>cnt1>>cnt2>>cnt3>>cnt4)
{
if(cnt1+cnt4==0)
{
if(cnt3)
cout<<0<<endl;
else
cout<<1<<endl;
continue;
}
if(cnt1==cnt4)
cout<<1<<endl;
else
cout<<0<<endl;
}
#ifndef ONLINE_JUDGE
cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" s.\n";
#endif
return 0;
}

Codeforces1132A——Regular Bracket Sequence(水题)的更多相关文章

  1. CF1095E Almost Regular Bracket Sequence

    题目地址:CF1095E Almost Regular Bracket Sequence 真的是尬,Div.3都没AK,难受QWQ 就死在这道水题上(水题都切不了,我太菜了) 看了题解,发现题解有错, ...

  2. CodeForces - 612C Replace To Make Regular Bracket Sequence 压栈

    C. Replace To Make Regular Bracket Sequence time limit per test 1 second memory limit per test 256 m ...

  3. (CodeForces - 5C)Longest Regular Bracket Sequence(dp+栈)(最长连续括号模板)

    (CodeForces - 5C)Longest Regular Bracket Sequence time limit per test:2 seconds memory limit per tes ...

  4. Almost Regular Bracket Sequence CodeForces - 1095E (线段树,单点更新,区间查询维护括号序列)

    Almost Regular Bracket Sequence CodeForces - 1095E You are given a bracket sequence ss consisting of ...

  5. UVa 1584 Circular Sequence --- 水题

    UVa 1584 题目大意:给定一个含有n个字母的环状字符串,可从任意位置开始按顺时针读取n个字母,输出其中字典序最小的结果 解题思路:先利用模运算实现一个判定给定一个环状的串以及两个首字母位置,比较 ...

  6. Educational Codeforces Round 4 C. Replace To Make Regular Bracket Sequence 栈

    C. Replace To Make Regular Bracket Sequence 题目连接: http://www.codeforces.com/contest/612/problem/C De ...

  7. Codeforces Beta Round #5 C. Longest Regular Bracket Sequence 栈/dp

    C. Longest Regular Bracket Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.c ...

  8. Replace To Make Regular Bracket Sequence

    Replace To Make Regular Bracket Sequence You are given string s consists of opening and closing brac ...

  9. D - Replace To Make Regular Bracket Sequence

    You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). ...

随机推荐

  1. 位运算符在JS中的妙用

    正文 位运算 JavaScript 中最臭名昭著的 Bug 就是 0.1 + 0.2 !== 0.3,因为精度的问题,导致所有的浮点运算都是不安全的,具体原因可详见<0.1 + 0.2不等于0. ...

  2. 数组相关API,reduce

    reduce() 方法接受一个数组作为输入值并返回一个值.这点挺有趣的.reduce 接受一个回调函数,回调函数参数包括一个累计器(数组每一段的累加值,它会像雪球一样增长),当前值,和索引.reduc ...

  3. 【JavaWeb安全】RMI-Remote Method Invocator

    RMI-Remote Method Invocator 什么是RMI?RMI有什么用? RMI允许用户通过数据传输,调用远程方法,在远程服务器处理数据.例如将1,3传到远程服务器的加法运算器,加法运算 ...

  4. 从源码看RequestMappingHandlerMapping的注册与发现

    1.问题的产生 日常开发中,大多数的API层中@Controller注解和@RequestMapping注解都会被使用在其中,但是为什么标注了@Controller和@RequestMapping注解 ...

  5. 创建Oracle数据库实例

    创建Oracle数据库实例 转自oracle数据库创建实例 数据库已经安装完成,可以正常登陆查看用户等操作. system用户只能用normal身份登陆em.除非你对它授予了sysdba的系统权限或者 ...

  6. Why is the size of an empty class not zero in C++?

    Predict the output of the following program? 1 #include<iostream> 2 using namespace std; 3 4 c ...

  7. Spring Cloud集成RabbitMQ的使用

    同步 or 异步 前言:我们现在有一个用微服务架构模式开发的系统,系统里有一个商品服务和订单服务,且它们都是同步通信的. 目前我们商品服务和订单服务之间的通信方式是同步的,当业务扩大之后,如果还继续使 ...

  8. 【编程思想】【设计模式】【结构模式Structural】享元模式flyweight

    Python版 https://github.com/faif/python-patterns/blob/master/structural/flyweight.py #!/usr/bin/env p ...

  9. Spring Boot项目的探究

    一.pom.xml文件 1.父项目 <parent> <groupId>org.springframework.boot</groupId> <artifac ...

  10. 通过js禁用浏览器的回退事件

    js代码: <script> history.pushState(null, null, document.URL); window.addEventListener('popstate' ...