#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 ;
}

最新文章

  1. .Net 转战 Android 4.4 日常笔记(4)--按钮事件和国际化
  2. PL/SQL导出到execl中,数据前面的0发生丢失的解决办法
  3. java中是否会存在内存泄漏
  4. Webform——中国省市三级联动以及IsPostBack
  5. Linq之Lambda表达式
  6. 用命令访问D:\python学习\wendjia教程\aa.py
  7. linux工程管理工具make入门
  8. js中跨域请求原理及2种常见解决方案
  9. 关于VS 2010 RDLC 报表的详细使用说明
  10. SE 2014 年4月21日(一)
  11. 《JavaScript高级程序设计》读书笔记 ---Array 类型
  12. Spring学习笔记(二)之装配Bean
  13. alibaba/druid 下的 密码加密
  14. tornado 初解
  15. react-native中的动画
  16. C#循环语句整理
  17. .Net转Java.01.从Main(main)函数说起
  18. springboot启动配置原理之一(创建SpringApplication对象)
  19. MySQL 性能管理及架构设计指南
  20. jdbc --- javabean

热门文章

  1. imagemap的推荐使用方法,前端自适应image maps库
  2. Struts action
  3. 解决 eclipse出现 Address already in use: bind
  4. RobotFramework教程使用笔记——web自动化测试弹窗处理
  5. BZOJ 1623 [Usaco2008 Open]Cow Cars 奶牛飞车:贪心
  6. windows 下python搭建环境
  7. bzoj3669【NOI2014】魔法森林
  8. 搜索算法 pots
  9. UVA-10534 (LIS)
  10. luogu 3812 【模板】 线性基