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,对答案是有贡献的。

  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <assert.h>
  7. #define IOS ios::sync_with_stdio(false)
  8. using namespace std;
  9. #define inf (0x3f3f3f3f)
  10. typedef long long int LL;
  11.  
  12. #include <iostream>
  13. #include <sstream>
  14. #include <vector>
  15. #include <set>
  16. #include <map>
  17. #include <queue>
  18. #include <string>
  19. #include <bitset>
  20. const int maxn = 1e2 + ;
  21. struct node {
  22. int val, cnt;
  23. bool operator < (const struct node & rhs) const {
  24. if (val != rhs.val) return val < rhs.val;
  25. else return ;
  26. }
  27. }a[maxn];
  28. vector<int>haha;
  29. int last[];
  30. void work() {
  31. int n;
  32. scanf("%d", &n);
  33. int mx = -inf;
  34. for (int i = ; i <= n; ++i) {
  35. scanf("%d%d", &a[i].val, &a[i].cnt);
  36. mx = max(mx, a[i].val);
  37. }
  38. sort(a + , a + + n);
  39. haha.push_back(-inf);
  40. for (int i = ; i <= n; ++i) {
  41. for (int j = ; j <= a[i].cnt; ++j) {
  42. haha.push_back(a[i].val);
  43. }
  44. }
  45. int sum = , pos = inf;
  46. for (int i = haha.size() - ; i >= ; --i) {
  47. sum += haha[i];
  48. if (sum <= ) {
  49. pos = i + ;
  50. break;
  51. }
  52. }
  53. LL ans = ;
  54. int now = ;
  55. for (int i = pos; i < haha.size(); ++i) {
  56. ans += now * haha[i];
  57. now++;
  58. }
  59. cout << ans << endl;
  60. }
  61.  
  62. int main() {
  63. #ifdef local
  64. freopen("data.txt", "r", stdin);
  65. // freopen("data.txt", "w", stdout);
  66. #endif
  67. int t;
  68. scanf("%d", &t);
  69. while (t--) work();
  70. return ;
  71. }

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. VS自己定义project向导开发(Custom Wizard)

     在vs2010中定制VC++project向导有例如以下两种方式: 改动现有向导.以满足自己的须要: 使用"自己定义向导"来产生一个向导骨架,并设计自己的向导. 本文档仅仅讨 ...

  2. fedora下安装xdot和objgraph

    前提:安装好了python 1.先下载xdot-0.6.tar.gz和objgraph-1.8.0-py27-none-any.whl,你也可以在官网上下载其他版本. 2.下载完后,解压. 3.打开终 ...

  3. oracle技术总结

    http://www.cnblogs.com/jimeper/ http://blog.csdn.net/dragonxiangfu http://www.boobooke.com/bbs/threa ...

  4. 关于Android中物理按键不响应的可能的一个问题。

    今天在工作中犯了一个错误,写的视频播放器突然物理音量键就不起作用了. 一開始以为是自己定义的音量条把系统的物理音量条按键给屏蔽掉了. 删除自己定义的音量条还是不行,又怀疑是是加入了什么权限之类的.重复 ...

  5. openstack kolla多节点容器化环境安装

    好久没写随笔了,6月份趁着在公司没有太忙的事儿,把公司的服务器进行了虚拟化,采用的openstack当前的容器化方案kolla. 整体安装完的感受时,小白感觉自己是个大牛!哈哈,开玩笑,由于以前是开发 ...

  6. 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 ...

  7. Apsara Clouder专项技能认证:实现调用API接口 (笔记)

  8. SpringMVC_配置和注解--跟海涛学SpringMVC(和自己在项目中的实际使用的对比)

    Spring2.5 之前,我们都是通过实现Controller 接口或其实现来定义我们的处理器类,就像前面介绍的 这里介绍的是Spring3.1的新特性,虽然现在我用的是spring4.2.6,不过基 ...

  9. session与cookie的理解

    噶,nation同志又给我布置任务了~~是隔壁家老王提到多次的,session和cookie的运行机制问题~~于是我真的意识到一个问题,程序猿都是一个德行! 1. cookie概述 cookie 常用 ...

  10. RFC函数设置外部断点