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的个数 ...
随机推荐
- 【大白话系统】MySQL 学习总结 之 缓冲池(Buffer Pool) 的设计原理和管理机制
一.缓冲池(Buffer Pool)的地位 在<MySQL 学习总结 之 InnoDB 存储引擎的架构设计>中,我们就讲到,缓冲池是 InnoDB 存储引擎中最重要的组件.因为为了提高 M ...
- Xamarin.Forms 二维码扫描实践
开发环境: Visual Studio 2019 版本 16.4.5 公用平台nuget ZXing.Net.Mobile.Forms 2.4.1 Plugin.Permissions 5.0.0-b ...
- 【Java并发工具类】CountDownLatch和CyclicBarrier
前言 下面介绍协调让多线程步调一致的两个工具类:CountDownLatch和CyclicBarrier. CountDownLatch和CyclicBarrier的用途介绍 CountDownLat ...
- Keras学习系列——神经网络层组件
对Keras提供的对各种层的抽象进行相对全面的概括 1 基础常用层 名称 作用 原型参数 Dense 实现全连接层 Dense(units,activation,use_bias=True, kern ...
- [redis读书笔记] 第一部分 数据结构与对象 链表
二 链表 1.链表节点使用ListNode结构,是一个双向的链表,同时,还实现了一个控制所有ListNode的结构list: typedef struct listNode { // 前置节点 str ...
- CentOS与Ubuntu的区别
学习博客:https://www.cnblogs.com/lirongzheng/p/8250511.html 更多Ubuntu相关信息见Ubuntu 专题页面 http://www.linuxidc ...
- JS求1到100的累计值
sum=0 for(i=1;i<=100;i++) { sum+=i } alert(sum) 作者:kerwin-chyl 文章链接:https:////www.cnblogs.com/k ...
- Zookeeper机制
顾名思义 zookeeper 就是动物园管理员,他是用来管 hadoop(大象).Hive(蜜蜂).pig(小 猪)的管理员, Apache Hbase 和 Apache Solr 的分布式集群都用到 ...
- 802.11有线等效加密WEP
有线等效加密(WEP)标准是802.11无线安全早期的解决方案,WEP并不安全. 既然WEP并不安全,为什么还要学习WEP呢? WEP简单,相比后续出现的加密协议,它不要求有多么强大的计算能力.一些老 ...
- 股票数据获取到了,导入MT4中,是否可以做出很好的量化交易策略呢?
寻找了很久,看到有tushare这个python的类库,但研究了几个小时都没有研究明白,anaconda安装和pycharm的使用都不是特别顺手,最后也是失败告终.还有就是我的低配的平板suerfac ...