HDU6299(2018多校第一场)
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多校第一场)的更多相关文章
- Time Zone 【模拟时区转换】(HDU暑假2018多校第一场)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6308 Time Zone Time Limit: 2000/1000 MS (Java/Others) ...
- 【2018多校第一场】hdu6308-Time Zone(日期)
Problem Description Chiaki often participates in international competitive programming contests. The ...
- HDU6300(2018多校第一场)
Bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6300 排个序就好了 #include<iostream> #include& ...
- HDU6301(2018多校第一场)
Bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6301 队友AC的,没怎么看 #include<iostream> #incl ...
- HDU6308(2018多校第一场)
Bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6308 将时间化简为分钟计算,同时不要用浮点数计算,精度会出现问题: 如果采用精度,最好加 ...
- HDU6298(2018多校第一场)
Bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6298 打表找规律: #include<bits/stdc++.h> usin ...
- 2019牛客多校第一场 I Points Division(动态规划+线段树)
2019牛客多校第一场 I Points Division(动态规划+线段树) 传送门:https://ac.nowcoder.com/acm/contest/881/I 题意: 给你n个点,每个点有 ...
- 牛客多校第一场 B Inergratiion
牛客多校第一场 B Inergratiion 传送门:https://ac.nowcoder.com/acm/contest/881/B 题意: 给你一个 [求值为多少 题解: 根据线代的知识 我们可 ...
- HDU6581 Vacation (HDU2019多校第一场1004)
HDU6581 Vacation (HDU2019多校第一场1004) 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6581 题意: 给你n+1辆汽车, ...
随机推荐
- RightScale发布2017年度云调查报告
RightScale最近发布了他们的年度云报告(RightScale 2017云现状报告,RightScale 2017 State of the Cloud Report),这份报告包括了云计算在采 ...
- JavaScript Objects in Detail
JavaScript’s core—most often used and most fundamental—data type is the Object data type. JavaScript ...
- maven中常用命令
1. 更新本地仓库, 首先确认C:\users\pengqiong\ 路径下有相应的pom文件 mvn clean package install:
- Sports
题目链接 : http://acm.hpu.edu.cn/problem.php?id=1184 或者 http://acm.nyist.net/JudgeOnline/problem.p ...
- 51nod1060:最复杂的数(DFS求反素数)
把一个数的约数个数定义为该数的复杂程度,给出一个n,求1-n中复杂程度最高的那个数. 例如:12的约数为:1 2 3 4 6 12,共6个数,所以12的复杂程度是6.如果有多个数复杂度相等,输出最 ...
- C++可移植性和跨平台初探
概述 今天聊聊C++的可移植性问题.如果你平时使用C++进行开发,并且你对C++的可移植性问题不是非常清楚,那么我建议你看看这个系列.即使你目前没有跨平台开发的需要,了解可移植性方面的知识对你还是很有 ...
- JavaScript-Tool:jquery.md5.js
ylbtech-JavaScript-Tool:jquery.md5.js 1.返回顶部 1. 引入js后 使用方法:document.write($.md5('1234')); 加密结果:81dc9 ...
- 五 pyJWT使用
PyJWT是一个Python库,用来编码/解码JWT(JSON Web Token)的. 1:安装PyJWT 2: 直接上代码了: import datetime, jwt, time from a ...
- wp8环境搭建
Windows Phone 8将采用与Windows 8相同的NT内核,这就意味着WP8将可能兼容Win8应用,开发者仅需很少改动就能让应用在两个平台上运行.由于内核变更,Windows Phone ...
- 【eclipse插件开发实战】 Eclipse插件开发5——时间插件Timer开发实例详解
Eclipse插件开发5--时间插件Timer开发实例详解 这里做的TimeHelper插件设定为在菜单栏.工具栏提供快捷方式,需要在相应地方设置扩展点,最后弹出窗体显示时间. 在上一篇文章里创建好了 ...