NOIP 2015 推销员

题意:

    有一个喜欢疲劳的推销员,告诉你在一个单口胡同(数轴)中的n户家庭的位置,和向他们推销可以获得的疲劳度。分别输出向(1,2,3,4...n)户人家推销可以得到的最大疲劳值。对了,这个推销员走一格,疲劳度也会加一。

思路:

  贪心,首先按每户人家的推销疲劳度从大到小排序,考虑选定一组,走路带来的疲劳度是定的,就是最远那个*2.

所以对于每个答案= max(sum[ i ]  + mx * 2 , sum [i - 1] + h[i] )。其中sum是排序后对推销疲劳度做的前缀和,而h[i] 保存 从 i 到 n中,最大的(2 * 距离 + 推销疲劳度)。

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <cstring>
  5. #include <string>
  6. #include <vector>
  7. #include <map>
  8. #include <set>
  9. #include <queue>
  10. #include <list>
  11. #include <cstdlib>
  12. #include <iterator>
  13. #include <cmath>
  14. #include <iomanip>
  15. #include <bitset>
  16. #include <cctype>
  17. using namespace std;
  18. //#pragma GCC optimize(3)
  19. //#pragma comment(linker, "/STACK:102400000,102400000") //c++
  20. #define lson (l , mid , rt << 1)
  21. #define rson (mid + 1 , r , rt << 1 | 1)
  22. #define debug(x) cerr << #x << " = " << x << "\n";
  23. #define pb push_back
  24. #define pq priority_queue
  25.  
  26. typedef long long ll;
  27. typedef unsigned long long ull;
  28.  
  29. typedef pair<ll ,ll > pll;
  30. typedef pair<int ,int > pii;
  31. typedef pair<int ,pii> p3;
  32. //priority_queue<int> q;//这是一个大根堆q
  33. //priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
  34. #define fi first
  35. #define se second
  36. //#define endl '\n'
  37.  
  38. #define OKC ios::sync_with_stdio(false);cin.tie(0)
  39. #define FT(A,B,C) for(int A=B;A <= C;++A) //用来压行
  40. #define REP(i , j , k) for(int i = j ; i < k ; ++i)
  41. //priority_queue<int ,vector<int>, greater<int> >que;
  42.  
  43. const ll mos = 0x7FFFFFFFLL; //
  44. const ll nmos = 0x80000000LL; //-2147483648
  45. const int inf = 0x3f3f3f3f;
  46. const ll inff = 0x3f3f3f3f3f3f3f3fLL; //
  47. const double PI=acos(-1.0);
  48.  
  49. template<typename T>
  50. inline T read(T&x){
  51. x=;int f=;char ch=getchar();
  52. while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
  53. while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
  54. return x=f?-x:x;
  55. }
  56. // #define _DEBUG; //*//
  57. #ifdef _DEBUG
  58. freopen("input", "r", stdin);
  59. // freopen("output.txt", "w", stdout);
  60. #endif
  61. /*-----------------------show time----------------------*/
  62.  
  63. const int maxn = 1e5+;
  64. struct node
  65. {
  66. int s,p;
  67. }a[maxn];
  68. bool cmp(const node &a,const node &b){
  69. return a.p > b.p;
  70. };
  71. int sum[maxn],mx,h[maxn];
  72. int main(){
  73. int n;
  74. scanf("%d", &n);
  75. for(int i=; i<=n; i++)scanf("%d", &a[i].s);
  76. for(int i=; i<=n; i++)scanf("%d", &a[i].p);
  77. sort(a+,a++n,cmp);
  78.  
  79. for(int i=; i<=n; i++){
  80. sum[i] = sum[i-] + a[i].p;
  81. }
  82. for(int i=n; i>=; i--){
  83. h[i] = max(h[i+],a[i].s * + a[i].p);
  84. }
  85.  
  86. for(int i=; i<=n; i++){
  87. if(mx < a[i].s) mx = a[i].s;
  88. int tmp = sum[i] + * mx;
  89. tmp = max(tmp , sum[i-] + h[i]);
  90. printf("%d\n", tmp);
  91. }
  92. return ;
  93. }

LUOGU 2672

