【贪心】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 题意:一个有向图,每个结点一个非负值,可以转移到其他结点 ...
随机推荐
- myisam_sort_buffer_size vs sort_buffer_size
Q: I am MySQL on server with 6GB RAM. I need to know what is the difference between myisam_sort_buff ...
- [codechef MEXDIV]Mex division
题目链接:https://vjudge.net/contest/171650#problem/I 直接用set+dp水过去了... /* 设dp[i]表示前i个做划分满足条件的方案数 有一个显然的转移 ...
- CMDB资产管理系统开发【day26】:02-数据写入待存区
一.资产自动回报数据及个更新流程图 二.表结构注释(NewAssetApprovalZone) class NewAssetApprovalZone(models.Model): "&quo ...
- Virtualization solutions on Linux systems - KVM and VirtualBox
Introduction Virtualization packages are means for users to run various operating systems without &q ...
- spring aop与aspectj
AOP:面向切面编程 简介 AOP解决的问题:将核心业务代码与外围业务(日志记录.权限校验.异常处理.事务控制)代码分离出来,提高模块化,降低代码耦合度,使职责更单一. AOP应用场景: 日志记录.权 ...
- HDU2481 Toy
Time Limit: 16000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission ...
- Cpython解释器支持的进程与线程
一.理论部分 一 什么是进程 进程:正在进行的一个过程或者说一个任务.而负责执行任务则是cpu. 举例(单核+多道,实现多个进程的并发执行): egon在一个时间段内有很多任务要做:python备课的 ...
- isatty
isatty - test whether a file descriptor refers to a terminal #include <stdio.h> #include <u ...
- 关于hrtimer_forward小段代码的分析【转】
转自:http://blog.csdn.net/wowuyinglingluan/article/details/45720151 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?) ...
- Windows下搭建本地SVN服务器【转】
转自:http://www.linuxidc.com/Linux/2015-01/111563.htm 本文介绍Windows下搭建本地SVN服务器的方法,网上资料比较少也比较旧,大都介绍的是旧版本S ...