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 贪心的更多相关文章

  1. hdu 4825 Xor Sum(trie+贪心)

    hdu 4825 Xor Sum(trie+贪心) 刚刚补了前天的CF的D题再做这题感觉轻松了许多.简直一个模子啊...跑树上异或x最大值.贪心地让某位的值与x对应位的值不同即可. #include ...

  2. Best Coder Lotus and Characters

     Lotus and Characters  问题描述 Lotus有nn种字母,给出每种字母的价值以及每种字母的个数限制,她想构造一个任意长度的串. 定义串的价值为:第1位字母的价值*1+第2位字母的 ...

  3. HDU 6011:Lotus and Characters(贪心)

    http://acm.hdu.edu.cn/showproblem.php?pid=6011 题意:共有n种字符,每种字符有一个val和一个cnt,代表这个字符的价值和数量.可以制造的总价值是:第一个 ...

  4. HDU 5744 Keep On Movin 贪心

    Keep On Movin 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5744 Description Professor Zhang has k ...

  5. BestCoder Round #91 1001 Lotus and Characters

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6011 题意: Lotus有nn种字母,给出每种字母的价值以及每种字母的个数限制,她想构造一个任意长度的 ...

  6. HDU 6034 Balala Power!(贪心+排序)

    Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  7. HDU 5813 Elegant Construction (贪心)

    Elegant Construction 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5813 Description Being an ACMer ...

  8. HDU 5802 Windows 10 (贪心+dfs)

    Windows 10 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5802 Description Long long ago, there was ...

  9. HDU 5500 Reorder the Books 贪心

    Reorder the Books Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

随机推荐

  1. Lucene中TokenStream,Tokenizer,TokenFilter,TokenStreamComponents与Analyzer

    TokenStream extends AttributeSource implements Closeable: incrementToken,end,reset,close Tokenizer直接 ...

  2. Android中个人推崇的数据库使用方式

    手机应用开发中常常会使用到数据库存储一些资料或者进行数据缓存,android中为我们提供了一个轻量的数据库.在上层进行了一层封装,同一时候还为我们提供了ContentProvider的框架.方便我们进 ...

  3. Selenium系列之--测试框架断言【转】

    selenium提供了三种模式的断言:assert .verify.waitfor 1)Assert(断言) 失败时,该测试将终止. 2)Verify(验证) 失败时,该测试将继续执行,并将错误记入日 ...

  4. 朴素的标题:MVC中权限管理实践

    基于MVC的web项目最好的权限控制方式我认为是对Action的控制,实现思路记录于此,权限管理分成两个部分授权.认证. 一.授权 1.读取当前项目中的所有需要控制的Action /// <su ...

  5. 【ios系列】-数据储存

    第一:plist属性列表 适用对象:仅仅是Foundation框架自带的一些类比如:NString\NSarry\NSDictionary\NSset\NSnumber\NSdata 使用: 1:调用 ...

  6. 使用css属性line-height实现文字垂直居中的问题

    使用css属性line-height实现文字垂直居中的问题 1.使用css属性line-height实现文字垂直居中 方法比较简单,但是只能实现单行文字的垂直居中. 单行垂直居中效果如下:   要是p ...

  7. js来获取所有屏幕适配的总结

    "屏幕分辨率为:"+screen.width+"*"+screen.height "屏幕可用大小:"+screen.availWidth+& ...

  8. java泛型-类型擦除

    详细内容:参考java编程思想P373,p650. Java 泛型(Generic)的引入加强了参数类型的安全性,减少了类型的转换,但有一点需要注意:Java 的泛型在编译器有效,在运行期被删除,也就 ...

  9. IE、W3C两种CSS盒子模型

    利用CSS来布局页面布局DIV有点逻辑性!重点理解盒子模型,标准流和非标准流的区别,还有定位原理!把这3个攻破了,就非常简单了!多实践多参考!最后就是兼容问题了,在实践中自然就有经验了!这些兼容技巧都 ...

  10. 牛客练习赛13D:幸运数字Ⅳ(康托展开) F:关键字排序

    链接:https://www.nowcoder.com/acm/contest/70/D 题目: 定义一个数字为幸运数字当且仅当它的所有数位都是4或者7. 比如说,47.744.4都是幸运数字而5.1 ...