URAL 2019 Pair: normal and paranormal (贪心) -GDUT联合第七场
题意:有n个人每人拿着一把枪想要杀死n个怪兽,大写字母代表人,小写字母代表怪兽。A只能杀死a,B只能杀死b,如题目中的图所示,枪的弹道不能交叉。人和怪兽的编号分别是1到n,问是否存在能全部杀死的情况,如果存在则输出编号1到n的每个人杀死的怪兽的编号,如果不能输出"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联合第七场的更多相关文章
- 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个点,其中有大写字母和小写字母.其中你需要连接大写字母到小写字母,其中需要保证这些连接的线段之间没有相交. 如果能够实现,将大写字母对应的小写字母的序号按序输出. 析:我把 ...
- Gym 100507H Pair: normal and paranormal (贪心)
Pair: normal and paranormal 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/H Description ...
- 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 ...
- 【贪心】Gym - 100507H - Pair: normal and paranormal
每次取相邻的两个可以射击的从序列中删除,重复n次. 可以看作括号序列的匹配. #include<cstdio> #include<vector> using namespace ...
- Gym 100507H - Pair: normal and paranormal
题目链接:http://codeforces.com/gym/100507/attachments -------------------------------------------------- ...
- 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个大写字母和 ...
- Governing sand(主席树/贪心)(2019牛客暑期多校训练营(第七场))
示例:输入:25 1 11 10 125 1 23 2 3输出:12 题意:n种树,第i种树有P[i]颗,砍掉每颗树的代价是C[i], 高度是H[i].需要用最小的花费砍掉一些树,让最高的树超过一半. ...
- 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< ...
随机推荐
- UIView不接受触摸事件的三种情况
1.不接收用户交互 userInteractionEnabled = NO 2.隐藏 hidden = YES 3.透明 alpha = 0.0 ~ 0.01 4. 如果子视图的位置超出了父视图的有效 ...
- PHP读取excel文档
PHP读取excel文档 项目需要读取Excel的内容,从百度搜索了下,主要有两个选择,第一个是PHPExcelReader,另外一个是PHPExcel. PHPExcelReader比较轻量级, ...
- cf306 C. Divisibility by Eight(数学推导)
C. Divisibility by Eight time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Ubuntu 14 如何打开 .chm格式文档?
好多手册是.chm格式,Ubuntu是需要安装第三方软件才能打开.chm格式文档,操作方式如下: 到“软件中心” -> 搜索“xchm”,并安装 -> 右键某个.chm文档,选择“属性” ...
- CentOS 6.5 3.0.4安装agentd
更改主机名为test3 [root@localhost ~]# cat /etc/sysconfig/network NETWORKING=yes HOSTNAME=test3 关闭selinux [ ...
- HDu1003(maxn sum)
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABBcAAAMDCAYAAAD5XP0yAAAgAElEQVR4nOy97a8c133n2X+H3xjIC4
- HDU 4939 Stupid Tower Defense(dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4939 解题报告:一条长度为n的线路,路上的每个单元格可以部署三种塔来给走在这条路上的敌人造成伤害,第一 ...
- iOS开发——UI进阶篇(十一)应用沙盒,归档,解档,偏好设置,plist存储,NSData,自定义对象归档解档
1.iOS应用数据存储的常用方式XML属性列表(plist)归档Preference(偏好设置)NSKeyedArchiver归档(NSCoding)SQLite3 Core Data 2.应用沙盒每 ...
- js计算24点
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Ubuntu下编译安装OpenCV 2.4.7并读取摄像头[转]
主要参考: 1.http://www.ozbotz.org/opencv-installation/ 2.http://www.ozbotz.org/opencv-install-troublesho ...