题意:两根导线绕在一起,问能不能拉成两条平行线,只能向两端拉不能绕

思路:从左至右,对+-号分别进行配对,遇到连续的两个“+”或连续的两个“-”即可消掉,最后如果全部能消掉则能拉成平行线。拿两根线绕一下就理解了,也可以一根拉成直线,另一根围着它绕,然后观察能拉成直线的条件。用栈实现就行。

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define fillchar(a, x) memset(a, x, sizeof(a))
#define copy(a, b) memcpy(a, b, sizeof(a)) typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned long long ull; //#ifndef ONLINE_JUDGE
void RI(vector<int>&a,int n){a.resize(n);for(int i=;i<n;i++)scanf("%d",&a[i]);}
void RI(){}void RI(int&X){scanf("%d",&X);}template<typename...R>
void RI(int&f,R&...r){RI(f);RI(r...);}void RI(int*p,int*q){int d=p<q?:-;
while(p!=q){scanf("%d",p);p+=d;}}void print(){cout<<endl;}template<typename T>
void print(const T t){cout<<t<<endl;}template<typename F,typename...R>
void print(const F f,const R...r){cout<<f<<", ";print(r...);}template<typename T>
void print(T*p, T*q){int d=p<q?:-;while(p!=q){cout<<*p<<", ";p+=d;}cout<<endl;}
//#endif
template<typename T>bool umax(T&a, const T&b){return b<=a?false:(a=b,true);}
template<typename T>bool umin(T&a, const T&b){return b>=a?false:(a=b,true);}
template<typename T>
void V2A(T a[],const vector<T>&b){for(int i=;i<b.size();i++)a[i]=b[i];}
template<typename T>
void A2V(vector<T>&a,const T b[]){for(int i=;i<a.size();i++)a[i]=b[i];} const double PI = acos(-1.0);
const int INF = 1e9 + ;
const double EPS = 1e-8; /* -------------------------------------------------------------------------------- */ char s[]; int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // ONLINE_JUDGE
while (~scanf("%s", s)) {
stack<char> S;
for (int i = ; s[i]; i ++) {
char ch = s[i];
if (!S.empty() && ch == S.top()) S.pop();
else S.push(ch);
}
puts(S.empty()? "Yes" : "No");
}
return ;
}

[CodeForces 344D Alternating Current]栈的更多相关文章

  1. CodeForces - 344D Alternating Current (模拟题)

    id=46667" style="color:blue; text-decoration:none">CodeForces - 344D id=46667" ...

  2. Codeforces 344D Alternating Current 简单使用栈

    Description Mad scientist Mike has just finished constructing a new device to search for extraterres ...

  3. Codeforces Round #200 (Div. 1) B. Alternating Current 栈

    B. Alternating Current Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343 ...

  4. 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 ...

  5. codeforces 963A Alternating Sum

    codeforces 963A Alternating Sum 题解 计算前 \(k\) 项的和,每 \(k\) 项的和是一个长度为 \((n+1)/k\) ,公比为 \((a^{-1}b)^k\) ...

  6. Alternating Current

    Codeforces Round #200 (Div. 1) B:http://codeforces.com/problemset/problem/343/B 题意:这一题看懂题意是关键,题目的意思就 ...

  7. Psychos in a Line CodeForces - 319B (单调栈的应用)

    Psychos in a Line CodeForces - 319B There are n psychos standing in a line. Each psycho is assigned ...

  8. cf D. Alternating Current

    http://codeforces.com/contest/344/problem/D #include <cstdio> #include <cstring> #includ ...

  9. Codeforces 963A Alternating Sum(等比数列求和+逆元+快速幂)

    题目链接:http://codeforces.com/problemset/problem/963/A 题目大意:就是给了你n,a,b和一段长度为k的只有'+'和‘-’字符串,保证n+1被k整除,让你 ...

随机推荐

  1. 微信小程序 —搜索框

    wxSearch优雅的微信小程序搜索框 一.功能 支持自定义热门key 支持搜索历史 支持搜索建议 支持搜索历史(记录)缓存 二.使用 1.将wxSearch文件夹整个拷贝到根目录下 2.引入 // ...

  2. WinRAR代码执行漏洞复现

    漏洞介绍 WinRAR 是一款流行的解压缩工具,据其官网上发布的数据,全球有超过5亿的用户在使用 2019年2月20日,安全厂商 checkpoint 发布了名为<Extracting a 19 ...

  3. Spring5:概念

    1.Spring优点 spring是一个开源的免费的框架 spring是一个轻量级的 非入侵式的框架 控制反转(IOC).面向切面(AOP) 支持事务的处理,对框架整合的支持 **总之:spring就 ...

  4. react: nextJs koa project basic structure

    1.init nextJs project npm init npm install react react-dom next config script in package.json " ...

  5. Spring Security 是如何在 Servlet 应用中执行的?

    Spring Security 是一个强大的认证和授权框架,它的使用方式也非常简单,但是要想真正理解它就需要花一时间来学习了,最近在学习 Spring Security 时有一些新的理解,特意记录下来 ...

  6. 定期清理nohup.out

    事件背景 服务应用weblogic通过nohup启动. nohup的使用全部都在weblogic域中的bin目录下 但是没有做定期nohup.out的清理 导致核心服务的日志过大,在出现问题时候难以打 ...

  7. SVN diff

    http://svnbook.red-bean.com/en/1.6/svn.ref.svn.c.diff.html Name svn diff (di) — This displays the di ...

  8. QT 获取可执行程序的路径

    获取到生成.exe目录 QCoreApplication::applicationDirPath(); 获取当前工程目录 QDir::currentPath()

  9. zabbix监控ftp

    [root@agent ~]# yum -y install vsftpd [root@agent ~]# systemctl start vsftpd[root@agent ~]# systemct ...

  10. CUBA:如何准备上线

            "在我电脑上是好的呢!"现在看来,这句话更像是调侃开发人员的一个段子,但是"开发环境与生产环境"之间的矛盾依然存在.作为开发者,你需要记住,你写 ...