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辆汽车, ...
随机推荐
- vim编辑makefile时临时不展开tab为空格
可以先敲ctrl-v组合键,再敲tab键,这样就不会被转换成空格了. 给自己的备忘!
- netstat 参数
Netstat用于显示与IP.TCP.UDP和ICMP协议相关的统计数据,一般用于检验本机各端口的网络连接情况. NETSTAT [-a] [-b] [-e] [-n] [-o] [-p proto] ...
- RobotFramework教程使用笔记——初识RobotFramework
1.创建项目 File->New Project 创建测试项目 Type选择Directory 右键项目创建测试套件,也可以理解为创建不同测试逻辑或者是测试业务 右键测试套件创建case 注:如 ...
- complex brain network
Organization, development and function of complex brain networks The Brain as a Complex System: Usin ...
- tensorflow sigmoid_cross_entropy_with_logits 函数解释
tf.nn.sigmoid_cross_entropy_with_logits(_sentinel=None,labels=None, logits=None, name=None) sigmoid_ ...
- webrtc 学习资源 http://www.cnblogs.com/lingyunhu/p/3578218.html
Realtime/Working WebRTC Experiments It is a repository of uniquely experimented WebRTC demos; writte ...
- 「网络流24题」「LuoguP3358」 最长k可重区间集问题(费用流
题目描述 对于给定的开区间集合 I 和正整数 k,计算开区间集合 I 的最长 k可重区间集的长度. 输入输出格式 输入格式: 的第 1 行有 2 个正整数 n和 k,分别表示开区间的个数和开区间的可重 ...
- android 怎么实现跑马灯效果
自定义控件 FocusedTextView, 使android系统误以为它拥有焦点 public class FocusedTextView extends TextView { public Foc ...
- Google 马来西亚主页被黑
互联网并没有想象中安全,Google 马来西亚主页被黑 | TheVerge 消… 查阅全文 ›
- windows下mysql5.1忘记root密码解决方法[win7]
步骤如下:1.停止mysql服务(以管理员身份,在cmd命令行下运行) net stop mysql2.使用 mysqld –skip-grant-tables 命令启动mysql数据库 D:\> ...