Codeforces 344D Alternating Current【模拟】
来源:互联网 发布:淘宝标题怎么改 编辑:程序博客网 时间:2024/06/07 01:04
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 andwithout 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.
The single line of the input contains a sequence of characters "+" and "-" of lengthn (1 ≤ n ≤ 100000). Thei-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on thei-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise.
Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled.
-++-
Yes
+-
No
++
Yes
-
No
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:
给你一堆+号和-号,两两相邻并且相同符号的就可以消去,问最终能否将所有线解开(将所有符号消去);
思路:
1、本题放在D题难度纯是难在读题上边。
2、本题就是一个栈模拟,很容易实现。
Ac代码:
#include<stdio.h>#include<string.h>#include<stack>using namespace std;char a[100500];int main(){ while(~scanf("%s",a)) { stack<char >s; int n=strlen(a); for(int i=0;i<n;i++) { if(s.size()==0) { s.push(a[i]); } else { if(s.top()==a[i])s.pop(); else s.push(a[i]); } } if(s.size()==0)printf("Yes\n"); else printf("No\n"); }}
- CodeForces - 344D Alternating Current (模拟题)
- Codeforces 344D Alternating Current【模拟】
- Codeforces 344D - Alternating Current
- Codeforces Round #200 (Div. 2)344D Alternating Current(栈)
- Codeforces Round #200 (Div. 2)D. Alternating Current
- Codeforces Round #200 (Div. 2)D. Alternating Current (堆栈)
- CodeForces 343B Alternating Current
- CodeForces 343B - Alternating Current
- CF#200 div2 D Alternating Current(stack)
- codeforces 343B Alternating Current 【栈】
- Alternating Current
- Alternating Current
- Alternating Current
- B. Alternating Current----栈
- codeforces 157D 模拟
- Codeforces 637D 模拟
- Codeforces 665D 模拟
- Codeforces 669D 模拟
- Mybatis完全使用指南
- 得分SCORE UVA1585
- 第1章 BashShell命令------------(vim编辑器)
- Fckeditor插件的使用
- 统计Java web项目的行数的代码
- Codeforces 344D Alternating Current【模拟】
- 解决CentOS中JDK7中文验证码乱码问题
- Java8 Stream 的并发
- web.xml 中的listener、 filter、servlet 加载顺序及其详解
- POJ 3977Subset
- js跨域问题
- docke入门
- 【转载】移植多款轻量级 Web服务器到ARM-Linux系统
- 关于程序编写中遇到的细节问题