HDU多校Round 1
Solved:5
rank:172
A.Maximum Multiple
#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll; int main()
{
int T;
scanf("%d", &T);
while(T--)
{
int n;
scanf("%d", &n);
ll ans = -;
if(n % == )
{
ll x = n / ;
ans = max(ans, x * x * x);
}
if(n % == )
{
ll x = n / ;
ans = max(ans, x * x * x * );
}
printf("%lld\n", ans);
}
return ;
}
B.Balanced Sequence
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string.h>
using namespace std; char s[];
struct node
{
int l, r;
}E[]; bool cmp(node A, node B)
{
int tmp1 = min(A.l, B.r);
int tmp2 = min(A.r, B.l);
if(tmp1 == tmp2) return A.r < B.r;
else return tmp1 > tmp2;
} int main()
{
int T;
scanf("%d", &T);
while(T--)
{
int ans = ; int cnt = ;
int suml = , sumr = ;
int n;
scanf("%d", &n);
for(int i = ; i <= n; i++)
{
scanf("%s", s);
int len = strlen(s); int cnl = , cnr = ;
for(int j = ; j < len; j++)
{
if(s[j] == '(') cnl++;
else
{
if(cnl)
{
cnl--;
ans += ;
}
else cnr++;
}
}
if(cnl == ) sumr += cnr;
else if(cnr == ) suml += cnl;
else
{
cnt++;
E[cnt].l = cnl;
E[cnt].r = cnr;
}
}
sort(E + , E + + cnt, cmp); for(int i = ; i <= cnt; i++)
{
if(suml >= E[i].r)
{
ans += E[i].r * ;
suml -= E[i].r;
suml += E[i].l;
}
else
{
ans += suml * ;
suml = E[i].l;
}
}
ans += min(suml, sumr) * ;
printf("%d\n", ans);
}
return ;
}
HDU多校Round 1的更多相关文章
- HDU多校Round 8
Solved:2 rank:141 D. Parentheses Matrix n,m有一个小于6的时候是一种构造方法 答案是n + (m - 2) / 2 (n > m) 都大于6的时候 可以 ...
- HDU多校Round 7
Solved:2 rank:293 J. Sequense 不知道自己写的什么东西 以后整数分块直接用 n / (n / i)表示一个块内相同n / i的最大i #include <bits/s ...
- HDU多校Round 6
Solved:2 rank:452 I. Werewolf 没有铁人 找铁狼 如果一个环中只有一条狼人边那个人就是铁狼 说铁狼是好人的人也是铁狼 #include <bits/stdc++.h& ...
- HDU多校Round 5
Solved:3 rank:71 E. Everything Has Changed #include <bits/stdc++.h> using namespace std; const ...
- HDU多校Round 4
Solved:3 rank:405................................. B. Harvest of Apples 知道了S(n,m) 可以o(1)的求S(n - 1, m ...
- HDU多校Round 3
Solved:4 rank:268 C. Dynamic Graph Matching 状压DP一下 #include <stdio.h> #include <algorithm& ...
- hdu 5667 BestCoder Round #80 矩阵快速幂
Sequence Accepts: 59 Submissions: 650 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536 ...
- hdu 5643 BestCoder Round #75
King's Game Accepts: 249 Submissions: 671 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 6 ...
- hdu 5641 BestCoder Round #75
King's Phone Accepts: 310 Submissions: 2980 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
随机推荐
- iOS学习笔记(4) — UITableView的 重用机制
iOS学习笔记(4) — UITableView的 重用机制 UITableView中的cell是动态的,在使用过程中,系统会根据屏幕的高度(480)和每个cell的高度计算屏幕中需要显示的cell的 ...
- 菜鸟的mongoDB学习---(五)MongoDB的limit、skip、sort方法
limit方法 假设你须要在MongoDB中读取指定数量的数据记录.能够使用MongoDB的Limit方法,limit()方法接受一个数字參数,该參数指定从MongoDB中读取的记录条数. mongo ...
- 稀疏表示 Sparse Representation
稀疏表示_百度百科 https://baike.baidu.com/item/%E7%A8%80%E7%96%8F%E8%A1%A8%E7%A4%BA/16530498 信号稀疏表示是过去近20年来信 ...
- mysql group by 组内排序 group by 原理
mysql group by 组内排序 SELECT * FROM (SELECT MAX(id) AS t,wukong_uid, 1 AS tag FROM toutiao_uid_gath ...
- Android原生音量控制【转】
本文转载自:http://blog.csdn.net/u013082948/article/details/65630085 本文主要涉及AudioService.还是基于5.1.1版本的代码. Au ...
- mac ox终端显示 bogon的问题
mac终端显示如果正常应该是电脑名称(偏好设置-共享)的,但是细心的我们会发现,当电脑换了网络环境之后,可能就会出现终端上显示为主机名为:bogon,一查bogon这个单词是虚拟.虚伪的意思. ...
- 学习 Shell —— 认识 shell
0. 认识 shell shell 是一个命令行解释器(interpreter),它会输出一个提示符,等待输入一个命令,然后执行该命令.如果该命令行的第一个单词不是一个内置的 shell 命令,那么 ...
- 【USACO07FEB】 Cow Relays
[题目链接] 点击打开链接 [算法] 朴素算法,就是跑N-1遍floyd 而满分算法就是通过矩阵快速幂加速这个过程 [代码] ...
- ModuleNotFoundError: No module named 'cStringIO'
这是2.x转3.x问题: 2.x写法: import cStringIO 3.x写法: from io import StringIO 问题解决.
- ZOJ2107 Quoit Design 最近点对
ZOJ2107 给定10^5个点,求距离最近的点对的距离. O(n^2)的算法是显而易见的. 可以通过分治优化到O(nlogn) 代码很简单 #include<iostream> #inc ...