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< ...
随机推荐
- 【C语言入门教程】2.7 表达式
表达式由运算符.常量及变量构成,C语言的表达式基本遵循一般代数规则.有几种运算法则是 C 语言表达式特有的. 2.7.1 表达式中的类型转换 同一表达式中的不同类型常量及变量在运算时需要变量为同一数据 ...
- linux 中断理解
1.进程.线程只针对的是应用层,而内核调用.驱动没有这种概念,调用的都是内核调用里相同的函数或变量,所以应用层多个应用操作同个硬件时,特别是要加互斥操作,8250通过cs针脚决定发送数据给哪个串口 2 ...
- 读w3c中文教程对键盘事件解释的感想 -遁地龙卷风
写这篇博文源于w3c中文教程对键盘事件的解释, onkeydown 某个键盘按键被按下 onkeypress 某个键盘按键被按下并松开 onkeyup 某个键盘按键被松开 可在实践中发现 只注册key ...
- 外国类似stackoverflow这样的网站访问慢怎么解决-遁地龙卷风
第二版 百度搜索蓝灯 下载桌面版 双击运行 如果打开的浏览器不是你想要的 拷贝地址栏地址给你想要的浏览器 一切就ok了!!!!! 建议不访问国外网站时,便将蓝灯关掉,否则在访问一些不开蓝灯能够正常访问 ...
- iOS开发——高级篇——如何集成支付宝SDK
一.什么是支付宝 第三方支付平台 和内购非常相似内购是用户将钱付款给苹果,之后苹果分成给商户支付宝是用户将钱付款给支付宝,之后支付宝将钱转入我们的账户 使用支付宝前提购买的物品必须是和应用程序无关的. ...
- [Asp.net MVC]Asp.net MVC5系列——添加模型
目录 概述 添加模型 总结 系列文章 [Asp.net MVC]Asp.net MVC5系列——第一个项目 [Asp.net MVC]Asp.net MVC5系列——添加视图 概述 在本节中我们将追加 ...
- NSBundle/其他Bundle的获取
#define D_SharkItOffViewControllerBundleName @"SharkItOffViewController.bundle" //套装名称 //其 ...
- 高性能图片服务器–ZIMG
2011年李彦宏在百度联盟峰会上就提到过互联网的读图时代已经到来1,图片服务早已成为一个互联网应用中占比很大的部分,对图片的处理能力也相应地变成企业和开发者的一项基本技能.需要处理海量图片的典型应用有 ...
- Units Problem: How to read text size as custom attr from xml and set it to TextView in java code
Here is this topic’s background: I defined a custom View which extends FrameLayout and contains a Te ...
- 【原创】ReFlux细说
ReFlux细说 Flux作为一种应用架构(application architecture)或是设计模式(pattern),阐述的是单向数据流(a unidirectional data flow) ...