【贪心】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 题意:一个有向图,每个结点一个非负值,可以转移到其他结点 ...
随机推荐
- CSS3边框会动的信封
<!DOCTYPE html><html> <head> <title>酷炫的CSS3</title> <meta charset=& ...
- Android 对Layout_weight属性完全解析以及使用ListView来实现表格
用在linearlayout 如果我们想要按照权重比例来分配LinearLayout,我们需要将其宽度设置为0dip http://blog.csdn.net/xiaanming/article/de ...
- 牛客 国庆七天乐 day1 L
https://www.nowcoder.com/acm/contest/201/L 题意:给你两条平行的直线和n个圆,在直线上面行走和在圆上和在圆内行走不需要耗费体力,除了这些区域外平面上经过任意两 ...
- Bash 实例,第一部分
您可能要问:为什么要学习 Bash 编程?好,以下是几条令人信服的理由: 已经在运行它 如果查看一下,可能会发现:您现在正在运行 bash.因为 bash 是标准 Linux shell,并用于各种目 ...
- JS知识总结
1.javascript继承机制 原型继承,访问对象属性时,如果对象内部有就返回,找不到就会从对象原型指向的对象原型中查找,一层一层的查找,直到最顶层的对象原型还找不到,就返回undefined. 2 ...
- Exceptioninthread"main"java.lang.ClassNotFoundsException的问题
报错如下: Exceptioninthread"main"java.lang.ClassNotFoundsException 大致可以判断出是无法定位到main方法,应该是用mav ...
- 【poj1743-Musical Theme】不可重叠最长重复子串-后缀数组
http://poj.org/problem?id=1743 这题是一道后缀数组的经典例题:求不可重叠最长重复子串. 题意: 有N(1 <= N <=20000)个音符的序列来表示一首乐曲 ...
- Python学习笔记 chapter 2基础
程序输入 >>> print('%s is number %d'%('Python', 1))Python is number 1 输出重定向有问题(待定) 文本输入>> ...
- SSM+Maven的JavaWeb项目中的异常的可能性
1.404 可能:1):被拦截了,即:springmvc中的controller可能不存在,可能没有被配置,可能配置出错 2):资源确实不存在 3):路径出错 2.500,程序异常,但是业务逻辑什么都 ...
- 【C++】各种成员变量
来自:黄邦勇帅 const 常量对象: 即把对象声明为常量,即 const hyong m,常量对象不能调用可能改变对象的值的函数,因此常量对象只能调用类中的 const 常量函数,因为不是 cons ...