题目链接: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. Luogu P1084 [NOIP2012]疫情控制

    题目 首先我们二分一下答案. 然后我们用倍增让军队往上跳,最多先跳到根的子节点. 如果当前军队可以到达根节点,那么记录一下它的编号和它到达根节点后还可以走的时间. 并且我们记录根节点的叶子节点上到根节 ...

  2. 最少多少人说谎(dp)

    https://ac.nowcoder.com/acm/contest/1168/H 题意:n个学生,邓志聪想知道这些学生的考试情况,于是一个一个叫这些学生叫去办公室问他们,但是有些学生并没有讲真话, ...

  3. django字段类型(Field types)介绍

    字段类型(Field types) AutoField 它是一个根据 ID 自增长的 IntegerField 字段.通常,你不必直接使用该字段.如果你没在别的字段上指定主 键,Django 就会自动 ...

  4. linux基本命令之磁盘管理命令(ls,cd,pwd,mkdir,rmdir,clear, touch)

    linux磁盘管理命令 1.ls(list)命令:列出目录内容. 格式:ls [参数][文件或目录] ls -a或-all表示列出所有文件和目录,以点开始的是影藏文件,例如,.bash_history ...

  5. Linux下配置JDK环境

    安装前需要查询Linux中是否已经存在jdk 如果存在,将存在的jdk删除 在/etc/profile中添加以下 JAVA_HOME为jdk的安装目录 PATH为jdk可执行文件的目录 使用sourc ...

  6. 基于Nginx+nginx-rtmp-module+ffmpeg搭建rtmp、hls流媒体服务器

    上篇文章是基于Red5与ffmpeg实现rtmp处理NVR或摄像头的监控视频处理方案,有兴趣的朋友可以查看. Nginx及nginx-rtmp-module安装 新建目录 mkdir /usr/loc ...

  7. Nginx和Apache 转发网络问题

    Linux 环境下,Apache 正常安装,httpd.conf也已正常配置,经测试80端口也已开通,但在外网测试时仍然是提示503错误.经过查资料和分析怀疑是SELinux的原因,于是查看果然是: ...

  8. jquery.fancybox.js 解决只加载一次的问题

    问题描述:有一块图片区域,页面第一次加载的时候jQuery(".fancybox-button").fancybox({}); 使用ajax上传成功后显示在图片区域,再次jQuer ...

  9. CSS3边框 圆角效果 border-radius

    border-radius是向元素添加圆角边框 使用方法: border-radius:10px; /* 所有角都使用半径为10px的圆角 */ border-radius: 5px 5px 5px ...

  10. Spring Security初识

    Spring Security与Spring Boot集成 添加依赖: <dependency> <groupId>org.springframework.boot</g ...