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,讨论一下.只需考虑,每一个磁盘是从右边的头,刷过来的(左边来的 ...
随机推荐
- UVa 12171 (离散化 floodfill) Sculpture
题意: 三维空间中有n个长方体组成的雕塑,求表面积和体积. 分析: 我们可以在最外边加一圈“空气”,然后求空气的连通块的体积,最后用总体积减去即是雕塑的体积. 还有一个很“严重”的问题就是5003所占 ...
- poj 2185 (KMP)
完全不会啊…… 附一份题解:http://blog.sina.com.cn/s/blog_69c3f0410100tyjl.html var i,j,k,r,c,x:longint; ch:..,.. ...
- Vim常用配置(~/.vimrc)(转载)
原文地址:http://www.2cto.com/os/201309/246271.html " This must be first, beacuse it changes other o ...
- 使用SVN小结
自从加入团队后,开始使用SVN,以下是个人对SVN的一些认识和小结. 一.SVN是什么? SVN是版本管理工具,譬如团队进行项目开发,项目代码都储存在服务器上,成员可用SVN在本地获得并更新代码. 二 ...
- jQuery轻量级京东图片轮播代码等
http://sc.chinaz.com/jiaoben/jiaodiantu.html jQuery轻量级京东图片轮播代码 查看全图点击预览 顶(17)踩(4)报错评论(0)下载地址 更新时间: ...
- #pragma alloc_text 与 ALLOC_PRAGMA
百度标题中的两部分,可以找到很多文章,现将收集到的其中两篇整理如下: 转载链接:http://hi.baidu.com/billbeggar/item/c378e2ea39a5daeffa42bada ...
- vector(相对线程安全) arryList(线程不安全)
1.什么是线程安全? 如果说某个集合是线程安全的,那么我们就不用考虑并发访问这个集合?(需要定义自己百度,但是很难懂) 2.深入jvm中的线程安全的级别. a不变模式(String等基本类型) b.绝 ...
- 给定金额m和红包数量n
这一题如果是采用暴力手段,不一定能获得正确答案,而且也非常耗时. 所以下面我们采用一个小技巧,也就是先产生n-1个红包,总得sum<m的,这样最后只要添加一个sum-m的红包钱数就可以了. 具体 ...
- ADB Server Didn’t ACK ,failed to Start Daemon 解决方法
解决方法如下: 1.adb nodaemon server 查看不能执行的原因,输出: cannot bind ‘tcp:5037’ 2.定位到了是端口的问题!是5037端口被占用了! 3.netst ...
- leetcode–Binary Tree Maximum Path Sum
1.题目说明 Given a binary tree, find the maximum path sum. The path may start and end at any node in t ...