博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
H - Pair: normal and paranormal URAL - 2019
阅读量:5751 次
发布时间:2019-06-18

本文共 3405 字,大约阅读时间需要 11 分钟。

If you find yourself in Nevada at an abandoned nuclear range during Halloween time, you’ll become a witness of an unusual show. Here Ghostbusters hold annual tests for new versions of their proton packs. There are 
n Ghostbusters and 
n portable traps with ghosts, all are located on a semicircle. Each trap contains exactly one ghost. The ghosts may be of different types, but each Ghostbuster can neutralize with his weapon only one type of the evil spirits.
On the count of three all ghost traps open at once and all Ghostbusters start to fire. Of course, each Ghostbuster shoots at the ghost, which his proton gun is able to neutralize. The most important thing here is not to cross proton beams of the guns.

Problem illustration

You know positions of all Ghostbusters and all the traps in this year’s tests. For each Ghostbuster determine which ghost he should shoot at, so that all the ghosts are neutralized and no two gun beams cross. You can assume that all proton beams are in the same horizontal plane and they don’t shoot ghosts through in case of a hit.

Input

In the first line there is an integer 
n that is the number of Ghostbusters (1 ≤ 
n ≤ 5 000). In the second line the sequence of 2 
n Latin letters is written, describing the allocation of the Ghostbusters and the traps on the semicircle. Uppercase letters correspond to the Ghostbusters and lowercase letters correspond to the traps. For example, “a” stands for a trap with the ghost of type “a”, while “A” stands for the Ghostbuster with the gun neutralizing ghosts of type “a”. The sequence has exactly 
n lowercase letters and exactly 
n uppercase letters.

Output

If the problem has a solution, output 
n space-separated integers 
g 
1
g 
2, …, 
g 
n, where 
g 
i is the number of the ghost 
i-th Ghostbuster should shoot at. Both Ghostbusters and ghosts are numbered with integers from 1 to 
n in the order of their positions along the semicircle. All 
g 
i must be pairwise different. If the problem has several solutions, output any of them. If the problem has no solution, output “Impossible”.

Example

input output
2AbBa
2 1
2AbaB
Impossible
1Ab
Impossible

Hint

 

/** @Author: lyuc* @Date:   2017-04-30 17:08:16* @Last Modified by:   lyuc* @Last Modified time: 2017-04-30 18:14:17*//** * 题意:有n个怪兽(小写字母),n个人(大写字母)在一个半圆的底面,如图,A只能杀死a,B只能杀死b *         如果相互的弹道不能交叉,问是否存在全部杀死的情况,如果是输出每个人杀死怪兽的编号,否则 *         输出Impossible * 思路:暴力模拟,一直取相邻的两个元素,如果取到没有相邻的了就输出不可能,否则就输出可能 */#include 
#include
#include
#include
#include
using namespace std;int n;int pm[10005];int mm[10005];int po,ms;char str[10005];bool vis[10005];int pos[10005];void init(){ po=1; ms=1; memset(vis,false,sizeof vis); memset(pos,0,sizeof pos);}int main(){ // freopen("in.txt","r",stdin); while(scanf("%d",&n)!=EOF){ scanf("%s",str); init(); for(int i=0;i
='A'&&str[i]<='Z'){ pm[i]=po++; }else{ mm[i]=ms++; } } int tmp=n*2; bool F=true; while(tmp){ bool flag=false; for(int i=0;i
='A'&&str[i]<='Z'){ if(str[i]-'A'+'a'==str[j]){ pos[pm[i]]=mm[j]; vis[i]=true; vis[j]=true; flag=true; tmp-=2; } break; }else{ if(str[i]-'a'+'A'==str[j]){ pos[pm[j]]=mm[i]; vis[i]=true; vis[j]=true; flag=true; tmp-=2; } break; } } } } if(flag==false){ F=false; break; } } if(F==false){ puts("Impossible"); }else{ for(int i=1;i

 

转载于:https://www.cnblogs.com/wuwangchuxin0924/p/6790012.html

你可能感兴趣的文章
Java集合(二) Map 架构
查看>>
linux 死机分析
查看>>
BOM
查看>>
LeetCode:Nim Game - 尼姆博弈
查看>>
Python装饰器高级版—Python类内定义装饰器并传递self参数
查看>>
Linux解压unzip用法
查看>>
JAXB和XStream比较
查看>>
SVG animation 回顾
查看>>
您无权输入许可证密钥,请请使用系统管理员账户重试
查看>>
在项目中引用android.support.v7
查看>>
Shell 入门笔记(一)
查看>>
Android 使用shape定义不同控件的的颜色、背景色、边框色
查看>>
python re complie 学习记录
查看>>
iOS - xcode - label 字体自动根据宽高 显示完全
查看>>
一个前端的MONGO救赎--5
查看>>
【android】错误集锦及解决办法
查看>>
xmpp即时通讯的笔记(摘抄)
查看>>
VS2010不能正确加载 'VSTS for Database Professionals Sql Server Data-tier Application'的解决方法...
查看>>
【NOIP】提高组2013 货车运输
查看>>
【vijos】P1190 繁忙的都市
查看>>