[普及]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 * 距离 + 推销疲劳度)。
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <cstring>
- #include <string>
- #include <vector>
- #include <map>
- #include <set>
- #include <queue>
- #include <list>
- #include <cstdlib>
- #include <iterator>
- #include <cmath>
- #include <iomanip>
- #include <bitset>
- #include <cctype>
- using namespace std;
- //#pragma GCC optimize(3)
- //#pragma comment(linker, "/STACK:102400000,102400000") //c++
- #define lson (l , mid , rt << 1)
- #define rson (mid + 1 , r , rt << 1 | 1)
- #define debug(x) cerr << #x << " = " << x << "\n";
- #define pb push_back
- #define pq priority_queue
- typedef long long ll;
- typedef unsigned long long ull;
- typedef pair<ll ,ll > pll;
- typedef pair<int ,int > pii;
- typedef pair<int ,pii> p3;
- //priority_queue<int> q;//这是一个大根堆q
- //priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
- #define fi first
- #define se second
- //#define endl '\n'
- #define OKC ios::sync_with_stdio(false);cin.tie(0)
- #define FT(A,B,C) for(int A=B;A <= C;++A) //用来压行
- #define REP(i , j , k) for(int i = j ; i < k ; ++i)
- //priority_queue<int ,vector<int>, greater<int> >que;
- const ll mos = 0x7FFFFFFFLL; //
- const ll nmos = 0x80000000LL; //-2147483648
- const int inf = 0x3f3f3f3f;
- const ll inff = 0x3f3f3f3f3f3f3f3fLL; //
- const double PI=acos(-1.0);
- template<typename T>
- inline T read(T&x){
- x=;int f=;char ch=getchar();
- while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
- while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
- return x=f?-x:x;
- }
- // #define _DEBUG; //*//
- #ifdef _DEBUG
- freopen("input", "r", stdin);
- // freopen("output.txt", "w", stdout);
- #endif
- /*-----------------------show time----------------------*/
- const int maxn = 1e5+;
- struct node
- {
- int s,p;
- }a[maxn];
- bool cmp(const node &a,const node &b){
- return a.p > b.p;
- };
- int sum[maxn],mx,h[maxn];
- int main(){
- int n;
- scanf("%d", &n);
- for(int i=; i<=n; i++)scanf("%d", &a[i].s);
- for(int i=; i<=n; i++)scanf("%d", &a[i].p);
- sort(a+,a++n,cmp);
- for(int i=; i<=n; i++){
- sum[i] = sum[i-] + a[i].p;
- }
- for(int i=n; i>=; i--){
- h[i] = max(h[i+],a[i].s * + a[i].p);
- }
- for(int i=; i<=n; i++){
- if(mx < a[i].s) mx = a[i].s;
- int tmp = sum[i] + * mx;
- tmp = max(tmp , sum[i-] + h[i]);
- printf("%d\n", tmp);
- }
- return ;
- }
LUOGU 2672
[普及]NOIP 2015 推销员 贪心的更多相关文章
- NOIP 2015 推销员
洛谷 P2672 推销员 洛谷传送门 JDOJ 2994: [NOIP2015]推销员 T4 JDOJ传送门 Description 阿明是一名推销员,他奉命到螺丝街推销他们公司的产品.螺丝街是一条死 ...
- 4632 NOIP[2015] 运输计划
4632 NOIP[2015] 运输计划 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 大师 Master 题解 题目描述 Description 公元 2044 ...
- [NOIP 2015]运输计划-[树上差分+二分答案]-解题报告
[NOIP 2015]运输计划 题面: A[NOIP2015 Day2]运输计划 时间限制 : 20000 MS 空间限制 : 262144 KB 问题描述 公元 2044 年,人类进入了宇宙纪元. ...
- Luogu 2680 NOIP 2015 运输计划(树链剖分,LCA,树状数组,树的重心,二分,差分)
Luogu 2680 NOIP 2015 运输计划(树链剖分,LCA,树状数组,树的重心,二分,差分) Description L 国有 n 个星球,还有 n-1 条双向航道,每条航道建立在两个星球之 ...
- Luogu 2668 NOIP 2015 斗地主(搜索,动态规划)
Luogu 2668 NOIP 2015 斗地主(搜索,动态规划) Description 牛牛最近迷上了一种叫斗地主的扑克游戏.斗地主是一种使用黑桃.红心.梅花.方片的A到K加上大小王的共54张牌来 ...
- cogs 2109. [NOIP 2015] 运输计划 提高组Day2T3 树链剖分求LCA 二分答案 差分
2109. [NOIP 2015] 运输计划 ★★★☆ 输入文件:transport.in 输出文件:transport.out 简单对比时间限制:3 s 内存限制:256 MB [题 ...
- 【noip 2015】普及组
T1.金币 题目链接 #include<cstdio> #include<algorithm> #include<cstring> using namespace ...
- 洛谷 P2668 & P2540 [ noip 2015 ] 斗地主 —— 搜索+贪心
题目:https://www.luogu.org/problemnew/show/P2668 https://www.luogu.org/problemnew/show/P2540 首先,如果没有 ...
- NOIP 2015普及组复赛Day1 T1 == Codevs4510 神奇的幻方
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description: 幻方是一种很神奇的N∗N矩阵:它由数字 1,2,3, … … ,N∗N构成, ...
随机推荐
- elasticsearch启动错误整理
一.elasticsearch错误复现 (一).环境 配置环境 OS:CentOS 7.4 64bit elasticsearch版本: - ip:10.18.43.170 java版本:java - ...
- hive数仓客户端界面工具
1.Hive的官网上介绍了三个可以在Windows中通过JDBC连接HiveServer2的图形界面工具,包括:SQuirrel SQL Client.Oracle SQL Developer以及Db ...
- 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依赖的库 ...
- SpringBoot配置web访问H2
[**前情提要**]最近开始搭建博客,在本地调试的时候使用的数据库是h2,但是调试的时候需要查看数据库,本文也由此而来. --- 下面是我用到的方法: 1. 使用IDEA的Database连接工具,具 ...
- 使用webstorm调试node.js
折腾半天,还是webstorm顺手,但也遇到一些小问题. 1.代码补全问题 nodeJS自身的补全 File->Project Setting->JavaScript->Librar ...
- scala之构造器详解
1.基本语法: 构造器分为主构造器和辅助构造器 class 类名(形参列表) { // 主构造器 // 类体 def this(形参列表) { // 辅助构造器 } def this(形参列表 ...
- Yii2 基础模板前后台登录分离
1.用GII 生成一个模块(modules)名字为 admin 2.在./config/web.php 中加入如下配置 'modules' => [ 'admin' => [ 'class ...
- 昂贵的聘礼 POJ - 1062
题目链接:https://vjudge.net/problem/POJ-1062 如图,我们可以把交换的情况,抽象为一个有向图, 先抛去等级限制,那么就是一个最短路,从①出发,到达其他点的最短路中 最 ...
- print,cat打印格式及字符串引号格式,去掉字符串空格 in R
print 函数的打印格式: ##no quote print out > x <- letters[1:5] > print(x,quote=F,);print(x,quote=T ...
- 如何利用jenkins插件查看allure报告-----完整篇(解决404和无数据问题)
背景: python3+appium+pytest+allure写了安卓的自动化脚本,在windows本机pycharm上跑通过后生成了allure报告. 公司jenkins搭建在linux服务器上 ...