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? ...
随机推荐
- VS自己定义project向导开发(Custom Wizard)
在vs2010中定制VC++project向导有例如以下两种方式: 改动现有向导.以满足自己的须要: 使用"自己定义向导"来产生一个向导骨架,并设计自己的向导. 本文档仅仅讨 ...
- fedora下安装xdot和objgraph
前提:安装好了python 1.先下载xdot-0.6.tar.gz和objgraph-1.8.0-py27-none-any.whl,你也可以在官网上下载其他版本. 2.下载完后,解压. 3.打开终 ...
- oracle技术总结
http://www.cnblogs.com/jimeper/ http://blog.csdn.net/dragonxiangfu http://www.boobooke.com/bbs/threa ...
- 关于Android中物理按键不响应的可能的一个问题。
今天在工作中犯了一个错误,写的视频播放器突然物理音量键就不起作用了. 一開始以为是自己定义的音量条把系统的物理音量条按键给屏蔽掉了. 删除自己定义的音量条还是不行,又怀疑是是加入了什么权限之类的.重复 ...
- openstack kolla多节点容器化环境安装
好久没写随笔了,6月份趁着在公司没有太忙的事儿,把公司的服务器进行了虚拟化,采用的openstack当前的容器化方案kolla. 整体安装完的感受时,小白感觉自己是个大牛!哈哈,开玩笑,由于以前是开发 ...
- Fix "Unable to lock the administration directory (/var/lib/dpkg/)" in Ubuntu
While using the apt-get command or the relatively new APT package management tool in Ubuntu Linux or ...
- Apsara Clouder专项技能认证:实现调用API接口 (笔记)
- SpringMVC_配置和注解--跟海涛学SpringMVC(和自己在项目中的实际使用的对比)
Spring2.5 之前,我们都是通过实现Controller 接口或其实现来定义我们的处理器类,就像前面介绍的 这里介绍的是Spring3.1的新特性,虽然现在我用的是spring4.2.6,不过基 ...
- session与cookie的理解
噶,nation同志又给我布置任务了~~是隔壁家老王提到多次的,session和cookie的运行机制问题~~于是我真的意识到一个问题,程序猿都是一个德行! 1. cookie概述 cookie 常用 ...
- RFC函数设置外部断点