Game with string CodeForces - 1104B
虽然只是B题,还是div2的
但感觉挺有意思,所以写一篇博客记录一下
最初的想法是利用DP去做,f[s]=true表示字符串s对应先手赢,否则对应后手赢,大致想了下发现是指数级别的算法,看了下范围直接pass掉
然后就接着想,发现如果两个相等的字符被消掉之后,相等字符的周边靠过来,如果还能消除的话他们就是相等,一想这不就是括号匹配?
然后问题就转化为了寻找合法括号字段的长度
然后就简单了
竟然是用栈来做!!!
#include<cstdio>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<stack>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
//#define endl "\n"
#define inf 0x3f3f3f3f
#define me(a,b) memset(a,b,sizeof(a)) string s;
stack<char> st;
int main()
{
cin>>s;
int cnt=;
for(auto i:s){
if(st.empty()) st.push(i);
else {
char c=st.top();
if(c==i) cnt++,st.pop();
else st.push(i);
}
}
if(cnt&) puts("Yes");
else puts("No"); }
Game with string CodeForces - 1104B的更多相关文章
- Minimal string CodeForces - 797C
Minimal string CodeForces - 797C 题意:有一个字符串s和空串t和u,每次操作可以将s的第一个字符取出并删除然后放到t的最后,或者将t的最后一个字符取出并删除然后放到u的 ...
- D. Mahmoud and Ehab and the binary string Codeforces Round #435 (Div. 2)
http://codeforces.com/contest/862/problem/D 交互题 fflush(stdout) 调试: 先行给出结果,函数代替输入 #include <cstdio ...
- You Are Given a Decimal String... CodeForces - 1202B [简单dp][补题]
补一下codeforces前天教育场的题.当时只A了一道题. 大致题意: 定义一个x - y - counter :是一个加法计数器.初始值为0,之后可以任意选择+x或者+y而我们由每次累加结果的最后 ...
- Check the string CodeForces - 960A
A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend ...
- Median String CodeForces - 1144E
You are given two strings ss and tt, both consisting of exactly kk lowercase Latin letters, ss is le ...
- Minimal string CodeForces – 797C
题目链接 题目难度: 1700rating 题目类型:string+贪心+STL 题目思路: 由于题目要求的最终结果是字典序最小的那个字符串,那么我们从贪心的从’a’开始查找字符串里是否存在,如果存在 ...
- Crisp String CodeForces - 1117F (状压)
#include <iostream> #include <algorithm> #include <cstdio> #include <math.h> ...
- Balanced Ternary String CodeForces - 1102D (贪心+思维)
You are given a string ss consisting of exactly nn characters, and each character is either '0', '1' ...
- codeforces 930b//Game with String// Codeforces Round #468 (Div. 1)
题意:一个串,右循环移位后,告诉你第一个字母,还能告诉你一个,问你能确定移位后的串的概率. 用map记录每个字母出现的位置.对于每个字母,用arr[j][k]记录它的所有出现位置的后j位是字母k的个数 ...
随机推荐
- 题解 USACO12DEC【逃跑的BarnRunning Away From…】
期末考前写题解,\(rp++! \ rp++! \ rp++!\) \[ description \] 给出一个以 \(1\) 为根的边带权有根树,给定一个参数 \(L\) ,问每个点的子树中与它距离 ...
- JavaWeb前置知识 : 动态和静态的区别、两种架构、常见状态码
JavaWeb程序设计(一) : 前置知识 1.动态网页与静态网页的区别: a.不要和是否有"动感"混为一谈. b.是否随着时间.地点.用户操作的改变而改变 (例如 : 在百度上搜 ...
- Python3(二) 表示‘组’的概念与定义
现实世界中总存在一组一组的事物, 一.列表的定义 type(['hello','world',1,9,True,False]) = <class 'list'> type([[1,2,3, ...
- ajax 解决中文乱码问题
最近遇到了ajax 中文乱码的问题.下面总结一下 1. HTTP协议的编码规定 在HTTP协议中,浏览器不能向服务器直接传递某些特殊字符,必须是这些字符进行URL编码后再进行传送.url编码遵循的规则 ...
- qt creator源码全方面分析(2-10-5)
目录 The Plugin Manager, the Object Pool, and Registered Objects 插件管理器 对象池和已注册对象 The Plugin Manager, t ...
- sun.misc.Unsafe中一些常用方法记录
sun.misc.Unsafe中一些常用方法记录 前情摘要 sun公司提供了可以用于直接操作内存的类,这个类就是sun.misc.Unsafe.因为Java本身是不会涉及到直接操作内存的,Java A ...
- Bookshelf 2 01背包
B - Bookshelf 2 Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submi ...
- typeof和类型转换
编程形式 ① 面向过程 ② 面向对象 ③ Js既面向过程又面向对象 typeof(数据) 1)typeof(数据)返回该数据是什么类型的 2)写法: ① typeof(数据) ② typeof 数据 ...
- mybatis postgresql 批量删除
一.需求介绍 前端是一个列表页面,列表可以进行复选框的选择,后台进行关联表数据的删除. 二.框架介绍 springboot+mybatis 数据库用的postgresql 三.具体代码(前端js) 1 ...
- 【公告】Hello World!
Hi! 这里 是 华中师大一附中 2019 级信息组 官方博客 ! ^_^ 我们将在这里分享一些难题的做法,帮助大家共同学习. 也欢迎同是OIer的你加入我们哦!