比赛题目链接

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

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

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<queue>
  4. using namespace std;
  5. int n,e;
  6. char data[*];
  7. int Next[*];
  8. bool eq(char a,char b) {
  9. bool ta=,tb=;
  10. if(a>='A'&&a<='Z') {
  11. a-='A';
  12. ta=;
  13. }
  14. if(a>='a'&&a<='z') a-='a';
  15. if(b>='A'&&b<='Z') {
  16. b-='A';
  17. tb=;
  18. }
  19. if(b>='a'&&b<='z') b-='a';
  20. if(ta&&tb) return false;
  21. if(ta==false && tb==false) return false;
  22. return a==b;
  23. }
  24. void solve(int s) {
  25. //printf("%d %d\n",s,e);
  26. e++;
  27. if(e>=n) return;
  28. while(e<n&&!eq(data[s],data[e])) {
  29. solve(e);
  30. }
  31. if(e>=n) return;
  32. Next[s]=e;
  33. Next[e]=s;
  34. e++;
  35. }
  36. int main() {
  37. scanf("%d",&n);
  38. scanf("%s",data);
  39. n*=;
  40. memset(Next,-,sizeof(Next));
  41. e=;
  42. while(e<=n) solve(e);
  43. for(int i=;i<n;i++) {
  44. //printf("%d ",Next[i]);
  45. if(Next[i]==-) {
  46. puts("Impossible");
  47. return ;
  48. }
  49. }
  50. //puts("");
  51. int gid[*],g=;
  52. for(int i=;i<n;i++) {
  53. if(data[i]>='a'&&data[i]<='z') {
  54. gid[i] = g++;
  55. }
  56. }
  57. for(int i=;i<n;i++) {
  58. if(data[i]>='A'&&data[i]<='Z') {
  59. printf("%d ",gid[Next[i]]);
  60. }
  61. }
  62. puts("");
  63. }

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. 【C语言入门教程】2.7 表达式

    表达式由运算符.常量及变量构成,C语言的表达式基本遵循一般代数规则.有几种运算法则是 C 语言表达式特有的. 2.7.1 表达式中的类型转换 同一表达式中的不同类型常量及变量在运算时需要变量为同一数据 ...

  2. linux 中断理解

    1.进程.线程只针对的是应用层,而内核调用.驱动没有这种概念,调用的都是内核调用里相同的函数或变量,所以应用层多个应用操作同个硬件时,特别是要加互斥操作,8250通过cs针脚决定发送数据给哪个串口 2 ...

  3. 读w3c中文教程对键盘事件解释的感想 -遁地龙卷风

    写这篇博文源于w3c中文教程对键盘事件的解释, onkeydown 某个键盘按键被按下 onkeypress 某个键盘按键被按下并松开 onkeyup 某个键盘按键被松开 可在实践中发现 只注册key ...

  4. 外国类似stackoverflow这样的网站访问慢怎么解决-遁地龙卷风

    第二版 百度搜索蓝灯 下载桌面版 双击运行 如果打开的浏览器不是你想要的 拷贝地址栏地址给你想要的浏览器 一切就ok了!!!!! 建议不访问国外网站时,便将蓝灯关掉,否则在访问一些不开蓝灯能够正常访问 ...

  5. iOS开发——高级篇——如何集成支付宝SDK

    一.什么是支付宝 第三方支付平台 和内购非常相似内购是用户将钱付款给苹果,之后苹果分成给商户支付宝是用户将钱付款给支付宝,之后支付宝将钱转入我们的账户 使用支付宝前提购买的物品必须是和应用程序无关的. ...

  6. [Asp.net MVC]Asp.net MVC5系列——添加模型

    目录 概述 添加模型 总结 系列文章 [Asp.net MVC]Asp.net MVC5系列——第一个项目 [Asp.net MVC]Asp.net MVC5系列——添加视图 概述 在本节中我们将追加 ...

  7. NSBundle/其他Bundle的获取

    #define D_SharkItOffViewControllerBundleName @"SharkItOffViewController.bundle" //套装名称 //其 ...

  8. 高性能图片服务器–ZIMG

    2011年李彦宏在百度联盟峰会上就提到过互联网的读图时代已经到来1,图片服务早已成为一个互联网应用中占比很大的部分,对图片的处理能力也相应地变成企业和开发者的一项基本技能.需要处理海量图片的典型应用有 ...

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

  10. 【原创】ReFlux细说

    ReFlux细说 Flux作为一种应用架构(application architecture)或是设计模式(pattern),阐述的是单向数据流(a unidirectional data flow) ...