每次取相邻的两个可以射击的从序列中删除,重复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的更多相关文章

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

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

  2. Gym 100507H - Pair: normal and paranormal

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

  3. ural 2019 Pair: normal and paranormal

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

  4. URAL 2019 Pair: normal and paranormal (贪心) -GDUT联合第七场

    比赛题目链接 题意:有n个人每人拿着一把枪想要杀死n个怪兽,大写字母代表人,小写字母代表怪兽.A只能杀死a,B只能杀死b,如题目中的图所示,枪的弹道不能交叉.人和怪兽的编号分别是1到n,问是否存在能全 ...

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

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

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

  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. 贪心 Gym 100502E Opening Ceremony

    题目传送门 /* 题意:有一堆砖块,每一次操作可以选择消去任意一行,也可以选择消去任意一列.求要消去所有的砖块需要最小的操作数 贪心:首先清楚的是消去最高列的最佳,消去第一行最佳,行列的顺序只对中间过 ...

  9. NEERC 2014, Eastern subregional contest

    最近做的一场比赛,把自己负责过的题目记一下好了. Problem B URAL 2013 Neither shaken nor stirred 题意:一个有向图,每个结点一个非负值,可以转移到其他结点 ...

随机推荐

  1. MySQL使用笔记(四)数据的操作

    By francis_hao    Dec 14,2016 数据的操作包括插入数据记录.更新数据记录和删除数据记录. 插入数据记录 插入单条数据记录 field表示的字段名和value表示数据要一一对 ...

  2. 使用XTU降低CPU功耗,自动执行不失效

    INTEL出品的XTU可以用来做软超频操作,给CPU/GPU加电压超频,也可以通过降低CPU/GPU电压来减少功耗. 以前用XTU设置好了之后,过一段时间就自动失效了,最近失效的频率突然很高,于是找了 ...

  3. JAVA中string.replace()和string.replaceAll()的区别及用法

    乍一看,字面上理解好像replace只替换第一个出现的字符(受javascript的影响),replaceall替换所有的字符,其实大不然,只是替换的用途不一样.    public String r ...

  4. 记录一发wm_concat()函数排序的问题

    需求:需要将列转行之后的工序按照待执行工序号排序,如果一样按工序号排 解决方法如下: select part_no, max(ywggx) ywggx from(select mt.part_no , ...

  5. Eclipse CDT 调用printf/cout 控制台(console)无输出

    转摘自:http://blog.csdn.net/dj0379/article/details/6940836 症状描述: 用Eclipse调试程序,执行printf和cout函数,但是console ...

  6. JS学习笔记之页面信息滚动效果

    效果截图: 1.无缝滚动效果 JS代码: <script> window.onload=function(){ var oInfobox=document.getElementById(' ...

  7. Nginx各项配置的含义

    #user nobody; #配置用户或者组,默认为nobody nobody worker_processes 4; #允许生成的进程数,默认为1 worker_cpu_affinity 00000 ...

  8. ()()()()x()=()()()()填1-9数字

    /** Function: ()()()()x()=()()()() Developer: Date: */ #include "iostream" #include " ...

  9. [洛谷P1541] 乌龟棋

    洛谷题目链接:乌龟棋 题目背景 小明过生日的时候,爸爸送给他一副乌龟棋当作礼物. 题目描述 乌龟棋的棋盘是一行N个格子,每个格子上一个分数(非负整数).棋盘第1格是唯一的起点,第N格是终点,游戏要求玩 ...

  10. 【EOJ3654】管理孩子(贪心,二分)

    题意:有一棵n个点的树,其中有k个是关键点,将树分割成若干部分,每部分至少包含一个关键点,求最大分割大小的最小值 思路: 最后特判一下f[1]的值 #include<cstdio> #in ...