hdu 6011 Lotus and Characters 贪心
http://acm.hdu.edu.cn/showproblem.php?pid=6011
先把数字从小到大排好,比如是-6、3、4这样,
然后处理出后缀和,当后缀和 <= 0的时候马上停止就好了。
证明:
假如现在是去到了第二个,也就是那个3,后缀和是7,那么我选不选-6呢?
如果选,
结果是: 1 * (-6) + 2 * 3 + 3 * 4
= 1 * (-6) + 3 + 4 + [1 * 3 + 2 * 4]
此时后缀和 > 0,对答案是有贡献的。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
const int maxn = 1e2 + ;
struct node {
int val, cnt;
bool operator < (const struct node & rhs) const {
if (val != rhs.val) return val < rhs.val;
else return ;
}
}a[maxn];
vector<int>haha;
int last[];
void work() {
int n;
scanf("%d", &n);
int mx = -inf;
for (int i = ; i <= n; ++i) {
scanf("%d%d", &a[i].val, &a[i].cnt);
mx = max(mx, a[i].val);
}
sort(a + , a + + n);
haha.push_back(-inf);
for (int i = ; i <= n; ++i) {
for (int j = ; j <= a[i].cnt; ++j) {
haha.push_back(a[i].val);
}
}
int sum = , pos = inf;
for (int i = haha.size() - ; i >= ; --i) {
sum += haha[i];
if (sum <= ) {
pos = i + ;
break;
}
}
LL ans = ;
int now = ;
for (int i = pos; i < haha.size(); ++i) {
ans += now * haha[i];
now++;
}
cout << ans << endl;
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
int t;
scanf("%d", &t);
while (t--) work();
return ;
}
hdu 6011 Lotus and Characters 贪心的更多相关文章
- hdu 4825 Xor Sum(trie+贪心)
hdu 4825 Xor Sum(trie+贪心) 刚刚补了前天的CF的D题再做这题感觉轻松了许多.简直一个模子啊...跑树上异或x最大值.贪心地让某位的值与x对应位的值不同即可. #include ...
- Best Coder Lotus and Characters
Lotus and Characters 问题描述 Lotus有nn种字母,给出每种字母的价值以及每种字母的个数限制,她想构造一个任意长度的串. 定义串的价值为:第1位字母的价值*1+第2位字母的 ...
- HDU 6011:Lotus and Characters(贪心)
http://acm.hdu.edu.cn/showproblem.php?pid=6011 题意:共有n种字符,每种字符有一个val和一个cnt,代表这个字符的价值和数量.可以制造的总价值是:第一个 ...
- HDU 5744 Keep On Movin 贪心
Keep On Movin 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5744 Description Professor Zhang has k ...
- BestCoder Round #91 1001 Lotus and Characters
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6011 题意: Lotus有nn种字母,给出每种字母的价值以及每种字母的个数限制,她想构造一个任意长度的 ...
- HDU 6034 Balala Power!(贪心+排序)
Balala Power! Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- HDU 5813 Elegant Construction (贪心)
Elegant Construction 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5813 Description Being an ACMer ...
- HDU 5802 Windows 10 (贪心+dfs)
Windows 10 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5802 Description Long long ago, there was ...
- HDU 5500 Reorder the Books 贪心
Reorder the Books Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
随机推荐
- Win8系统如何在桌面行显示我的电脑
1 桌面右击-个性化 2 更改桌面图标-然后可以在桌面上显示需要的东西
- 微信通过openID发送消息/后台post、get提交并接收数据 C# .NET 配置404,500等错误信息 连接字符串
微信通过openID发送消息/后台post.get提交并接收数据 控制器:下面是post发送消息(微信不支持从前台发送数据,之前试过,报错,需要跨域,跨域的问题解决后还不行,最后发现之后后端提交 ...
- [Android]自己定义带删除输入框
在项目开发中,带删除button输入框也是人们经常常使用到的,该文章便介绍一下怎样创建一个带删除输入框.当中,须要解决的问题例如以下: a)创建自己定义editText类 b)在自己定义editTex ...
- string 是值类型,还是引用类型(.net)[转]
转自http://hi.baidu.com/newfzks/item/b805f0f4edb0810dd89e7290 string 是值类型,还是引用类型(.net) 一. string 类型的用法 ...
- 嵌入式开发之davinci--- 8127 中camer 和 capture link 的区别
(1)camera link (2)capture link (3)两者区别 (1)camera link 走的是isp iss link采集的得到的数据,适用于ipnc 框架 (2)capture ...
- 嵌入式开发之命令行---linux下的find文件查找命令与grep文件内容查找命令
在使用linux时,经常需要进行文件查找.其中查找的命令主要有find和grep.两个命令是有区的. 区别:(1)find命令是根据文件的属性进行查找,如文件名,文件大小,所有者,所属组,是否为空,访 ...
- [IT学习]Python pandas 学习
今天学习pandas来处理数据,结果用python 3.5.0的shell来调试,总是报错. 报错中包含如下字样: Traceback (most recent call last): File &q ...
- [办公自动化]chrome浏览器的书签在哪里存放
最近换电脑了. 硬盘直接挂在了新电脑上.忘记导出Chrome的浏览器的书签了. 对于书签,Windows XP和Windows 7的路径都是: C:\Documents and Settings\** ...
- HDU 5544 Ba Gua Zhen dfs+高斯消元
Ba Gua Zhen Problem Description During the Three-Kingdom period, there was a general named Xun Lu wh ...
- POJ 3368 Frequent values RMQ ST算法/线段树
Frequent values Time Limit: 2000MS Memory Lim ...