[普及]NOIP 2015 推销员 贪心的更多相关文章

  1. NOIP 2015 推销员

    洛谷 P2672 推销员 洛谷传送门 JDOJ 2994: [NOIP2015]推销员 T4 JDOJ传送门 Description 阿明是一名推销员,他奉命到螺丝街推销他们公司的产品.螺丝街是一条死 ...

  2. 4632 NOIP[2015] 运输计划

    4632 NOIP[2015] 运输计划  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 大师 Master 题解       题目描述 Description 公元 2044 ...

  3. [NOIP 2015]运输计划-[树上差分+二分答案]-解题报告

    [NOIP 2015]运输计划 题面: A[NOIP2015 Day2]运输计划 时间限制 : 20000 MS 空间限制 : 262144 KB 问题描述 公元 2044 年,人类进入了宇宙纪元. ...

  4. Luogu 2680 NOIP 2015 运输计划(树链剖分,LCA,树状数组,树的重心,二分,差分)

    Luogu 2680 NOIP 2015 运输计划(树链剖分,LCA,树状数组,树的重心,二分,差分) Description L 国有 n 个星球,还有 n-1 条双向航道,每条航道建立在两个星球之 ...

  5. Luogu 2668 NOIP 2015 斗地主(搜索,动态规划)

    Luogu 2668 NOIP 2015 斗地主(搜索,动态规划) Description 牛牛最近迷上了一种叫斗地主的扑克游戏.斗地主是一种使用黑桃.红心.梅花.方片的A到K加上大小王的共54张牌来 ...

  6. cogs 2109. [NOIP 2015] 运输计划 提高组Day2T3 树链剖分求LCA 二分答案 差分

    2109. [NOIP 2015] 运输计划 ★★★☆   输入文件:transport.in   输出文件:transport.out   简单对比时间限制:3 s   内存限制:256 MB [题 ...

  7. 【noip 2015】普及组

    T1.金币 题目链接 #include<cstdio> #include<algorithm> #include<cstring> using namespace ...

  8. 洛谷 P2668 & P2540 [ noip 2015 ] 斗地主 —— 搜索+贪心

    题目:https://www.luogu.org/problemnew/show/P2668   https://www.luogu.org/problemnew/show/P2540 首先,如果没有 ...

  9. NOIP 2015普及组复赛Day1 T1 == Codevs4510 神奇的幻方

    时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold  题目描述 Description: 幻方是一种很神奇的N∗N矩阵:它由数字 1,2,3, … … ,N∗N构成, ...

随机推荐

  1. elasticsearch启动错误整理

    一.elasticsearch错误复现 (一).环境 配置环境 OS:CentOS 7.4 64bit elasticsearch版本: - ip:10.18.43.170 java版本:java - ...

  2. hive数仓客户端界面工具

    1.Hive的官网上介绍了三个可以在Windows中通过JDBC连接HiveServer2的图形界面工具,包括:SQuirrel SQL Client.Oracle SQL Developer以及Db ...

  3. Centos安装git并配置ssh

    1.下载git安装包 git-2.9.4.tar.gz 2.解压 tar -xzvf git-2.9.4.tar.gz 3.修改解压后的文件名 mv git-2.9.4 git 4.安装git依赖的库 ...

  4. SpringBoot配置web访问H2

    [**前情提要**]最近开始搭建博客,在本地调试的时候使用的数据库是h2,但是调试的时候需要查看数据库,本文也由此而来. --- 下面是我用到的方法: 1. 使用IDEA的Database连接工具,具 ...

  5. 使用webstorm调试node.js

    折腾半天,还是webstorm顺手,但也遇到一些小问题. 1.代码补全问题 nodeJS自身的补全 File->Project Setting->JavaScript->Librar ...

  6. scala之构造器详解

    1.基本语法: 构造器分为主构造器和辅助构造器 class 类名(形参列表) {  // 主构造器 // 类体 def  this(形参列表) {  // 辅助构造器 } def  this(形参列表 ...

  7. Yii2 基础模板前后台登录分离

    1.用GII 生成一个模块(modules)名字为 admin 2.在./config/web.php 中加入如下配置 'modules' => [ 'admin' => [ 'class ...

  8. 昂贵的聘礼 POJ - 1062

    题目链接:https://vjudge.net/problem/POJ-1062 如图,我们可以把交换的情况,抽象为一个有向图, 先抛去等级限制,那么就是一个最短路,从①出发,到达其他点的最短路中 最 ...

  9. print,cat打印格式及字符串引号格式,去掉字符串空格 in R

    print 函数的打印格式: ##no quote print out > x <- letters[1:5] > print(x,quote=F,);print(x,quote=T ...

  10. 如何利用jenkins插件查看allure报告-----完整篇(解决404和无数据问题)

    背景: python3+appium+pytest+allure写了安卓的自动化脚本,在windows本机pycharm上跑通过后生成了allure报告.  公司jenkins搭建在linux服务器上 ...