1132A. Regular Bracket Sequence bymrhao61

#include<iostream>
using namespace std;
int main()
{
	int a[5];int flag1=0,flag2=0;
	for(int i=1;i<=4;i++)cin>>a[i];
	if(a[1]==a[4]&&a[1]>0)
	{
		flag1=1;
	}
	if(a[1]==0&&a[3]==0&&a[4]==0)
	{
		flag2=1;
	}
	if(flag1||flag2)
	{
		cout<<1;
	}	
	else
	{
		cout<<0;
	}
} 

A. Regular Bracket Sequence
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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 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 2. So, overall you have cnt1 strings “((”, cnt2 strings “()”, cnt3 strings “)(” and cnt4 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). 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, i-th of them contains one integer cnti (0≤cnti≤109).

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

Examples
inputCopy
3
1
4
3
outputCopy
1
inputCopy
0
0
0
0
outputCopy
1
inputCopy
1
2
3
4
outputCopy
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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值