hdu 6299 Balanced Sequence( 2018 Multi-University Training Contest 1 )
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull; #define Faster ios::sync_with_stdio(false),cin.tie(0)
#define Read freopen("in.txt", "r", stdin),freopen("out.txt", "w", stdout)
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + ;
const int MOD = 1e9 + ; struct node{
int left, right;
bool operator < (const node& x) const {
if(left <= right && x.right < x.left) return false;
else if(left > right && x.right >= x.left) return true;
if(left <= right && x.right >= x.left) return left > x.left;
else return right < x.right;
}
}a[maxn]; int main()
{
Faster;
int t;
cin >> t;
while(t--){
int n;
cin >> n;
int ans = ;
for(int i = ;i < n;i++){
string s;
cin >> s;
a[i].left = a[i].right = ;
for(int j = ;j < s.size();j++){
if(s[j] == '('){
a[i].left++;
}
else if(s[j] == ')'){
if(a[i].left > ){
a[i].left--;
ans += ;
}
else{
a[i].right++;
}
}
}
}
sort(a, a+n);
int now = ; //记录有多少左括号没有匹配
for(int i = ;i < n;i++){
if(a[i].right > now)
a[i].right = now;
ans += a[i].right*;
now -= a[i].right;
now += a[i].left;
}
cout << ans << endl;
}
return ;
}
hdu 6299 Balanced Sequence( 2018 Multi-University Training Contest 1 )的更多相关文章
- hdu 6299 Balanced Sequence (贪心)
Balanced Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- hdu 6299 Balanced Sequence (括号序列,贪心)
大意: 记$f(t)$表示字符串$t$的最长括号匹配子序列, 给定n个括号序列, 求它们重排后的最大f(t). 首先可以注意到一个括号序列中已经匹配的可以直接消去, 一定不会影响最优解. 那么这样最终 ...
- hdu 6299 Balanced Sequence(贪心)题解
题意:题意一开始不是很明白...就是他给你n个串,让你重新排列组合这n个串(每个串内部顺序不变),使得匹配的括号长度最大.注意,题目要求not necessary continuous,括号匹配不需要 ...
- HDU 6299 Balanced Sequence(贪心)
题目:给出N个只有左右括号字符串 ,这N个字符串的排列顺序是任意的 , 问按最优的排序后 , 得到最多匹配的括号个数 分析: 我们很容易的想到 字符串)()()(( , 这样的字符串可以精简为)(( ...
- HDU 6299.Balanced Sequence-贪心、前缀和排序 (2018 Multi-University Training Contest 1 1002)
HDU6299.Balanced Sequence 这个题就是将括号处理一下,先把串里能匹配上的先计数去掉,然后统计左半边括号的前缀和以及右半边括号的前缀和,然后结构体排序,然后遍历一遍,贪心策略走一 ...
- HDU 6091 - Rikka with Match | 2017 Multi-University Training Contest 5
思路来自 某FXXL 不过复杂度咋算的.. /* HDU 6091 - Rikka with Match [ 树形DP ] | 2017 Multi-University Training Conte ...
- HDU 6125 - Free from square | 2017 Multi-University Training Contest 7
思路来自这里 - - /* HDU 6125 - Free from square [ 分组,状压,DP ] | 2017 Multi-University Training Contest 7 题意 ...
- HDU 6129 - Just do it | 2017 Multi-University Training Contest 7
比赛时脑子一直想着按位卷积... 按题解的思路: /* HDU 6129 - Just do it [ 规律,组合数 ] | 2017 Multi-University Training Contes ...
- HDU 6088 - Rikka with Rock-paper-scissors | 2017 Multi-University Training Contest 5
思路和任意模数FFT模板都来自 这里 看了一晚上那篇<再探快速傅里叶变换>还是懵得不行,可能水平还没到- - 只能先存个模板了,这题单模数NTT跑了5.9s,没敢写三模数NTT,可能姿势太 ...
随机推荐
- vim学习之以退为进——可反复移动和可反复改动的美妙结合
时间:2014.06.29 地点:基地 -------------------------------------------------------------------------------- ...
- win7和win2008 r2下配置IIS7(ASP.net运行环境)
win7和win2008 r2下配置IIS7(ASP.net运行环境) 1.先要设置应用程序池(ApplicationPool)为Classic.NETAppPool,而不是默认的DefaultApp ...
- AndroidContactsTest.java
以下代码使用ContactManager.apk进行测试 package com.saucelabs.appium; import io.appium.java_client.AppiumDriver ...
- jquery特效(7)—弹出遮罩层且内容居中
上周写了几个小特效,其中有个点击按钮弹出遮罩层的特效,下面来看最终实现的效果: 由于是测试的程序,所以我未加关闭的按钮. 一.主体程序 <!DOCTYPE html> <html&g ...
- C++打印变量地址
%p专门用来打印变量的以十六进制表示的地址: #include<iostream> using namespace std; int main() { ; printf("a的地 ...
- 提取html的正文
1 using System; 2 using System.Text; 3 namespace HtmlStrip 4 { 5 class MainClass 6 { 7 ...
- 浏览器端JS导出EXCEL——001
<script src="https://rawgithub.com/eligrey/FileSaver.js/master/FileSaver.js" type=" ...
- liunx环境下安装tomcat
第一:下载tomcat的安装包
- yolo-开源数据集coco kitti voc
1.kitti数据集(参考博客:https://blog.csdn.net/jesse_mx/article/details/65634482 https://blog.csdn.net/baoli ...
- CSS:CSS 单位
ylbtech-CSS:CSS 单位 1.返回顶部 1. 尺寸 单位 描述 % 百分比 in 英寸 cm 厘米 mm 毫米 em 1em 等于当前的字体尺寸. 2em 等于当前字体尺寸的两倍. 例如, ...