B. Alternating Current----栈

来源:互联网 发布:linux route add 网关 编辑:程序博客网 时间:2024/06/08 02:46

B. Alternating Current
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again.

The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view):

Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without movingthe device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut.

To understand the problem better please read the notes to the test samples.

Input

The single line of the input contains a sequence of characters "+" and "-" of length n (1 ≤ n ≤ 100000). The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise.

Output

Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled.

Examples
input
-++-
output
Yes
input
+-
output
No
input
++
output
Yes
input
-
output
No
Note

The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses.

In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled:

In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher:

In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself:


题目链接:http://codeforces.com/contest/343/problem/B


这个题卡题意了。。。看了半天没看懂。。。无奈求助了谷歌翻译,然后这个题很简单,,,为什么会出现在div1里。。

题意是说我们通过在平面上移动红蓝两条线能否让这两条线分开,+代表交叉处红在上,-代表交叉处蓝在上。

首先我们很容易就知道奇数个肯定不行,pass掉,然后我们看提示中画的第二个图,很容易就可以看出来如果要是想要消掉的话我们需要满足两个条件,一个是连续,另一个是相同,所以我们维护一个简单栈就可以了。。。

代码:

#include <cstdio>#include <cstring>#include <iostream>using namespace std;char s[200000];int xin[200000];int main(){    int top=0;    scanf("%s",s);    int len=strlen(s);    if(len%2){        printf("No\n");        return 0;    }    int k;    for(int i=0;i<len;i++){        if(s[i]=='+'){            k=1;        }        else{            k=-1;        }        if(top!=0&&xin[top-1]==k){            top--;        }        else{            xin[top++]=k;        }    }    if(top==0){        printf("Yes\n");    }    else{        printf("No\n");    }    return 0;}


原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 小孩爱捡垃圾是怎么办 腰扭了不敢弯腰怎么办 小人狗在背后骂我怎么办 微信表情缺失了怎么办 动图过大 微信 怎么办 我能怎么办图片带字 我该怎么办图片带字 学化妆找不到模特练妆怎么办? cf进房间闪退怎么办 手游cf账号封了怎么办 大门牙缺了一块怎么办 缺了一颗牙齿怎么办 CF购买医疗包竞猜币没到账怎么办 CF手游昵称不合法怎么办 微信gif尺寸过大怎么办 微信表情上限300怎么办 太受欢迎了怎么办快穿 兔宝宝沾上人气味怎么办 我该怎么办的文字图片 爱奇艺缓存视频显示下载失败怎么办 把老公惹生气了怎么办 苹果x用电量太快怎么办 小中考地生没过怎么办 如果遇到不负责的语文老师怎么办 孩子的语文老师教的不好怎么办 刚买的小猫很凶怎么办 2月幼犬不吃东西怎么办 小狗狗不吃狗粮怎么办 母猫不会照顾小猫怎么办 刚买的小狗拉稀怎么办 母兔子吃小兔子怎么办 照片照出来背亮景人是黑的怎么办 手机透明壳变黄了怎么办 ae视频渲染太慢怎么办 3ce口红太干了怎么办 中考误用0.38mm的笔怎么办 ps画笔都锁住了怎么办 削铅笔机坏了怎么办 幼儿园小朋友不听老师话怎么办 孩子在幼儿园不听老师话怎么办 幼儿园大班孩子上课不好好上怎么办