每次取相邻的两个可以射击的从序列中删除,重复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. BZOJ1798 维护序列seq

    1798: [Ahoi2009]Seq 维护序列seq Time Limit: 30 Sec  Memory Limit: 64 MBSubmit: 8058  Solved: 2964[Submit ...

  2. ambari server内存溢出

    抛出的异常信息如下: java.lang.OutOfMemoryError: PermGen space at java.lang.ClassLoader.defineClass1(Native Me ...

  3. [Book Content]Python进阶

    python进阶 原书内容https://github.com/eastlakeside/interpy-zh 通过记录书本目录和大概内容做一个记录,方便以后回顾检索. Chapter Title B ...

  4. python实现后台系统的JWT认证

    介绍一种适用于restful+json的API认证方法,这个方法是基于jwt,并且加入了一些从oauth2.0借鉴的改良. 1. 常见的几种实现认证的方法 首先要明白,认证和鉴权是不同的.认证是判定用 ...

  5. WebView使用--文章集锦

    对于android WebView加载不出Html5网页的解决方法 在android4.4中webview的使用相对于之前版本的一些区别 理解WebKit和Chromium: Android 4.4 ...

  6. 动态规划:LCS

    先上状态转移方程,还是很容易看明白的 例题是Codevs的1862,这个题不是实现了方程就可以了的,还要完成一个事情那就是计数,数一数到底有多少个最长公共子序列 #include<cstdio& ...

  7. [POJ1637]混合图的欧拉回路判定|网络流

    混合图的欧拉回路判定 上一篇正好分别讲了有向图和无向图的欧拉回路判定方法 如果遇上了混合图要怎么做呢? 首先我们思考有向图的判定方法:所有点的出度=入度 我们可以先为无向边任意定一个向,算出此时所有顶 ...

  8. 【BZOJ】1725: [Usaco2006 Nov]Corn Fields牧场的安排

    [算法]状压DP [题解]对于上一行的每个状态,每行进行DFS. #include<cstdio> #include<algorithm> #include<cstrin ...

  9. 【Luogu P3834】可持久化数组(可持久化线段树)

    题目链接 可持久化线段树模板题. 这里总结一下可持久化线段树. 可持久化数据结构就是能恢复历史状态的数据结构,比如可持久化\(Trie\),并查集,平衡树. 可持久化数组是最基础的,这里通过可持久化线 ...

  10. iOS推送原理和证书生成简介

    1. 推送流程: Provider: 我们自己的后台服务器: APNS: 苹果的消息推送服务器 (1) 当Provider有消息要推送给手机的时候,先将消息和deviceToken等字段发送到APNS ...