Codeforces Round #200 (Div. 1) B. Alternating Current 栈
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
Output
Sample Input
-++-
Sample Output
Yes
HINT
题意
有两条直线缠绕在一起,一条直线是+,一条直线是-
如果+就表示第一条直线在上面,如果是-,就表示第二条直线在上面
问你能否直接拉,就能把这两条直线拉成平行线
题解:
首先我们想一想,必须是偶数个才行,不然的话,根本不可能拉成平行线
必须得两个连在一起的符号一样才能消除,于是我们就用栈来搞定就好啦
代码:
#include<stdio.h>
#include<stack>
#include<iostream>
using namespace std; string S;
int main()
{
stack<char> s;
cin>>S;
for(int i=;i<S.size();i++)
{
char ch = S[i];
if(!s.empty()&&ch==s.top())s.pop();
else s.push(ch);
}
if(s.empty())printf("Yes\n");
else printf("No\n");
}
Codeforces Round #200 (Div. 1) B. Alternating Current 栈的更多相关文章
- Codeforces Round #200 (Div. 2)D. Alternating Current (堆栈)
D. Alternating Current time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #200 (Div. 1 + Div. 2)
A. Magnets 模拟. B. Simple Molecules 设12.13.23边的条数,列出三个等式,解即可. C. Rational Resistance 题目每次扩展的电阻之一是1Ω的, ...
- Codeforces Round #200 (Div. 1) C. Read Time 二分
C. Read Time Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343/problem/C ...
- Codeforces Round #200 (Div. 1)A. Rational Resistance 数学
A. Rational Resistance Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343 ...
- Codeforces Round #200 (Div. 1)D. Water Tree dfs序
D. Water Tree Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343/problem/ ...
- Codeforces Round #200 (Div. 2) C. Rational Resistance
C. Rational Resistance time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #200 (Div. 1) BCD
为了锻炼个人能力奋力div1 为了不做原题从200开始 B 两个电线缠在一起了 能不能抓住两头一扯就给扯分开 很明显当len为odd的时候无解 当len为偶数的时候 可以任选一段长度为even的相同字 ...
- Codeforces Round #200 (Div. 1) D. Water Tree(dfs序加线段树)
思路: dfs序其实是很水的东西. 和树链剖分一样, 都是对树链的hash. 该题做法是:每次对子树全部赋值为1,对一个点赋值为0,查询子树最小值. 该题需要注意的是:当我们对一棵子树全都赋值为1的 ...
- Codeforces Round #200 (Div. 2) E. Read Time(二分)
题目链接 这题,关键不是二分,而是如果在t的时间内,将n个头,刷完这m个磁盘. 看了一下题解,完全不知怎么弄.用一个指针从pre,枚举m,讨论一下.只需考虑,每一个磁盘是从右边的头,刷过来的(左边来的 ...
随机推荐
- Spring事务Transaction配置的五种注入方式详解
Spring事务Transaction配置的五种注入方式详解 前段时间对Spring的事务配置做了比较深入的研究,在此之间对Spring的事务配置虽说也配置过,但是一直没有一个清楚的认识.通过这次的学 ...
- C/C++中static关键词的作用
1.在函数体内的static变量作用范围是该函数体,其只被内存分配一次,所以在下次调用的时候会保持上一次的值. 2.模块内的static全局变量可以被模块内的所有函数访问,但不能被模块外的函数访问. ...
- pyqt实践——从裸机到打包安装
1 安装python 安装python-2.7.6.msi默认在c盘 设置环境变量,path后追加c:/python27.可以在命令行直接认识命令python 2 安装pyqt PyQt4-4.10- ...
- mac terminal终端ls命令参数详解
原文:https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/ls.1.html -a ...
- POJ 1149 PIGS ★(经典网络流构图)
[题意] 有M个猪圈,每个猪圈里初始时有若干头猪.一开始所有猪圈都是关闭的.依 次来了N个顾客,每个顾客分别会打开指定的几个猪圈,从中买若干头猪.每 个顾客分别都有他能够买的数量的上限.每个顾客走后, ...
- I.MX6 Android 移除 Settings wifi功能
/********************************************************************* * I.MX6 Android 移除 Settings w ...
- Java传参那些事!
刚刚学习java传参的时候很纠结,也非常的不理解!课本上的“按值传递”和“按址传递”搞的自己是一头雾水,后来写的项目多了,自然就明白了! 现在写传参几乎就是条件反射一般——“秒成”,分享当初自己为此写 ...
- Imageview使用记录
1. imageView清除背景 原文网址:http://blog.csdn.net/lzq1039602600/article/details/40393591 两种清除 imageView的背景 ...
- servlet规范
Servlet规范 一个最基本的 Java Web 项目所需的 jar 包只需要一个 servlet-api.jar ,这个 jar 包中的类大部分都是接口,还有一些工具类,共有 2 个包,分别是 j ...
- 6、四大组件之二-Service初步
一.什么是Service 有些用时比较长得操作我们希望他在后台运行 ,不耽误我们当前的操作 . 这就引入了Service概念 . 常见的比如:访问网络 , 文件IO操作 , 大数据的数据库任务,播放音 ...