博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #200 (Div. 1) B. Alternating Current 栈
阅读量:6637 次
发布时间:2019-06-25

本文共 2195 字,大约阅读时间需要 7 分钟。

B. Alternating Current

Time Limit: 1 Sec  

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/343/problem/B

Description

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 moving the 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.

Sample Input

-++-

Sample Output

Yes

 

HINT

 

题意

有两条直线缠绕在一起,一条直线是+,一条直线是-

如果+就表示第一条直线在上面,如果是-,就表示第二条直线在上面

问你能否直接拉,就能把这两条直线拉成平行线

题解:

首先我们想一想,必须是偶数个才行,不然的话,根本不可能拉成平行线

必须得两个连在一起的符号一样才能消除,于是我们就用栈来搞定就好啦

代码:

#include
#include
#include
using namespace std;string S;int main(){ stack
s; cin>>S; for(int i=0;i

 

转载地址:http://ghivo.baihongyu.com/

你可能感兴趣的文章
飞信批处理应用--每日定时发送天气预报及消息
查看>>
一个神秘的一句话后门代码详解
查看>>
开始→运行→输入的命令集锦
查看>>
sqlserver导出带数据的脚本
查看>>
查看端口与服务的对应关系
查看>>
Web中播放Flash
查看>>
windows server2012R2 数据库的还原
查看>>
[LINUX-操作系统]pc机上安装Enterprise Linux操作系统,无法启动图形界面
查看>>
squid 配置文件详解
查看>>
linux下httpd服务阶段实验
查看>>
常用的DOS命令和运行命令总结(不常用的不介绍,节省学习时间成本)【高手请绕道】...
查看>>
HNUSTOJ-1639 分糖果(几何)
查看>>
我的友情链接
查看>>
Linux 服务篇之——httpd的配置(一)
查看>>
亲测!阿里云公共DNS,感觉不错!
查看>>
mysql 的日志的启动与查看
查看>>
MySQL数据迁移实战
查看>>
Eclipse如何安装JD-Eclipse反编译插件
查看>>
ioS开发知识(二十三)
查看>>
Python第三周 学习笔记(1)
查看>>