题面:

传送门

思路:

一眼看得,这是贪心【雾】

实际上,我们要求的答案就是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 [贪心]的更多相关文章

  1. CF 115B Lawnmower(贪心)

    题目链接: 传送门 Lawnmower time limit per test:2 second     memory limit per test:256 megabytes Description ...

  2. CF Soldier and Badges (贪心)

    Soldier and Badges time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  3. CF Anya and Ghosts (贪心)

    Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  4. cf 853 D Michael and Charging Stations [dp]

    题面: 传送门 思路: 看到题目,第一思路是贪心,但是我很快就否决掉了(其实分类贪心也可以做) 然后就想,贪心不能解决的状态缺失,是否可以用dp来解决呢? 事实证明是可以的 我们设dp[i][j]表示 ...

  5. #433 Div2 Problem C Planning (贪心 && 优先队列)

    链接 : http://codeforces.com/contest/854/problem/C 题意 : 有 n 架飞机需要分别在 1~n 秒后起飞,允许起飞的时间是从 k 秒后开始,给出每一架飞机 ...

  6. CF 1082E Increasing Frequency(贪心)

    传送门 解题思路 贪心.对于一段区间中,可以将这段区间中相同的元素同时变成\(c\),但要付出的代价是区间中等于\(c\)的数的个数,设\(sum[i]\)表示等于\(c\)数字的前缀和,Max[i] ...

  7. (codeforces 853A)Planning 贪心

    Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n ...

  8. cf 12C Fruits(贪心【简单数学】)

    题意: m个水果,n个价格.每种水果只有一个价格. 问如果给每种水果分配价格,使得买的m个水果总价格最小.最大. 输出最小值和最大值. 思路: 贪心. 代码: bool cmp(int a,int b ...

  9. CF 161B Discounts(贪心)

    题目链接: 传送门 Discounts time limit per test:3 second     memory limit per test:256 megabytes Description ...

随机推荐

  1. fifo - 先进先出的特殊文件, 又名管道

    描述 (DESCRIPTION) 一个 FIFO 特殊 文件 (又名 管道) 同 管道线 相似, 但是 它是 作为 文件 系统 的一部分 访问的. 可以 有 多个 进程 打开它 以供 读写. 当 进程 ...

  2. axiospost请求向后端提交数据

    Axios向后端提交数据容易接收不到原因是传参方式是request payload,参数格式是json,而并非用的是form传参,所以在后台用接收form数据的方式接收参数就接收不到了.post表单请 ...

  3. 【转】【win网络编程】socket中的recv阻塞和select的用法

    在编写ftp客户端程序时,在联通后使用recv函数进行接收欢迎信息时,需要申请内存进行接收数据保存,一次读取成功,但是由于一个随机的ftp服务端在说,欢迎信息的大小是不知道的,所以在尝试使用死循环,在 ...

  4. jquery/js/a标签实现当前页面跳转的两种方法

    在逛购物网站首页时经常看到侧边导航栏,当我们点击导航栏中某一项时会跳转到当前页面的某一处 有两种方法实现,一种是利用js计算好各位置的高度,通过绑定事件使页面跳转到指定位置,另一种是利用a标签进行当前 ...

  5. php - 去除php代码中的多余空格

    <?php class Test{ public function test(){ $tmplContent = file_get_contents('./test.php'); $tmplCo ...

  6. Python知识点进阶——细节问题

    int()强制转换浮点数 在int()的强制转换浮点数时候,不管是正数还是负数,只取整数部分. 注意:这里不是向上或者向下取整,也不是四舍五入. 无限递归 递归是为了将问题简化为更小规模的同类型问题, ...

  7. Android系统中标准Intent的使用

    Android系统用于Activity的标准Intent 1.根据联系人ID显示联系人信息= Intent intent=new Intent(); intent.setAction(Intent.A ...

  8. Python学习笔记:math模块(数学),random模块(随机数)

    math模块 math模块用于数学意义上的一些计算,常用的方法有: math.pi:PI的值(3.141592653589793). math.floor(x):返回一个小于等于x的最大整数(浮点类型 ...

  9. linux-最最最最最常用的操作

    去除两个文件中相同的内容 比如我想把file1中不含文件file2的内容保留下来:(这个在抠一些内容的时候挺好用的) awk '{print $0}' file1 file2 |sort|uniq - ...

  10. 笔记-python-tutorial-8.errors and exceptions

    笔记-python-tutorial-8.errors and exceptions 1.      errors and exceptions 1.1.    syntax errors >& ...