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类. (官 ...
随机推荐
- c++ 判断两圆位置关系
对于两圆的位置一般有五种关系: (1) 外离:两圆的半径之和小于两圆圆心距离 (2) 外切:两圆的半径之和等于两圆圆心距离 (3) 相交:两圆的半径之和大于两圆圆心距离,两圆圆心距离大于两圆半径之差 ...
- 卸载yum-mysql
注意事项:1. 卸载yum MYSQLsystemctl status mysqlsystemctl stop mysqlsystemctl disable mysqld rpm -qa | grep ...
- 如何获取图片的base64编码
1.准备一张图片,比如1.gif 2.使用chrome浏览器,新建立一个窗口,然后将a.png拖动至浏览器窗口里面,打开控制台(检查),最后点击source 3.使用方法: 注意source获取的一串 ...
- FTP连接不上的解决方法
1.注意内网IP和外网IP 2.检查ftp服务是否启动 (面板首页即可看到) 3.检查防火墙20端口 ftp 21端口及被动端口39000 - 40000是否放行 (如是腾讯云/阿里云等还需检查安全组 ...
- 前端开发HTML&css入门——HTML
HTML究竟为何物?其实HTML就是一种标记语言,英文全称为Hypertext Markup Language,翻译过来就叫超文本标记语言.它的作用就是负责负责网页的三个要素之中的结构. HTML使用 ...
- Ubuntu 增加新用户并赋予root权限及免密的方法
添加用户 添加一个名为hylink的用户 adduser hylink 修改密码 passwd hylink Changing password for user hylink. New UNIX p ...
- python-xss攻击和单例模式
1.python中单例模式 class Foo: instance = None def __new__(cls, *args, **kwargs): if not Foo.instance: Foo ...
- WPS专业版及序列号
目录 1. 软件下载 2. 序列号(永久) 1. 软件下载 城通网盘:https://sn9.us/dir/13403389-35833830-3fc98f (仅Android版) 官网: https ...
- dockerfile制作笔记
dockerfile语法格式: FROM: 基础镜像(就是在什么镜像上面做) MAINTAINER: 镜像创建者信息(作者的信息) EXPOSE: 开放的端口 ENV: 设置变量 ...
- Linux之目录配置
Linux目录配置标准:FHS 主要目的,希望让用户可以了解到已安装软件通常放置于哪个目录下. FHS定义了三层主目录:/./usr./var 1. /(root,根目录) (1)根目录与开机.还原. ...