【贪心】Gym - 100507H - Pair: normal and paranormal
每次取相邻的两个可以射击的从序列中删除,重复n次。
可以看作括号序列的匹配。
#include<cstdio>
#include<vector>
using namespace std;
struct data
{
char c;
int p;
data(){}
data(const char &cc,const int &pp)
{
c=cc;
p=pp;
}
};
vector<data>a;
typedef vector<data>::iterator ITER;
int n,shoot[5010];
char s[10010];
int main()
{
//freopen("h.in","r",stdin);
int p1=0,p2=0;
scanf("%d%s",&n,s);
for(int i=0;i<n*2;++i)
{
if(s[i]>='A' && s[i]<='Z')
{
++p1;
a.push_back(data(s[i],p1));
}
else
{
++p2;
a.push_back(data(s[i],p2));
}
}
for(int i=0;i<n;++i)
{
bool flag=0;
ITER k=a.begin(); ++k;
for(ITER j=a.begin();k!=a.end();++j,++k)
if((*j).c==(*k).c-32)
{
shoot[(*j).p]=(*k).p;
++k;
a.erase(j,k);
flag=1;
break;
}
else if((*j).c-32==(*k).c)
{
shoot[(*k).p]=(*j).p;
++k;
a.erase(j,k);
flag=1;
break;
}
if(!flag)
{
puts("Impossible");
return 0;
}
}
for(int i=1;i<n;++i)
printf("%d ",shoot[i]);
printf("%d\n",shoot[n]);
return 0;
}
【贪心】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
题目链接:http://codeforces.com/gym/100507/attachments -------------------------------------------------- ...
- 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 (贪心) -GDUT联合第七场
比赛题目链接 题意:有n个人每人拿着一把枪想要杀死n个怪兽,大写字母代表人,小写字母代表怪兽.A只能杀死a,B只能杀死b,如题目中的图所示,枪的弹道不能交叉.人和怪兽的编号分别是1到n,问是否存在能全 ...
- URAL 2019 Pair: normal and paranormal (STL栈)
题意:在一个半圆内,有2*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个大写字母和 ...
- 贪心 Gym 100502E Opening Ceremony
题目传送门 /* 题意:有一堆砖块,每一次操作可以选择消去任意一行,也可以选择消去任意一列.求要消去所有的砖块需要最小的操作数 贪心:首先清楚的是消去最高列的最佳,消去第一行最佳,行列的顺序只对中间过 ...
- NEERC 2014, Eastern subregional contest
最近做的一场比赛,把自己负责过的题目记一下好了. Problem B URAL 2013 Neither shaken nor stirred 题意:一个有向图,每个结点一个非负值,可以转移到其他结点 ...
随机推荐
- Google File System中文版
英文原文地址: Google File system 译文原文地址: The Google File System中文版 Google File System中文版 摘要 我们设计并实现了Google ...
- -webkit-overflow-scrolling:touch;
-webkit-overflow-scrolling建了带有硬件加速的系统级控件,所以效率很高.但是这相对是耗更多内存的,最好在产生了非常大面积的overflow时才应用. 而且在 ios8 里有b ...
- jquery 的相关 width 和 height 方法辨析
width() 设置或返回元素的宽度(不包括内边距.边框或外边距). height() 设置或返回元素的高度(不包括内边距.边框或外边距). innerWidth() 返回元素的宽度(包括内边距). ...
- JS遮罩层弹框效果
对于前端开发者来说,js是不可缺少的语言.现在我开始把我日常积累的一些js效果或者通过搜索自己总结的一些效果分享给大家,希望能够帮助大家一起进步,也希望大家能够多多支持! 1.今天我先分享一个遮罩层弹 ...
- linux基础(2)
Linux基础题 作业一:1) 新建用户natasha,uid为1000,gid为555,备注信息为“master”useradd natashagroupmod -g 555 natashauser ...
- 无线路由器中WMM/Short GI/AP隔离各是什么功能, 开启时PC无法ping通手机.
无线路由器的WMM功能和开启ap隔离,以及开启ShortGI有什么用 无线路由器中有开启WMM.开启Short GI和开启AP隔离分别代表什么呢?这是我在我的TP-LINK无线路由器TL-WR84 ...
- android 调试 native 程序的方法
一.背景 首先说需求,这个需求非常常见,就是android上需要的一个功能,linux已经有开源代码而且非常稳定,希望能直接porting过去使用,这个程序是pure c 的代码,也就是说,跟andr ...
- Linux下进程描述(1)—进程控制块【转】
转自:http://www.cnblogs.com/33debug/p/6705391.html 进程概念介绍 进程是操作系统对运行程序的一种抽象. • 一个正在执行的程序: • 一个正在计算机上执行 ...
- Backbone Collection 源码简谈
一切由一个例子引发: var Man=Backbone.Model.extend({ initilize:function(){ this.bind('change:name',function(){ ...
- 数据类型转换,JS操作HTML
数据类型转换 1.自动转换(在某种运算环境下) Number环境 String环境 Boolean环境 2.强制类型转换 Number() 字符串:纯数字和空字符转为正常数字,其他NaN 布尔值:tu ...