比赛题目链接

题意:n个人每人拿着一把枪想要杀死n个怪兽,大写字母代表人,小写字母代表怪兽。A只能杀死aB只能杀死b,如题目中的图所示,枪的弹道不能交叉。人和怪兽的编号分别是1n,问是否存在能全部杀死的情况,如果存在则输出编号1n的每个人杀死的怪兽的编号,如果不能输出"Impossible"。

题解:贪心,用递归实现,判断相邻的是否能构成一对,优先构成相邻的,如果不能就递归到前面看是否能构成一对即可。

#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
int n,e;
char data[*];
int Next[*];
bool eq(char a,char b) {
bool ta=,tb=;
if(a>='A'&&a<='Z') {
a-='A';
ta=;
}
if(a>='a'&&a<='z') a-='a';
if(b>='A'&&b<='Z') {
b-='A';
tb=;
}
if(b>='a'&&b<='z') b-='a';
if(ta&&tb) return false;
if(ta==false && tb==false) return false;
return a==b;
}
void solve(int s) {
//printf("%d %d\n",s,e);
e++;
if(e>=n) return;
while(e<n&&!eq(data[s],data[e])) {
solve(e);
}
if(e>=n) return;
Next[s]=e;
Next[e]=s;
e++;
}
int main() {
scanf("%d",&n);
scanf("%s",data);
n*=;
memset(Next,-,sizeof(Next));
e=;
while(e<=n) solve(e);
for(int i=;i<n;i++) {
//printf("%d ",Next[i]);
if(Next[i]==-) {
puts("Impossible");
return ;
}
}
//puts("");
int gid[*],g=;
for(int i=;i<n;i++) {
if(data[i]>='a'&&data[i]<='z') {
gid[i] = g++;
}
}
for(int i=;i<n;i++) {
if(data[i]>='A'&&data[i]<='Z') {
printf("%d ",gid[Next[i]]);
}
}
puts("");
}

URAL 2019 Pair: normal and paranormal (贪心) -GDUT联合第七场的更多相关文章

  1. ural 2019 Pair: normal and paranormal

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

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

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

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

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

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

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

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

  6. Gym 100507H - Pair: normal and paranormal

    题目链接:http://codeforces.com/gym/100507/attachments -------------------------------------------------- ...

  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. Governing sand(主席树/贪心)(2019牛客暑期多校训练营(第七场))

    示例:输入:25 1 11 10 125 1 23 2 3输出:12 题意:n种树,第i种树有P[i]颗,砍掉每颗树的代价是C[i], 高度是H[i].需要用最小的花费砍掉一些树,让最高的树超过一半. ...

  9. Pair(二进制处理+数位dp)(2019牛客暑期多校训练营(第七场))

    示例: 输入: 33 4 24 5 27 8 5 输出:5 7 31 题意:存在多少对<x,y>满足x&y>C或x^y<C的条件.(0<x<=A,0< ...

随机推荐

  1. express 框架之 路由与中间件

    1.  什么是router路径,什么是middleware? 我们输入www.baidu.com 来访问百度的主页,浏览器会自动转换为 http://www.baidu.com:80/(省略一些参数) ...

  2. 利用UIActivityController调用ios系统自带的分享功能,实现微信发布多图的功能

    通过一番查找以后找到一个类UIActivityController,可以调用系统的social.framework中的分享接口.看下面的图就知道了,这个还是挺常见的 微信发布多图 借鉴了CSDN上的一 ...

  3. window8.1使用之快捷键

    WIN键+? Win键——打开“开始”屏幕 Win+D——显示桌面 Win+E——打开计算机 Win+R——打开“运行”对话框 Win+L——锁定计算机 Win+M——最小化窗口 Win+方向键——窗 ...

  4. iframe 内联框架

    Iframe - 设置高度和宽度 height 和 width 属性用于规定 iframe 的高度和宽度. 属性值的默认单位是像素,但也可以用百分比来设定(比如 "80%"). 实 ...

  5. Mac Pro 开机自启动 PHP-FPM,Nginx,MySql 等软件

    在Mac下安装好了PHP开发环境(PHP-FPM,Nginx,MySql), 想设置成开机自启动,原来以为和一般的Linux系统一样,也是在rc.d这样目录放置启动脚本.在网上查了一些资料,发现苹果应 ...

  6. Android-Universal-Image-Loader 图片异步加载类库的使用(超详细配置)

    这个图片异步加载并缓存的类已经被很多开发者所使用,是最常用的几个开源库之一,主流的应用,随便反编译几个火的项目,都可以见到它的身影. 可是有的人并不知道如何去使用这库如何进行配置,网上查到的信息对于刚 ...

  7. webpack的最简单应用,只使用js与css的打包

    首先进行全局安装webpack npm install -g webpack cmd跳转到项目的文件夹,安装webpack npm install --save-dev webpack 接着需要pac ...

  8. java File delete()执行失败原因

    java.io.File里的delete操作很实用也很常用,可以用来删除单独的文件和某一目录.但有时候会出现delete失败的情况,出现这种情况的原因一般有以下几种: 1.删除时还有其他程序在使用该文 ...

  9. PHP--获取响应头(Response Header)方法

    方法一: $baiduUrl = "http://www.baidu.com/link";   file_get_contents($baiduUrl); $responseInf ...

  10. pycharm3.4 下svn 项目checkout&配置

    pycharm 社区版: 3.4 1. checkout 项目 注意,之前配置好:设置里面的一些配置:(以下勾勾不要勾上) 2. checkout 项目之后,做以下操作: vcs ->enabl ...