Gym 100507H - Pair: normal and paranormal
题目链接:http://codeforces.com/gym/100507/attachments
----------------------------------------------------------------------------
刚看这题的时候感觉是区间$DP$ 然而复杂度一直停留在$O(n^3)$优化不下来
后来又瞎试了一些贪心 都在较大的数据上挂掉了
反复琢磨着大写字母和相应小写字母匹配 便想到了以前做过的括号匹配
只不过此题大写字母和小写字母的左右关系是不限制的
因此可以用一个栈来辅助贪心
如果当前加入的新的字母可以直接和栈顶匹配就直接让它们匹配
否则先丢在栈顶放着(防止做了这个匹配后使得匹配线之间的字母被限制住无法匹配)
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int N = ;
char s[N];
int sta[N];
int ma[N], ans[N], num[N];
int n, len, top;
int main()
{
scanf("%d%s", &n, s + );
len = n << ;
for(int i = ; i <= len; ++i)
if(!top || abs((int)s[sta[top - ]] - s[i])!= )
sta[top++] = i;
else
{
ma[i] = sta[top - ];
ma[sta[top - ]] = i;
--top;
}
if(top)
{
puts("Impossible");
return ;
}
for(int i = ; i <= len; ++i)
if(s[i] < 'a')
num[i] = num[i - ];
else
num[i] = num[i - ] + ;
for(int i = ; i <= len; ++i)
if(s[i] < 'a')
printf("%d ", num[ma[i]]);
}
Gym 100507H - Pair: normal and paranormal的更多相关文章
- Gym 100507H Pair: normal and paranormal (贪心)
Pair: normal and paranormal 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/H Description ...
- 【贪心】Gym - 100507H - Pair: normal and paranormal
每次取相邻的两个可以射击的从序列中删除,重复n次. 可以看作括号序列的匹配. #include<cstdio> #include<vector> using namespace ...
- ural 2019 Pair: normal and paranormal
2019. Pair: normal and paranormal Time limit: 1.0 secondMemory limit: 64 MB If you find yourself in ...
- URAL 2019 Pair: normal and paranormal (STL栈)
题意:在一个半圆内,有2*n个点,其中有大写字母和小写字母.其中你需要连接大写字母到小写字母,其中需要保证这些连接的线段之间没有相交. 如果能够实现,将大写字母对应的小写字母的序号按序输出. 析:我把 ...
- URAL 2019 Pair: normal and paranormal (贪心) -GDUT联合第七场
比赛题目链接 题意:有n个人每人拿着一把枪想要杀死n个怪兽,大写字母代表人,小写字母代表怪兽.A只能杀死a,B只能杀死b,如题目中的图所示,枪的弹道不能交叉.人和怪兽的编号分别是1到n,问是否存在能全 ...
- H - Pair: normal and paranormal URAL - 2019
If you find yourself in Nevada at an abandoned nuclear range during Halloween time, you’ll become a ...
- 2014-2015 ACM-ICPC, NEERC, Eastern Subregional Contest Problem H. Pair: normal and paranormal
题目链接:http://codeforces.com/group/aUVPeyEnI2/contest/229669 时间限制:1s 空间限制:64MB 题目大意:给定一个长度为2n,由n个大写字母和 ...
- NEERC 2014, Eastern subregional contest
最近做的一场比赛,把自己负责过的题目记一下好了. Problem B URAL 2013 Neither shaken nor stirred 题意:一个有向图,每个结点一个非负值,可以转移到其他结点 ...
- apache_commons 之 双向Map DualHashBidiMap (使用及源码)
在项目当中,经常出现需要根据Key值获取value:而且要求根据value获取key值,其实在commons-collections包中已经提供了此集合类.就是DualHashBidiMap类. (官 ...
随机推荐
- 卷积神经网络(ConvNets)中卷积的实现
#include <iostream> #include <sstream> #include <fstream> #include <algorithm&g ...
- 【JZOJ 3909】Idiot 的乘幂
题面: 正文: 把题目中的方程组组合在一起就变成了: \(X^{a+c}\equiv b \cdot d (\mod p)\) 那这时,我们假定两个数\(x\)和\(y\),使得: \(ax + cy ...
- T-聊天止于呵呵
(现代版)俗话说:流言止于智者,聊天止于呵呵.输入一段聊天记录,你的任务是数一数有 多少段对话“止于呵呵”,即对话的最后一句话包含单词 hehe 或者它的变形. 具体来说,我们首先提取出对话的最后一句 ...
- dsu on tree 与长链剖分
dsu on tree 对于树进行轻重链剖分,对于节点 $x$ ,递归所有轻儿子后消除其影响,递归重儿子,不消除其影响. 然后对于所有轻儿子的子树暴力,从而得到 $x$ 的答案. 对于要消除暴力消除即 ...
- maven联通网络下中央仓库不能访问的解决办法
最近刚开始学习maven工具,下载解压完毕,环境变量配置完毕,运行如下命令尝试快速构建一个maven项目: mvn archetype:generate 结果就有问题: [INFO] Scanning ...
- es7.2版本安装ik分词
(一)到官网下载https://github.com/medcl/elasticsearch-analysis-ik对应版本的ik(直接下载releases版本,避免maven打包!!!如果不是这个版 ...
- Listview使用
ListView控件比前面几种控件要复杂一些,通过此控件,可将项目组成带有或不带有列标头的列,并显示伴随的图标和文本.ListView控件是由ColumnHeader和ListItem对象所组成的,其 ...
- 北京师范大学第十五届ACM决赛-重现赛C Captcha Cracker (字符串模拟)
链接:https://ac.nowcoder.com/acm/contest/3/C 来源:牛客网 Captcha Cracker 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 26 ...
- mnist 卷积神经网络
# from keras.models import Sequential# from keras.layers.core import Dense,Activation,Flatten #creat ...
- this 指向图