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? ...
随机推荐
- 【计算机视觉】SIFT中LoG和DoG比較
在实际计算时,三种方法计算的金字塔组数noctaves,尺度空间坐标σ,以及每组金字塔内的层数S是一样的.同一时候,如果图像为640*480的标准图像. 金字塔层数: 当中o_min = 0,对于分辨 ...
- 湘潭邀请赛——Alice and Bob
Alice and Bob Accepted : 133 Submit : 268 Time Limit : 1000 MS Memory Limit : 65536 KB Problem ...
- 安装PyQt5和Eric6
安装官方的指引,安装起来本来是非常简单的,但是我前后折腾了两天,甚至连Eric得源码都去调试都没成功.过程如下: 在PyQt5的官网链接中下载轮子 PyQt5-5.7.1-5.7.1-cp34.cp3 ...
- oracle连接串的一种写法
我在.NET项目里访问oracle,向来是规规矩矩地这样写: DATA SOURCE=PDBGZFBC;PASSWORD=test;PERSIST SECURITY INFO=True;USER ID ...
- C项目实践--图书管理系统(3)
接下来将要实现用户管理模块的相关功能,用户管理模块的主要功能包括增加用户,查找用户以及保存用户等功能,查找用户时,如果查找成功,充许对查找到用户进行更新或删除操作.如果查找不成功,则给出相应的提示信息 ...
- LeetCode 7. Reverse Integer (JS)
Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 Examp ...
- 解决Linux环境Oracle显示乱码
首先查看当前的编码格式 select userenv('language') from dual; 解决方法: 一.临时解决方法 切换到Oracle用户,执行 export NLS_LAN ...
- Count on an IEnumerable<dynamic>
http://stackoverflow.com/questions/7733305/count-on-an-ienumerabledynamic int count = Enumerable.Cou ...
- YTU 2573: 连续奇数和
2573: 连续奇数和 时间限制: 1 Sec 内存限制: 128 MB 提交: 63 解决: 37 题目描述 小明看到一本书上写着:任何数字的立方都可以表示为连续奇数的和. 比如: 2^3 = ...
- 用dpkg命令制作deb包方法总结
用dpkg命令制作deb包方法总结 如何制作Deb包和相应的软件仓库,其实这个很简单.这里推荐使用dpkg来进行deb包的创建.编辑和制作. 首先了解一下deb包的文件结构: deb 软件包里面的结构 ...