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.

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 1g 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
2
AbBa
2 1
2
AbaB
Impossible
1
Ab
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 <iostream>
#include <stdio.h>
#include <map>
#include <string.h>
#include <vector>
using namespace std;
int n;
int pm[];
int mm[];
int po,ms;
char str[];
bool vis[];
int pos[];
void init(){
po=;
ms=;
memset(vis,false,sizeof vis);
memset(pos,,sizeof pos);
}
int main(){
// freopen("in.txt","r",stdin);
while(scanf("%d",&n)!=EOF){
scanf("%s",str);
init();
for(int i=;i<n*;i++){
if(str[i]>='A'&&str[i]<='Z'){
pm[i]=po++;
}else{
mm[i]=ms++;
}
}
int tmp=n*;
bool F=true;
while(tmp){
bool flag=false;
for(int i=;i<n*;i++){
if(vis[i]) continue;
for(int j=i+;j<n*;j++){
if(vis[j]) continue;
else{
if(str[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-=;
}
break;
}else{
if(str[i]-'a'+'A'==str[j]){
pos[pm[j]]=mm[i];
vis[i]=true;
vis[j]=true;
flag=true;
tmp-=;
}
break;
}
}
}
}
if(flag==false){
F=false;
break;
}
}
if(F==false){
puts("Impossible");
}else{
for(int i=;i<po;i++)
printf(i==?"%d":" %d",pos[i]);
printf("\n");
}
}
return ;
}

H - Pair: normal and paranormal URAL - 2019的更多相关文章

  1. 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个大写字母和 ...

  2. ural 2019 Pair: normal and paranormal

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

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

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

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

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

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

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

  6. 【贪心】Gym - 100507H - Pair: normal and paranormal

    每次取相邻的两个可以射击的从序列中删除,重复n次. 可以看作括号序列的匹配. #include<cstdio> #include<vector> using namespace ...

  7. Gym 100507H - Pair: normal and paranormal

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

  8. 2019牛客多校第七场H Pair 数位DP

    题意:给你一个3个数A, B, C问有多少对pair(i, j),1 <= i <= A, 1 <= j <= B, i AND j > C或 i XOR j < ...

  9. 2019 牛客网 第七场 H pair

     题目链接:https://ac.nowcoder.com/acm/contest/887/H  题意: 给定A,B,C问在[1,A]和[1,B]中有多少对x,y满足x&y>C或者x^y ...

随机推荐

  1. 西邮linux兴趣小组2014纳新免试题(四)

    [第四关] 题目 http://findakey.sinaapp.com/ Example: String1:FFFF8 5080D D0807 9CBFC E4A04 24BC6 6C840 49B ...

  2. pmap 命令详解

    通过查看帮助,返回了如下信息: Usage:  pmap [options] pid [pid ...] Options: -x, --extended              show detai ...

  3. 【JVM命令系列】javap

    命令基本概述 javap是JDK自带的反汇编器,可以查看java编译器为我们生成的字节码.通过它,可以对照源代码和字节码,从而了解很多编译器内部的工作.可以在命令行窗口先用javap -help看下j ...

  4. spring-mvc List及数组的配置接收

    数组接收 前台传递数组id 后台接收方式: public WebReturnObject deleteBatch(@RequestParam("id[]") String[] id ...

  5. Flip Game poj 1753

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 29731   Accepted: 12886 Descr ...

  6. 【模板】AC自动机(加强版)

    题目描述 有个由小写字母组成的模式串以及一个文本串.每个模式串可能会在文本串中出现多次.你需要找出哪些模式串在文本串中出现的次数最多. 输入输出格式 输入格式: 输入含多组数据. 每组数据的第一行为一 ...

  7. [Sdoi2010]星际竞速

    个人对山东省选已经十分无语了,做了三道题,都TM是费用流,这山东省选是要干什么,2009--2011连续三年,只要会费用流,然后建个边,跑一跑就过了. 10 年一度的银河系赛车大赛又要开始了.作为全银 ...

  8. JavaScript设计模式接口

    JavaScript中实现接口的方法有三种: 第一种,使用注释的方法实现接口 特点:(1)最简单,但是功能最弱(2)利用 interface和 implement"文字"(3)把他 ...

  9. Java历程-初学篇 Day05选择结构(2)

    一,switch 由于本作者学的是jdk6.0版本,我知道7.0可以使用字符串,但是我就不改了 语法: switch(char类型/int类型){ case 值: //输出 break; ... de ...

  10. ZOJ-3933-Team Formation【二分图最佳匹配】【KM】

    http://blog.csdn.net/loy_184548/article/details/51154195    一开始对不同组合得不同分数(mm1,mg2,gg3),想用sap来写,但是保证了 ...