Bryce1010模板

http://acm.hdu.edu.cn/showproblem.php?pid=6299

两个字符串的排序可以分成四种情况:

(1)str1左少右多 vs str2 左多右少

str2排在str1前面

(2)str1 左多右少 vs str2 左少右多

str1排在str2前面

(3)str1 左少右多 vs str2 左少右多

按左括号的数量排序

(4)其他情况按右括号的数量排

 if(l<=r&&s.l>s.r)//左少右多  vs  左多右少
{
return false;
}
if(l>r&&s.l<=s.r)//左多右少 vs 左少右多
{
return true;
}
if(r>=l&&s.r>=s.l)//左少右多 vs 左少右多
{
return l>s.l;
}
return r<s.r;

最后用一个if维护左括号的数量,不断更新对应右括号的最大值(从dls的代码学到的)

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN=1e5+10; struct Str
{
int l,r,add;
bool operator < (const Str& s)const
{
if(l<=r&&s.l>s.r)//左少右多 vs 左多右少
{
return false;
}
if(l>r&&s.l<=s.r)//左多右少 vs 左少右多
{
return true;
}
if(r>=l&&s.r>=s.l)//左少右多 vs 左少右多
{
return l>s.l;
}
return r<s.r;
}
}str[MAXN];
char s[MAXN];
int main()
{
//freopen("in.txt","r",stdin);
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%s",s);
str[i].l=str[i].r=str[i].add=0;
int len=strlen(s);
//count括号
for(int j=0;j<len;j++)
{
if(s[j]=='(')
str[i].l++;
else
{
if(str[i].l>0)
str[i].l--,str[i].add++;
else
str[i].r++;
}
} }
sort(str+1,str+1+n);
int ans=0;
int now=0;
for(int i=1;i<=n;i++)
{
if(str[i].r>now)
{
str[i].r=now;
}
ans+=str[i].r+str[i].add;
now-=str[i].r;
now+=str[i].l;
}
cout<<ans*2<<endl;
}
}

HDU6299(2018多校第一场)的更多相关文章

  1. Time Zone 【模拟时区转换】(HDU暑假2018多校第一场)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6308 Time Zone Time Limit: 2000/1000 MS (Java/Others)  ...

  2. 【2018多校第一场】hdu6308-Time Zone(日期)

    Problem Description Chiaki often participates in international competitive programming contests. The ...

  3. HDU6300(2018多校第一场)

    Bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6300 排个序就好了 #include<iostream> #include& ...

  4. HDU6301(2018多校第一场)

    Bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6301 队友AC的,没怎么看 #include<iostream> #incl ...

  5. HDU6308(2018多校第一场)

    Bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6308 将时间化简为分钟计算,同时不要用浮点数计算,精度会出现问题: 如果采用精度,最好加 ...

  6. HDU6298(2018多校第一场)

    Bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6298 打表找规律: #include<bits/stdc++.h> usin ...

  7. 2019牛客多校第一场 I Points Division(动态规划+线段树)

    2019牛客多校第一场 I Points Division(动态规划+线段树) 传送门:https://ac.nowcoder.com/acm/contest/881/I 题意: 给你n个点,每个点有 ...

  8. 牛客多校第一场 B Inergratiion

    牛客多校第一场 B Inergratiion 传送门:https://ac.nowcoder.com/acm/contest/881/B 题意: 给你一个 [求值为多少 题解: 根据线代的知识 我们可 ...

  9. HDU6581 Vacation (HDU2019多校第一场1004)

    HDU6581 Vacation (HDU2019多校第一场1004) 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6581 题意: 给你n+1辆汽车, ...

随机推荐

  1. 【USACO OPEN 10】hop

    奶牛们正在回味童年,玩一个类似跳格子的游戏,在这个游戏里,奶牛们在草地上画了一行N个格子,(3 <=N <= 250,000),编号为1..N. 就像任何一个好游戏一样,这样的跳格子游戏也 ...

  2. CodeChef Forest Gathering —— 二分

    题目链接:https://vjudge.net/problem/CodeChef-FORESTGA 题解: 现场赛.拿到这题很快就知道是二分,但是一直wa,怎么修改也wa,后来又换了种错误的思路,最后 ...

  3. Codeforces Beta Round #96 (Div. 1) C. Logo Turtle —— DP

    题目链接:http://codeforces.com/contest/132/problem/C C. Logo Turtle time limit per test 2 seconds memory ...

  4. SystemV和BSD的区别

    目前,Unix操作系统不管其内核如何,其操作风格上主要分为SystemV(目前一般采用其第4个版本SVR4)和BSD两种.其代表操作系统本别是Solaris和FreeBSD.当然,在SunOS4(So ...

  5. __FILE__,__LINE__,__func__ 真好用,DEBUG利器啊!

    我是不喜欢用类似VC下的F5,F10.曾经很喜欢用.被代码逻辑逼的没招了.所以不喜欢用了. 比如,错误是根据动态数据,产生的行为错误,无论是该写的未写,还是不该写的写了.指针跑飞什么等等,无非就是上述 ...

  6. win7下使用source insight,没有Courier字体

    http://hi.baidu.com/raoxj/item/0e3a3a3b2461c5be134b14fa 1. “控制面板:--->“字体”--->找到Courier New(建议用 ...

  7. Swing项目编译成exe,并且打包成安装文件(一)

    我们一般用java做Swing项目的时候一般都是只能在Myeclipse里面运行,那么怎么把我们的项目打包成exe可以直接双击运行呢? 初始工作:为了不让用户安装java环境,所以我们先新建一个文件夹 ...

  8. 「USACO16OPEN」「LuoguP3146」248(区间dp

    题目描述 Bessie likes downloading games to play on her cell phone, even though she doesfind the small to ...

  9. DIY一个DNS查询器:程序实现

    上一篇文章<DIY一个DNS查询器:了解DNS协议>中讲了DNS查询协议的原理和数据结构.经过两个星期的开发,完成了该查询器的编写.期间也遇到了一些问题,如: 1资源记录(Resource ...

  10. kafka之五:如何手动更新Kafka中某个Topic的偏移量

    本文介绍如何手动跟新zookeeper中的偏移量.我们在使用kafka的过程中,有时候需要通过修改偏移量来进行重新消费.我们都知道offsets是记录在zookeeper中的,所以我们想修改offse ...