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:FreeMarker
ylbtech-杂项-Java:FreeMarker 1.返回顶部 1. FreeMarker是一款模板引擎: 即一种基于模板和要改变的数据, 并用来生成输出文本(HTML网页.电子邮件.配置文件.源 ...
- bzoj4870
http://www.lydsy.com/JudgeOnline/problem.php?id=4870 矩阵快速幂... 人话题意:从nk个物品里选模k余r个物品,问方案数模P 那么我们有方程 f[ ...
- mysql status关键字 数据表设计中慎重使用
mysql status关键字 数据表设计中慎重使用
- bzoj 1623: [Usaco2008 Open]Cow Cars 奶牛飞车【排序+贪心】
从小到大排个序,然后能选就选 #include<iostream> #include<cstdio> #include<algorithm> using names ...
- P3822 [NOI2017]整数
传送门 shadowice大佬已经写的非常详细了我就不再写一遍了-- //minamoto #include<bits/stdc++.h> #define u unsigned int # ...
- 最近我总结的常用mate标签-常用mate标签
昨天开始上班 ,今天晚上不是太忙 ,来写篇博客了 meta元素共有三个可选属性(http-equiv.name和scheme)和一个必选属性(content),content定义与 http-equ ...
- PowerDesigner连接Oracle数据库(32位)反向生成物理数据模型
PowerDesigner可以连接Oracle数据库进行反向生成物理数据模型,本文演示操作过程. 环境说明: 1)Windows8.1,Oracle11R2 32位. 2)PowerDesigner1 ...
- python2 'str' object has no attribute 'decode'
'.decode('hex') 上述代码,报错: 'str' object has no attribute 'decode' 查找原因: https://stackoverflow.com/ques ...
- Spring.Net学习笔记(1)-容器的使用
一.下载地址: http://www.springframework.net/download.html 二.相关程序集 Spring.Net容器定义在程序集Spring.Core.dll中,它依赖于 ...
- CF798C Mike and gcd problem
思路: 首先如果数列的最大公约数大于1,直接输出即可. 否则,设对原数列中的ai和ai+1进行一次操作,分别变为ai - ai+1和ai + ai+1.设新数列的最大公约数为d,则由于d|(ai - ...