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. java to Json or Json to JavaBean

    今天练习,放这里,以后再补充 这里使用的jar包是 net.sf.json.JSONObject package yh.test.t1118; import net.sf.json.JSONArray ...

  2. input表单元素的默认padding不一致问题

    最近做的项目,发现一堆问题,input type=“text”和type=“button” (1)在无文字的时候高度是一致的,分别写入相同大小的文字type=“button”高度>type=“t ...

  3. Android图片加载神器之Fresco, 基于各种使用场景的讲解

    Fresco是Facebook开源Android平台上一个强大的图片加载库,也是迄今为止Android平台上最强大的图片加载库. 优点:相对于其他开源的第三方图片加载库,Fresco拥有更好的内存管理 ...

  4. 关于“C++语言程序设计”书的一个类

    class book{    char* title;    int num_pages;    int cur_page;public:    book(const char* theTitle, ...

  5. 数组(Array)的初始化

    如果这样: private static int unsorted[]; for(int i = 1 ; i < 8 ; i ++ ) unsorted[i] = 1 ; 是会报NullPoin ...

  6. Git 常用命令学习

    本文转载自:https://buptldy.github.io/2016/03/02/2016-03-02-Git%20Cheat%20Sheet/ 文章 创建版本库 初始化一个Git仓库,使用git ...

  7. java并发之阻塞队列LinkedBlockingQueue与ArrayBlockingQueue

    Java中阻塞队列接口BlockingQueue继承自Queue接口,并提供put.take阻塞方法.两个主要的阻塞类实现是ArrayBlockingQueue和LinkedBlockingQueue ...

  8. web集群时代

    随着业务的不断增加,我们的单台服务器承受不住需求,那么我们就需要对此进行伸缩,有两种维度,一种是纵向的也就是增大该台服务器的硬件,再者就是加新服务器与之前的机器组成集群对外提供服务,我们都知道前者是有 ...

  9. keil5中文乱码的解决

    keil5 复制出来的中文显示乱码,该如何解决? 点击Edit - Configuration ,进入编辑器设置: 点击ok ,就可以了

  10. C# ActiveX 中static变量缓存的问题

    最近在忙活一个绘图程序,按照要求需要以ActiveX的方式发布在网站中,这个绘图程序的大概功能就是从数据库获取数据,成图.发布后用户反映,数据变化后,图形没有发生变化,好像有缓存,如果把浏览器全部关闭 ...