题目链接: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的更多相关文章

  1. Gym 100507H Pair: normal and paranormal (贪心)

    Pair: normal and paranormal 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/H Description ...

  2. 【贪心】Gym - 100507H - Pair: normal and paranormal

    每次取相邻的两个可以射击的从序列中删除,重复n次. 可以看作括号序列的匹配. #include<cstdio> #include<vector> using namespace ...

  3. ural 2019 Pair: normal and paranormal

    2019. Pair: normal and paranormal Time limit: 1.0 secondMemory limit: 64 MB If you find yourself in ...

  4. URAL 2019 Pair: normal and paranormal (STL栈)

    题意:在一个半圆内,有2*n个点,其中有大写字母和小写字母.其中你需要连接大写字母到小写字母,其中需要保证这些连接的线段之间没有相交. 如果能够实现,将大写字母对应的小写字母的序号按序输出. 析:我把 ...

  5. URAL 2019 Pair: normal and paranormal (贪心) -GDUT联合第七场

    比赛题目链接 题意:有n个人每人拿着一把枪想要杀死n个怪兽,大写字母代表人,小写字母代表怪兽.A只能杀死a,B只能杀死b,如题目中的图所示,枪的弹道不能交叉.人和怪兽的编号分别是1到n,问是否存在能全 ...

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

  7. 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个大写字母和 ...

  8. NEERC 2014, Eastern subregional contest

    最近做的一场比赛,把自己负责过的题目记一下好了. Problem B URAL 2013 Neither shaken nor stirred 题意:一个有向图,每个结点一个非负值,可以转移到其他结点 ...

  9. apache_commons 之 双向Map DualHashBidiMap (使用及源码)

    在项目当中,经常出现需要根据Key值获取value:而且要求根据value获取key值,其实在commons-collections包中已经提供了此集合类.就是DualHashBidiMap类. (官 ...

随机推荐

  1. C++中的const分析

    1,C 语言中的 const: 1,const 修饰的变量是只读的,本质还是变量: 1,C 语言中的 const 使变量具有只读属性: 2,const 只在编译期有用,在运行期无用: 3,const ...

  2. gcc编译工具生成动态库和静态库

    一. 库的分类 1.1. 静态库(.a) 1.1.1. 静态库的代码在编译过程中已经被载入可执行程序,因此体积比较大.所以生成的可执行文件就不受库的影响了,即使库被删除了,程序依然可以成功运行. 1. ...

  3. [Codeforces 1214D]Treasure Island(dfs)

    [Codeforces 1214D]Treasure Island(dfs) 题面 给出一个n*m的字符矩阵,'.'表示能通过,'#'表示不能通过.每步可以往下或往右走.问至少把多少个'.'变成'#' ...

  4. 搜索专题: HDU2102 A计划

    这不知道是公主被抓走了第几次了,反正我们的骑士救就对了(别说了,我都救我都救...);这次的迷宫有些特别,双层,带电梯(?),而且这个电梯还有生命危险,可能会撞死(一层是电梯,一层是墙),或者永远困在 ...

  5. Python 里面如何生成随机数?

    在 Python 中用于生成随机数的模块是 random,在使用前需要 import. 如下例子可以酌情列举: random.random():生成一个 0-1 之间的随机浮点数: random.un ...

  6. wordpress添加index页面跳转链接

    1. 制作page页面 1.1 在themes下的主题目录新建一个page页面 1.2 在wordpress后台新建页面跟在目录页面中相同名字的页面文件 1.3 复制后台页面中的古定链接 1.4 在i ...

  7. gp指标信息

    RSI: 相对强弱指数,RSI的原理简单来说是以数字计算的方法求出买卖双方的力量对比 强弱指标理论认为,任何市价的大涨或大跌,均在0-100之间变动,根据常态分配 认为RSI值多在30-70之间变动, ...

  8. 基于maven搭建hibernate运行环境

    准备案例需要的数据库表和测试数据 建表语句: create table DEPARTMENT ( DEPT_ID integer not null, DEPT_NAME ) not null, DEP ...

  9. 一、ASP.NET Iframework_SignalR永久连接类(v2)

    一.新建项目,选MVC项目默认 添加mvc文件夹和核心引用 二.添加SignaIR包 SignalR的准备:NuGet包管理器搜索:工具——>库程序包管理器——>Microsoft.Asp ...

  10. tf Dataset API

    https://zhuanlan.zhihu.com/p/30751039 https://zhuanlan.zhihu.com/p/37106443 关于其中shuffle时的buffer_size ...