[普及]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构成, ...
随机推荐
- 【iOS】更新 CocoaPods 后 Podfile 报错
更新了 CocoaPods 后,再执行 "pod install" 时报了如下错误: [!] The dependency `AFOnoResponseSerializer` is ...
- 快速字符串匹配一: 看毛片算法(KMP)
前言 由于需要做一个快速匹配敏感关键词的服务,为了提供一个高效,准确,低能耗的关键词匹配服务,我进行了漫长的探索.这里把过程记录成系列博客,供大家参考. 在一开始,接收到快速敏感词匹配时,我就想到了 ...
- 自练Eclipse搭建SSH全自动注解博客项目笔记
1.创建一个动态的java项目 2.导入搭建所需要的jar包 3.配置web.xml文件 1).头文件 2).struts2的拦截器 3).定位加载Spring容器的配置文件 4).监听 5). 6) ...
- BFS DFS模板
转载于https://blog.csdn.net/alalalalalqp/article/details/9155419 BFS模板: #include<cstdio> #include ...
- 1、JAVA的小白之路
大学的时光过得很快,转眼我已经大二了,在大一时,学习了C\C++,对于语言有一定基础,在未来的道路上,我需要攒足干劲,积累足够的知识和技能,去走上社会. 我的第一任大学班主任告诉我:“作为程序员,你至 ...
- 使用webstorm搭建vue-cli项目
前言 随着vue在前端不断的壮大,越来越多的前端工程师使用vue了,作为大型项目的开发,vue-cli是不二之选,所以这篇博客是为搭建vue-cli所写,想要搭建vue-cli项目就必须先有git,n ...
- 转载 | float 清除浮动的7种方法
什么叫浮动:浮动会使当前标签脱离文档流,产生上浮的效果,同时还会影响周边元素(前后标签)及父级元素的位置和width,height属性.下面用一个小例子来看一看浮动的全过程:1.首先我们新建一个网页, ...
- 「求助」关于MacOS 适配不了SOIL的问题 以及我自己愚蠢的解决办法
我的环境 macOS High Sierra 10.13.6 (2018) 我的SOIL源是通过 终端 git clone https://github.com/DeVaukz/SOIL 直接从gay ...
- 后端开发之chrome开发者模式
1. 场景描述 java开发前后端分离模式越来越流行,后端人员可以直接使用swagger进行接口调试(前后端分离之Swagger2),但是调试的时候,需要设置入参,假如该模块不是软件老王开发的,接别人 ...
- mysql根据逗号将一行数据拆分成多行数据
mysql根据逗号将一行数据拆分成多行数据 原始数据 处理结果展示 DDL CREATE TABLE `company` ( `id` ) DEFAULT NULL, `name` ) DEFAULT ...