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类. (官 ...
随机推荐
- Thinkphp3.2 Redis支持REDIS_AUTH验证
原有的Redis类在Library/Think/Cache/Driver/中 换成下面的: <?php // +----------------------------------------- ...
- python中django中间件
一.中间件 所谓的中间件,就是存在socket和视图函数中间的一种相当于过滤的机构. 中间件共分为: (1)process_request(self,request) (2)process_view( ...
- RESTful API 设计总结
RESTful API 设计总结 @(技术-架构)[API, 规范, 设计] RESTful的接口设计风格应用的越来越广泛,包括Spring Cloud等微服务架构平台之间的调用都是以RESTful设 ...
- LazyMan的深入解析和实现
一.题目介绍 以下是我copy自网上的面试题原文: 实现一个LazyMan,可以按照以下方式调用: LazyMan("Hank")输出: Hi! This is Hank! L ...
- 40. Combination Sum II (JAVA)
Given a collection of candidate numbers (candidates) and a target number (target), find all unique c ...
- python2和3的一些区别,编码方式
python2与python3的区别: #python2 print() print'abc' #range() xrange()生成器 #raw_input()#python3 #print('ab ...
- 编写第一个Qt程序
http://c.biancheng.net/view/1817.html 学习一种编程语言或编程环境,通常会先编写一个“Hello World”程序.我们也用 Qt Creator 编写一个“Hel ...
- Linux-day-1
1. ls 作用:列出文件信息,默认为当前目录下 常用选项: -a: 列出所有的文件,包括所有以.开头的隐藏文件 -d: 列出目录本身,并不包含目录中的文件 ...
- Linux之vim按键
1. 移动光标的方法 h或左箭头 光标向左移动一个字符 j或下箭头 光标向下移动一个字符 k或上箭头 光标向上移动一个字符 l或右箭头 光标向右移动一个字符 如果想要向下移动30行,可以使用“30j” ...
- jenkins上job误删除怎么恢复
1.点击jobConfigHistory 2.点击Show deleted jobs only 3.找到被删除的 记录,点击Restore