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 ...
随机推荐
- 【转载】Java - Wait & Notify
[本文转自]http://www.cnblogs.com/dolphin0520/p/3920385.html 这三个方法的文字描述可以知道以下几点信息: 1)wait().notify()和noti ...
- 开车旅行 2012年NOIP全国联赛提高组(倍增+set)
开车旅行 2012年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 小A 和小B决定利用 ...
- 课后题--------求分子量-----Molar mass------
简单的化学式 求分子量问题 下面附上 代码和解析. #include<stdio.h> #include<algorithm> #include<string.h&g ...
- 贪心+构造 Codeforces Round #277 (Div. 2) C. Palindrome Transformation
题目传送门 /* 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了 */ /************************************************ ...
- 400 Nth Digit 第N个数字
在无限的整数序列 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...中找到第 n 个数字.注意:n 是正数且在32为整形范围内 ( n < 231).示例 1:输入:3 ...
- 获取Sprite上某一个点的透明度
转载[ http://www.cnblogs.com/Androider123/p/3795050.html] 本篇文章主要讲一下怎么做一个不规则的按钮,比如如下图的八卦,点击绿色和点击红色部分,需要 ...
- 专题二:HTTP协议详解
我们在用Asp.net技术开发Web应用程序后,当用户在浏览器输入一个网址时就是再向服务器发送一个HTTP请求,此时就使用了应用层的HTTP协议,在上一个专题我们简单介绍了网络协议的知识,主要是为了后 ...
- malloc()函数的使用
malloc是向系统申请分配指定size个字节的内存空间.返回值类型为void *类型.void *表示未确定的类型指针.C语言中,void *类型可以强制转换为任何其他类型的指针. 语法:void ...
- Codewars练习Python
计算一个数组的中间数,数的两边和相等,并返回index值 如:数组[1,2,3,4,6] 返回3(数组序号从0开始) def find_even_index(arr): ""&qu ...
- dedecms手机网站内页上一篇/下一篇的翻页功能
修改文件include/arc.archives.class.php文件. 1.搜索 function GetPreNext($gtype='') 2.将这个函数的所有内容替换为 function G ...