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. unity3D写一个hello world

    unity3D写一个hello world 打开unity并且在assets建立一个新的文件,新的文件命名为hello world.unity.接着创建一个新的C#Sript脚本文件,命名为hello ...

  2. String StringBuffer StringBuilder 之间的区别

    StringBuffer与StringBuilder的区别: StringBuffer是jdk1.0版本出来的,线程安全,效率低 StringBuilder是jdk1.5版本出来的,线程不安全,效率高 ...

  3. GCD之信号量机制二

    在前面GCD之信号量机制一中介绍了通过信号量设置并行最大线程数,依此信号量还可以防止多线程访问公有变量时数据有误,下面的代码能说明. 1.下面是不采用信号量修改公有变量的值 1 2 3 4 5 6 7 ...

  4. 插入排序-python实现

    def insert_sort(arr): for j in range(1,len(arr)):               #从list第二个元素开始 key=arr[j]             ...

  5. Spring 3.x 读书笔记

    第一:如果使用BeanFactory作为Spring Bean的工厂类,则所有的bean都是在第一次使用该Bean的时候实例化 第二:如果使用ApplicationContext作为Spring Be ...

  6. [js高手之路] html5 canvas系列教程 - 线形渐变,径向渐变与阴影设置

    接着上文[js高手之路] html5 canvas系列教程 - 像素操作(反色,黑白,亮度,复古,蒙版,透明)继续. 一.线形渐变 线形渐变指的是一条直线上发生的渐变. 用法: var linear ...

  7. hdu3695 ac自动机入门

    Computer Virus on Planet Pandora Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 256000/1280 ...

  8. NOIP2017SummerTraining0706

    个人感受:这套题也依旧在划水,和wqh在一起,然后也没怎么好好想,第一题开始时打了个思维很好的方法,但是事完全错误的:然后就开始第二题,然后第二题枚举20分,然后看答案多了25分,就拿了 45分:第三 ...

  9. ZOJ2345Gold Coins 简单分块

    昨天做过一样的题: 平方和公式:n*(n+1)*(2n+1) #include<cstdio> #include<cstdlib> #include<iostream&g ...

  10. Xadmin集成富文本编辑器ueditor

    在xadmin中通过自定义插件,实现富文本编辑器,效果如下: 1.首先,pip安装ueditor的Django版本: pip install DjangoUeditor 2.之后需要添加到项目的set ...