cf 853 A planning [贪心]
题面:
思路:
一眼看得,这是贪心【雾】
实际上,我们要求的答案就是sigma(ci*(ti-i))(i=1~n),这其中sigma(ci*i)是确定的
那么我们就要最小化sigma(ci*ti)
所以在新的每一秒,就把这一秒开始可以起飞的飞机中,cost最大的那一个拿出来,让他起飞就可以了
证明:
设最大的为m,我们取得另一个为n
那么n*ti+m*(ti+1) >= n*(ti+1)+m*ti
所以取m最好
这个过程用堆实现,懒得手打了,就用了priority_queue
Code:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
inline int read(){
int re=,flag=;char ch=getchar();
while(ch>''||ch<''){
if(ch=='-') flag=-;
ch=getchar();
}
while(ch>=''&&ch<='') re=(re<<)+(re<<)+ch-'',ch=getchar();
return re*flag;
}
struct flight{
int t,cost;
}a[];
inline bool operator < (flight l,flight r){
return l.cost<r.cost;
}
priority_queue<flight>q;
int n,k;long long tot=;
int ans[];
int main(){
int i;flight tmp;
n=read();k=read();
for(i=;i<=n;i++) a[i].t=i,a[i].cost=read();
for(i=;i<=k;i++) q.push(a[i]);
for(i=k+;i<=k+n;i++){
if(i<=n) q.push(a[i]);
tmp=q.top();q.pop();
ans[tmp.t]=i;tot+=(i-tmp.t)*1ll*tmp.cost;
}
printf("%lld\n",tot);
for(i=;i<=n;i++) printf("%d ",ans[i]);
}
cf 853 A planning [贪心]的更多相关文章
- CF 115B Lawnmower(贪心)
题目链接: 传送门 Lawnmower time limit per test:2 second memory limit per test:256 megabytes Description ...
- CF Soldier and Badges (贪心)
Soldier and Badges time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- CF Anya and Ghosts (贪心)
Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- cf 853 D Michael and Charging Stations [dp]
题面: 传送门 思路: 看到题目,第一思路是贪心,但是我很快就否决掉了(其实分类贪心也可以做) 然后就想,贪心不能解决的状态缺失,是否可以用dp来解决呢? 事实证明是可以的 我们设dp[i][j]表示 ...
- #433 Div2 Problem C Planning (贪心 && 优先队列)
链接 : http://codeforces.com/contest/854/problem/C 题意 : 有 n 架飞机需要分别在 1~n 秒后起飞,允许起飞的时间是从 k 秒后开始,给出每一架飞机 ...
- CF 1082E Increasing Frequency(贪心)
传送门 解题思路 贪心.对于一段区间中,可以将这段区间中相同的元素同时变成\(c\),但要付出的代价是区间中等于\(c\)的数的个数,设\(sum[i]\)表示等于\(c\)数字的前缀和,Max[i] ...
- (codeforces 853A)Planning 贪心
Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n ...
- cf 12C Fruits(贪心【简单数学】)
题意: m个水果,n个价格.每种水果只有一个价格. 问如果给每种水果分配价格,使得买的m个水果总价格最小.最大. 输出最小值和最大值. 思路: 贪心. 代码: bool cmp(int a,int b ...
- CF 161B Discounts(贪心)
题目链接: 传送门 Discounts time limit per test:3 second memory limit per test:256 megabytes Description ...
随机推荐
- Java MD5加密算法工具类
MD5.java package util; import java.security.MessageDigest; import java.security.NoSuchAlgorithmExcep ...
- C#获取Honeywell voyager 1400g扫码后的数据
一.在类方法中加入 System.IO.Ports.SerialPort com;二.在构造方法中加入 try { com = new System.IO.Ports.SerialPort(&qu ...
- 安装软件出现缺少vcruntime140dll的解决方法
转自:http://jingyan.baidu.com/article/49711c617e4000fa441b7c92.html 首先下载vc++2015,注意自己系统是32位还是64位的,下载对应 ...
- php 递归
function digui($data,$j=0,$lev=0){ $subs=array();//存放子孙数组 foreach ($data as $v){ if ($v['parent_id'] ...
- 《TensorFlow实战》中AlexNet卷积神经网络的训练中
TensorFlow实战中AlexNet卷积神经网络的训练 01 出错 TypeError: as_default() missing 1 required positional argument: ...
- Python_装饰器、迭代器、生成器
一.装饰器 装饰器的存在是为了实现开放封闭原则: 封闭: 已实现的功能代码块不应该被修改: 开放: 对现有功能的扩展开放. 理解装饰器的三要素: 函数的作用域 高阶函数 闭包 1. 闭包 闭包定义:如 ...
- Nginx读书笔记
... upstream proxy_svrs { server http://192.168.1.1:8001/uri/; server http://192.168.1.2:8001/uri/; ...
- jQuery编码中的一些技巧
缓存变量 DOM遍历是昂贵的,所以尽量将会重用的元素缓存. // 糟糕 h = $('#element').height(); $('#element').css('height',h-20); // ...
- python面试题Python2.x和Python3.x的区别
所属网站分类: 面试经典 > python 作者:外星人入侵 原文链接: http://www.pythonheidong.com/blog/article/22/ 来源:python黑洞网 w ...
- day 71 Django基础六之ORM中的锁和事务
Django基础六之ORM中的锁和事务 本节目录 一 锁 二 事务 三 xxx 四 xxx 五 xxx 六 xxx 七 xxx 八 xxx 一 锁 行级锁 select_for_update(no ...