Alternating Current
Codeforces Round #200 (Div. 1) B:http://codeforces.com/problemset/problem/343/B
题意:这一题看懂题意是关键,题目的意思就是两根a,b电线相互缠绕,+表示a在b的上面,-表示b在a的上面,给以一个串,然后问你这两根线能否解开。
题解:显然,如果两个相邻的++或者--的话可以直接消去,然后就会想到用栈来模拟,相同的就消去,不同的就进栈,最后判断栈内是否为空就可以了。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e5+;
char ans[N],a[N];
int n,top;
int main(){
while(~scanf("%s",a)){
n=strlen(a);top=;
for(int i=;i<n;i++){
if(top==){
ans[++top]=a[i];
}
else if(a[i]==ans[top]){
top--;
}
else ans[++top]=a[i];
}
if(top==)printf("Yes\n");
else
printf("No\n");
}
}
Alternating Current的更多相关文章
- Codeforces Round #200 (Div. 1) B. Alternating Current 栈
B. Alternating Current Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343 ...
- CodeForces - 344D Alternating Current (模拟题)
id=46667" style="color:blue; text-decoration:none">CodeForces - 344D id=46667" ...
- 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 ...
- cf D. Alternating Current
http://codeforces.com/contest/344/problem/D #include <cstdio> #include <cstring> #includ ...
- Codeforces 344D Alternating Current 简单使用栈
Description Mad scientist Mike has just finished constructing a new device to search for extraterres ...
- [CodeForces 344D Alternating Current]栈
题意:两根导线绕在一起,问能不能拉成两条平行线,只能向两端拉不能绕 思路:从左至右,对+-号分别进行配对,遇到连续的两个“+”或连续的两个“-”即可消掉,最后如果全部能消掉则能拉成平行线.拿两根线绕一 ...
- Electronic oscillator
https://en.wikipedia.org/wiki/Electronic_oscillator An electronic oscillator is an electronic circui ...
- Arduino 极速入门系列 - 光控灯(1)- 关于理论和 LED 那些事
点个 LED 闪亮好像太单调,这次来个光控 LED 灯.这个其实不需要 Arduino 也能做,这次只是用来演示一下 PWM 在 Arduino 里面的做法.PWM 原理后面会解释.这次用充电宝提供 ...
- RFID 基础/分类/编码/调制/传输
不同频段的RFID产品会有不同的特性,本文详细介绍了无源的感应器在不同工作频率产品的特性以及主要的应用. 目前定义RFID产品的工作频率有低频.高频和甚高频的频率范围内的符合不同标准的不同的产品,而且 ...
随机推荐
- tuple类型的单词查询例子
17.3 重写前面的TextQuery程序,使用tuple代替QueryResult类. TextQuery.h #ifndef TEXTQUERY_H #define TEXTQUERY_H #in ...
- 【转】iOS应用崩溃日志揭秘
这篇文章还可以在这里找到 英语 If you're new here, you may want to subscribe to my RSS feed or follow me on Twitter ...
- LAMP环境部署总结
linux+apche+mysql+php 此次用到的工具有:/etc/init.d/iptables , selinux, useradd, yum,chkconfig,sshd,visudo,cr ...
- 【转】谈Objective-c block的实现
本文转自http://blog.devtang.com/blog/2013/07/28/a-look-inside-blocks/,如有侵权,请联系我删除 前言 这里有关于block的5道测试题,建议 ...
- 一个基于MVVM的TableView组件化实现方案
AITableView https://github.com/chentoo/AITableView cocoapods: pod ‘AITableView’ 做什么用? 这是一个简化UITableV ...
- centos emacs安装
wget http://mirrors.ustc.edu.cn/gnu/emacs/emacs-24.5.tar.gz tar zxvf emacs-24.5.tar.gz cd emacs-24.5 ...
- System Operations on AWS - Lab 3W - Managing Storage (Windows)
创建一个名叫Processor的EC2实例,登陆到CommandHost实例,通过AWS CLI对Processor实例的EBS卷做snapshot,设置周期性snapshot的计划任务, 登陆到Pr ...
- codeforces 580D Kefa and Dishes(状压dp)
题意:给定n个菜,每个菜都有一个价值,给定k个规则,每个规则描述吃菜的顺序:i j w,按照先吃i接着吃j,可以多增加w的价值.问如果吃m个菜,最大价值是多大.其中n<=18 思路:一看n这么小 ...
- php快速定位多维数组的深度
原文地址:php快速定位多维数组的深度作者:陌上花开 自定义一个函数: function array_depth($array) { $max_depth = 1; foreach ($array ...
- (转)Spring 读书笔记-----使用Spring容器(一)
Spring有两个核心接口:BeanFactory和ApplicationContext,其中ApplicationContext是BeanFactory的子接口.他们都可代表Spring容器,Spr ...