H - Pair: normal and paranormal URAL - 2019
Input
Output
Example
input | output |
---|---|
2 |
2 1 |
2 |
Impossible |
1 |
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的更多相关文章
- 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个大写字母和 ...
- ural 2019 Pair: normal and paranormal
2019. Pair: normal and paranormal Time limit: 1.0 secondMemory limit: 64 MB If you find yourself in ...
- Gym 100507H Pair: normal and paranormal (贪心)
Pair: normal and paranormal 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/H Description ...
- URAL 2019 Pair: normal and paranormal (STL栈)
题意:在一个半圆内,有2*n个点,其中有大写字母和小写字母.其中你需要连接大写字母到小写字母,其中需要保证这些连接的线段之间没有相交. 如果能够实现,将大写字母对应的小写字母的序号按序输出. 析:我把 ...
- URAL 2019 Pair: normal and paranormal (贪心) -GDUT联合第七场
比赛题目链接 题意:有n个人每人拿着一把枪想要杀死n个怪兽,大写字母代表人,小写字母代表怪兽.A只能杀死a,B只能杀死b,如题目中的图所示,枪的弹道不能交叉.人和怪兽的编号分别是1到n,问是否存在能全 ...
- 【贪心】Gym - 100507H - Pair: normal and paranormal
每次取相邻的两个可以射击的从序列中删除,重复n次. 可以看作括号序列的匹配. #include<cstdio> #include<vector> using namespace ...
- Gym 100507H - Pair: normal and paranormal
题目链接:http://codeforces.com/gym/100507/attachments -------------------------------------------------- ...
- 2019牛客多校第七场H Pair 数位DP
题意:给你一个3个数A, B, C问有多少对pair(i, j),1 <= i <= A, 1 <= j <= B, i AND j > C或 i XOR j < ...
- 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 ...
随机推荐
- unity3D写一个hello world
unity3D写一个hello world 打开unity并且在assets建立一个新的文件,新的文件命名为hello world.unity.接着创建一个新的C#Sript脚本文件,命名为hello ...
- String StringBuffer StringBuilder 之间的区别
StringBuffer与StringBuilder的区别: StringBuffer是jdk1.0版本出来的,线程安全,效率低 StringBuilder是jdk1.5版本出来的,线程不安全,效率高 ...
- GCD之信号量机制二
在前面GCD之信号量机制一中介绍了通过信号量设置并行最大线程数,依此信号量还可以防止多线程访问公有变量时数据有误,下面的代码能说明. 1.下面是不采用信号量修改公有变量的值 1 2 3 4 5 6 7 ...
- 插入排序-python实现
def insert_sort(arr): for j in range(1,len(arr)): #从list第二个元素开始 key=arr[j] ...
- Spring 3.x 读书笔记
第一:如果使用BeanFactory作为Spring Bean的工厂类,则所有的bean都是在第一次使用该Bean的时候实例化 第二:如果使用ApplicationContext作为Spring Be ...
- [js高手之路] html5 canvas系列教程 - 线形渐变,径向渐变与阴影设置
接着上文[js高手之路] html5 canvas系列教程 - 像素操作(反色,黑白,亮度,复古,蒙版,透明)继续. 一.线形渐变 线形渐变指的是一条直线上发生的渐变. 用法: var linear ...
- hdu3695 ac自动机入门
Computer Virus on Planet Pandora Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 256000/1280 ...
- NOIP2017SummerTraining0706
个人感受:这套题也依旧在划水,和wqh在一起,然后也没怎么好好想,第一题开始时打了个思维很好的方法,但是事完全错误的:然后就开始第二题,然后第二题枚举20分,然后看答案多了25分,就拿了 45分:第三 ...
- ZOJ2345Gold Coins 简单分块
昨天做过一样的题: 平方和公式:n*(n+1)*(2n+1) #include<cstdio> #include<cstdlib> #include<iostream&g ...
- Xadmin集成富文本编辑器ueditor
在xadmin中通过自定义插件,实现富文本编辑器,效果如下: 1.首先,pip安装ueditor的Django版本: pip install DjangoUeditor 2.之后需要添加到项目的set ...