Problem G. Pulp Fiction-Gym 100345G-贪心
来源:互联网 发布:孕妇防辐射服 知乎 编辑:程序博客网 时间:2024/06/06 08:25
要写n本书,要求平均时间最小,即∑ci 最小
对每本书,判断 在 下一次得到思路之前能否写完,能则写完(得到较小的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 0x7f7f7f7fconst __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[n]);while(!qq.empty()){node tmp=qq.top();qq.pop();now+=tmp.day;ans+=now;}printf("%I64d\n",ans);return 0;}
0 0
- Problem G. Pulp Fiction-Gym 100345G-贪心
- Gym 100345G Pulp Fiction 贪心
- 2007-2008 Winter Petrozavodsk Camp, Andrew Stankevich Contest 30-G - Pulp Fiction-贪心+优先队列
- GYM 100488 G.Change-making Problem(贪心)
- gym 100430 G【贪心+map瞎搞】
- Gym 100801G Graph(贪心构造)
- GYM 100030 G.Procrastination(贪心)
- 贪心算法 Problem G 1006
- 贪心算法—Problem G
- Codeforces/gym/100685/problem/G Gadget Hackwrench ( LCA )
- codeforces gym 100548G
- Gym 100269G-Garage
- CodeForces Gym 100735G
- CodeForces Gym 100735G
- Gym 100971G Repair
- Gym 100685G
- Codeforces-GYM-100923G
- Gym 101097G Party
- 漫谈高数 特征向量物理意义
- unity AnimationState和animationclip的区别
- 文件锁-FileLock
- 系统调用与库函数调用的区别
- 2014 ACM/ICPC Asia Regional Beijing Online(hdu5036 概率+bitset优化)
- Problem G. Pulp Fiction-Gym 100345G-贪心
- 形参和实参 (F#)
- 67Add Binary
- 前缀表达式求值
- 白话经典算法-快速排序
- SecureCRT登录Linux出现中文乱码问题
- LeetCode257——Binary Tree Paths
- 数据结构--赫夫曼树(最优二叉村)
- 如何将自定义RPM包加入YUM