18年多校-1002 Balanced Sequence


思路:自己写没写出来,想不通该怎么排序好,看了杜神代码后补题A掉的。重新理解了一下优先队列中重载小于号的含义,这里记录一下这种排序方式。
#include<cstdio>
#include<string>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
struct Node{
int l, r, add;
bool operator <(const Node &b)const{
if (l >= r && b.l < b.r)
return true;
if (l < r && b.l >= b.r)
return false;
if (l >= r && b.l >= b.r)
return r<b.r;
return l > b.l;
}
};
int main()
{
priority_queue<Node>que;
int t; //cin >> t;
scanf("%d", &t);
char temp[];
while (t--){ int n; //cin >> n;
scanf("%d", &n);
getchar(); while (n--){
//string temp; cin >> temp;
gets(temp);
int len = strlen(temp);
int tleft = , tright = , sum = ;
for (int i = ; i < len; i++){
if (temp[i] == '(')
tleft++;
else if (temp[i] == ')'){
if (tleft == )tright++;
else {
tleft--;
sum += ;
}
}
}
Node node;
node.l = tright; node.r = tleft; node.add = sum;
que.push(node);
}
int ans = , now = ;
while (!que.empty()){
Node node = que.top();
que.pop();
if (node.l > now)
node.l = now;
ans += node.add+node.l*;
now -= node.l;
now += node.r;
//cout << node.l << " " << node.r << " " << node.add << endl;
}
//cout << sum << endl;
printf("%d\n", ans);
} return ;
}
18年多校-1002 Balanced Sequence的更多相关文章
- hdu多校1002 Balanced Sequence
Balanced Sequence Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s) ...
- HDU6299 Balanced Sequence (多校第一场1002) (贪心)
Balanced Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 多校对抗赛 B Balanced Sequence
Balanced Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- hdu6299 Balanced Sequence 贪心
题目传送门 题目大意:给出n个字符串,定义了平衡字符串,问这些字符串组合之后,最长的平衡字符子序列的长度. 思路: 首先肯定要把所有字符串先处理成全是不合法的,记录右括号的数量为a,左括号的数量为b, ...
- 2017 多校4 Wavel Sequence
2017 多校4 Wavel Sequence 题意: Formally, he defines a sequence \(a_1,a_2,...,a_n\) as ''wavel'' if and ...
- hdu 6299 Balanced Sequence (贪心)
Balanced Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- Balanced Sequence(毒瘤啊)排序贪心 HDU多校
Problem Description Chiaki has n strings s1,s2,…,sn consisting of '(' and ')'. A string of this type ...
- Balanced Sequence HDU - 6299(杭电多校1 B)
题目说要n个字符串串内随意组合以后将这些串放在一起,然后求最长的括号匹配的长度,并不要求是连续的 因为不需要是连续的,所以可以先把已经匹配好的括号加入到答案里面去,先把这些删掉,以为并不影响结果,然后 ...
- 2018 杭电多校1 - Chiaki Sequence Revisited
题目链接 Problem Description Chiaki is interested in an infinite sequence $$$a_1,a_2,a_3,...,$$$ which i ...
随机推荐
- Spark 多项式逻辑回归__二分类
package Spark_MLlib import org.apache.spark.ml.Pipeline import org.apache.spark.ml.classification.{L ...
- VS快捷键整理
Ctrl+J 自动提示Ctrl+. 解析ctrl+e,d 格式化代码ctrl+e,s 辅助横线Ctrl+m,o 全部合闭Ctrl+m,l 全部打开Ctrl + Shift + space 方法提示调用 ...
- Flask-SQLAlchemy - 不使用外键连表查询。记得常回来看我
前言 相比于 Django 的 ORM ,SQLAlchemy "不依靠外键进行跨表联查" 的解决方案就比较多. 没啥好说的,只能怪自己学艺不精.. _(:з」∠)_ 解决办法 ...
- Beyond Compare 激活解决办法
问题: 当你使用过一段时间后会提示有问题,需要激活或者什么. 解决办法: 找到这个路径并删除其下Beyond Compare 3文件夹即可正常使用. C:\Users\******\AppData\R ...
- Manacher HDOJ 5371 Hotaru's problem
题目传送门 /* 题意:求形如(2 3 4) (4 3 2) (2 3 4)的最长长度,即两个重叠一半的回文串 Manacher:比赛看到这题还以为套个模板就行了,因为BC上有道类似的题,自己又学过M ...
- 超实用的jQuery代码片段
1.jQuery回到顶部效果 HTML代码:<a href="javascript:;" id="btn" title="回到顶部"& ...
- 全面学习ORACLE Scheduler特性(9)创建Chains
五.使用Chains 今天要来认识一位新同学:CHAIN(注意不要敲成CHINA).CHAIN可以被视做一组Programs的复合,举个简单的例子:运行PROGRAM:A以及PROGRAM:B,如果成 ...
- Focusky的下载、安装、注册和使用(动画演示大师)
一.下载 二.安装 三.使用 四.注册 五.附录 非常感谢Focusky官方团队开发并提供实用的这么一款软件!!! 一.下载 http://www.focusky.com.cn/ 二.安装 三.使用 ...
- 在Azure Ubunt Server 14.04虚机中使用Deep-Visualization-Toolbox
参考网站 a) https://zhuanlan.zhihu.com/p/24833574?utm_source=tuicool&utm_medium=referral b) ht ...
- Mysql动态查询
if条件查询 格式: <if test=”条件判断”> 添加到sql的语句 </if> where标签 简化SQL语句中WHERE条件判断 智能处理and和or 如果使用几个i ...