HDU 多校对抗赛 B Balanced Sequence
Balanced Sequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1320 Accepted Submission(s): 316
+ if it is the empty string
+ if A and B are balanced, AB is balanced,
+ if A is balanced, (A) is balanced.
Chiaki can reorder the strings and then concatenate them get a new string t. Let f(t) be the length of the longest balanced subsequence (not necessary continuous) of t. Chiaki would like to know the maximum value of f(t) for all possible t.
The first line contains an integer n (1≤n≤105) -- the number of strings.
Each of the next n lines contains a string si (1≤|si|≤105) consisting of `(' and `)'.
It is guaranteed that the sum of all |si| does not exceeds 5×106.
1
)()(()(
2
)
)(
2
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;
const int maxn = 1e5+;
struct node{
int l,r;
}a[maxn];
bool cmp(node a,node b){
if(a.l==b.l) return a.r<b.r;
return a.l<b.l;
}
int ans[maxn];
int vis[maxn];
int main(){
int T;
scanf("%d",&T);
while(T--){
int n,m;
memset(vis,,sizeof(vis));
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++){
scanf("%d%d",&a[i].l,&a[i].r);
}
sort(a+,a+m+,cmp);
priority_queue<int,vector<int>,greater<int> >q;
for(int i=; i<=n; i++){
ans[i]=;vis[i]=;
q.push(i);
}
int l=a[].l,r=a[].l;
for(int i=;i<=m;i++){
for(;l<a[i].l;l++){
if(vis[l]) q.push(ans[l]);
}
for(;r<=a[i].r;r++){
if(r>=a[i].l){
ans[r]=q.top();q.pop();
vis[r]=;
}
}
}
for(int i=; i<=n; i++) {
printf("%d",ans[i]);
if(i==n) printf("\n");
else printf(" ");
}
}
}
HDU 多校对抗赛 B Balanced Sequence的更多相关文章
- HDU 多校对抗赛第二场 1010 Swaps and Inversions
Swaps and Inversions Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU 多校对抗赛第二场 1004 Game
Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- HDU 多校对抗赛 D Distinct Values
Distinct Values Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- HDU 多校对抗赛 C Triangle Partition
Triangle Partition Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Oth ...
- HDU 多校对抗赛 A Maximum Multiple
Maximum Multiple Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 多校对抗赛 J Time Zone
Time Zone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- hdu多校1002 Balanced Sequence
Balanced Sequence Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s) ...
- HDU6299 Balanced Sequence (多校第一场1002) (贪心)
Balanced Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- hdu 6299 Balanced Sequence (贪心)
Balanced Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
随机推荐
- 005---json & pickle
json & pickle 什么是序列化 序列化是指把内存里的数据类型转变成字符串,以便使其能存储在硬盘和网络传输.因为只能接收bytes类型. 为什么要序列化 持久化存储 分类 - json ...
- python2.7入门---Number(数字)
今天咱们来简单分享一下关于python中的一种数据类型和操作方法.费话不多说哈,咱们直接来进行实践加理论.首先,我们要知道,Python Number 数据类型用于存储数.数据类型是不允许改变 ...
- 为WPF中DropShadowBitmapEffect提供轻量级的替代品
原文:为WPF中DropShadowBitmapEffect提供轻量级的替代品 为WPF中DropShadowBitmapEffect提供轻量级的替代品 ...
- 2.PostgreSQL安装详细步骤(windows)【转】
感谢 Junn9527 PostgreSQL安装:一.windows下安装过程安装介质:postgresql-9.1.3-1-windows.exe(46M),安装过程非常简单,过程如下:1.开始安装 ...
- 浅析 Linux 初始化 init 系统,Systemd
原文地址:http://www.ibm.com/developerworks/cn/linux/1407_liuming_init3/ Systemd 的简介和特点 Systemd 是 Linux 系 ...
- Anytime项目开发记录1
关于Android APP 应用设计,我并没有接受过系统的学习. 下面,是按照我一直以来的方法来进行编辑. 由于在程序开始之前并没有画类图,这里简单的讲述一下程序是如何设计的. 自己实现了一个Appl ...
- QSS 的选择器
本文连接地址:http://www.qtdebug.com/QSS-Selector.html 选择器决定了 style sheet 作用于哪些 Widget,QSS 支持 CSS2 定义的所有选择器 ...
- SQL 注入教程
SQL 注入测评教程 1 准备 安装包:Burpsuit.Python27.sqlmap 2 安装配置 2.1 Burpsuit 1) 解压Burpsuit 2) ...
- 分布式一致性算法之Paxos原理剖析
概述 Zookeeper集群中,只有一个节点是leader节点,其它节点都是follower节点(实际上还有observer节点,不参与选举投票,在这里我们先忽略,下同).所有更新操作,必须经过lea ...
- python xlrd处理表格常用方法
1.导入模块import xlrd2.打开Excel文件读取数据data = xlrd.open_workbook('excelFile.xls')3.使用技巧获取一个工作表 table = data ...