Problem G. Pulp Fiction-Gym 100345G-贪心
2015-08-17 21:51
381 查看
要写n本书,要求平均时间最小,即∑ci 最小
对每本书,判断 在 下一次得到思路之前能否写完,能则写完(得到较小的ci),否则写到下一次思路出现,判断开始是 继续写比较优,还是开始写下一本书比较优。一直到n-1本书都进丢列了,然后把第n本插入队列 ,把队列中的书全部取出即可
对每本书,判断 在 下一次得到思路之前能否写完,能则写完(得到较小的ci),否则写到下一次思路出现,判断开始是 继续写比较优,还是开始写下一本书比较优。一直到n-1本书都进丢列了,然后把第n本插入队列 ,把队列中的书全部取出即可
#include <cstdio> #include <cmath> #include <cstring> #include <string> #include <algorithm> #include <iostream> #include <queue> #include <map> #include <set> #include <vector> using namespace std; #define INF 0x7f7f7f7f const __int64 maxn = 100005; struct node { __int64 x,day; bool operator < (const node &b )const { return day>b.day; } }; node tm[maxn]; priority_queue <node> qq; __int64 cmp(node a,node b) { return a.x<b.x; } int main() { freopen( "pulp.in","r",stdin ); //scanf 从1.txt输入 freopen( "pulp.out","w",stdout ); //printf输出到1.tx __int64 n,i; scanf("%I64d",&n); for (i=1;i<=n;i++) { scanf("%I64d%I64d",&tm[i].x,&tm[i].day); } sort(tm+1,tm+1+n,cmp); __int64 now=tm[1].x; __int64 ans=0; for (i=1;i<n;i++) { qq.push(tm[i]); while(now<tm[i+1].x) { if (!qq.empty()) { node tmp=qq.top(); qq.pop(); if (tmp.day<=tm[i+1].x-now) { now+=tmp.day; ans+=now; } else { tmp.day-=(tm[i+1].x-now); now=tm[i+1].x; qq.push(tmp); } } else { now=tm[i+1].x; } } } qq.push(tm ); while(!qq.empty()) { node tmp=qq.top(); qq.pop(); now+=tmp.day; ans+=now; } printf("%I64d\n",ans); return 0; }
相关文章推荐
- 基于Android2.3的车载导航---andorid GPS HAL的移植与分析(by liukun321咕唧咕唧)
- Apache 启动失败 VisualSvn 端口占用问题
- iOS开发需要学习哪些内容?
- java基础及多线程
- static静态初始化块
- Javascript关闭详细说明
- POJ 3762 The Bonus Salary!(费用流)
- 【索引】Geometric Computations in 2D:Exercises: Beginner
- java内存管理:垃圾回收机制
- UVA 12657 Boxes in a Line
- 白话经典算法-快速排序
- 前缀表达式求值
- SecureCRT登录Linux出现中文乱码问题
- 形参和实参 (F#)
- 数据结构--赫夫曼树(最优二叉村)
- 67 Add Binary
- 2015年8月17日工作日志------------------赵鑫
- 文件锁-FileLock
- 《Linux Device Drivers》第十一章 核心数据类型——note
- 系统调用与库函数调用的区别