URAL 2019 Pair: normal and paranormal (STL栈)
题意:在一个半圆内,有2*n个点,其中有大写字母和小写字母。其中你需要连接大写字母到小写字母,其中需要保证这些连接的线段之间没有相交。
如果能够实现,将大写字母对应的小写字母的序号按序输出。
析:我把它看成一个括号序列,然后用栈解决即可。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e16;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} struct Node{
char ch;
int id;
};
map<int, int> mp;
stack<Node> st; int main(){
string s;
cin >> n >> s;
int up = 1, lo = 1;
for(int i = 0; i < s.size(); ++i){
if(st.empty()){
if(islower(s[i])) st.push((Node){s[i], lo++});
else st.push((Node){s[i], up++});
}
else if(islower(s[i])){
if(s[i] == st.top().ch + 32) mp[st.top().id] = lo++, st.pop();
else st.push((Node){s[i], lo++});
}
else{
if(s[i] + 32 == st.top().ch) mp[up++] = st.top().id, st.pop();
else st.push((Node){s[i], up++});
}
}
if(!st.empty()){ puts("Impossible"); return 0; }
for(map<int, int> :: iterator it = mp.begin(); it != mp.end(); ++it)
if(it == mp.begin()) printf("%d", it->second);
else printf(" %d", it->second);
printf("\n");
return 0;
}
URAL 2019 Pair: normal and paranormal (STL栈)的更多相关文章
- 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,问是否存在能全 ...
- Gym 100507H Pair: normal and paranormal (贪心)
Pair: normal and paranormal 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/H Description ...
- 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 100507H - Pair: normal and paranormal
题目链接:http://codeforces.com/gym/100507/attachments -------------------------------------------------- ...
- 【贪心】Gym - 100507H - Pair: normal and paranormal
每次取相邻的两个可以射击的从序列中删除,重复n次. 可以看作括号序列的匹配. #include<cstdio> #include<vector> using namespace ...
- 从零开始写STL—栈和队列
从零开始写STL-栈和队列 适配器模式 意图:将一个类的接口转换成客户希望的另外一个接口.适配器模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作. 主要解决:主要解决在软件系统中,常常要将 ...
- hdu1237 简单计算器[STL 栈]
目录 题目地址 题干 代码和解释 参考 题目地址 hdu1237 题干 代码和解释 解本题时使用了STL 栈,要记得使用#include<stack>. 解本题时使用了isdigit()函 ...
随机推荐
- Luogu-4049 [JSOI2007]合金
题目中给出了三种金属的比例,实际上只用考虑两个就可以,第三个可以由另外两个确定qwq 如果把原料和需求看做二维平面上的点,可以发现两种原料能混合成的比例就在他们相连的线段上,也就是说线段上的点都能混合 ...
- HTML特效文字代码大全
HTML特效文字代码大全一.从右向左移代码<marquee direction=left>需要移动的文字</marquee>二.从左向右移代码<marquee dire ...
- ruanjiangongcheng1
软体工程的方法有很多方面的意义.包括专案管理,分析,设计,程序的编写,测试和质量控制. 软体设计方法可以区别为重量级的方法和轻量级的方法.重量级的方法中产生大量的正式文档. 著名的重量级开发方法包括I ...
- IE6、IE7、IE8及其他浏览器多个元素并排显示
IE6.IE7.IE8及其他浏览器多个元素并排显示 HTML代码 <div class="line"> <h1>全部input框</h1> &l ...
- Centos安装SZRZ方便文件传输
方便Centos服务器传输文件, 要用到szrz命令, 具体安装如下: # wget http://freeware.sgi.com/source/rzsz/rzsz-3.48.tar.gz# ta ...
- 普林斯顿算法(1.3)并查集(union-find算法)——本质就是一个数 下面的子树代表了连在一起的点
转自:https://libhappy.com/2016/03/algs-1.3/ 假设在互联网中有两台计算机需要互相通信,那么该怎么确定它们之间是否已经连接起来还是需要架设新的线路连接这两台计算机. ...
- 1_Command 游戏开发命令模式
A dead simple implementation looks like: ``` // simple void InputHandler::handleInput() { if (isPres ...
- Qt Quick之TableView的使用
本博只是简单的展示TableView的基本使用(TableView.style:TableViewStyle.headerDelegate.rowDelegate.itemDelegate.Table ...
- LeetCode:Add Digits - 非负整数各位相加
1.题目名称 Add Digits (非负整数各位相加) 2.题目地址 https://leetcode.com/problems/add-digits/ 3.题目内容 英文:Given a non- ...
- POJ1041 John's trip
John's trip Language:Default John's trip Time Limit: 1000MS Memory Limit: 65536K Total Submissions: ...