题意:有n个任务,每个任务必须在在时刻[r, d]之内执行w的工作量(三个变量都是整数)。处理器执行的速度可以变化,当速度为s时,一个工作量为w的任务需要 执行的时间为w/s个单位时间。另外不一定要连续执行,可以分成若干块。求处理器在执行过程中最大速度的最小值。处理器速度为任意的整数值。
思路:起初的思路是整体贪心,就是把某个区间的任务量累加,然后对于当前区间能否满足限制速度,但是这样难以实现。第二个思路就是,对于某个时刻处理最快结束的(即右端点最小的),这显然是当前最优的选择。

代码:

#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn=1e4+10;
struct node
{
int l,r,w;
bool operator <(const node&aa)const
{
return r>aa.r;
}
}a[maxn];
int n;
bool cmp(node aa,node b)
{
return aa.l<b.l;
}
bool ok(int m)
{
priority_queue<node> q;
while(!q.empty())q.pop();
int t=1,pos=0;
while(!q.empty()||pos<n)
{
while(pos<n&&a[pos].l<t)q.push(a[pos++]);
int speed=m;
while(!q.empty()&&speed)
{
node now=q.top();q.pop();
if(now.r<t)return false;
if(speed>=now.w)speed-=now.w;
else
{
now.w-=speed;
q.push(now);
break;
}
}
t++;
}
return q.empty();
}
int main()
{
int t;
cin>>t;
while(t--)
{
cin>>n;
for(int i=0;i<n;i++)cin>>a[i].l>>a[i].r>>a[i].w;
sort(a,a+n,cmp);
int l=1,r=100000;
while(r>l)
{
int m=(l+r)/2;
if(ok(m))r=m;
else l=m+1;
//cout<<l<<" "<<r<<endl;
}
cout<<l<<endl;
}
system("pause");
return 0;
}

  

uva1422 二分法+优先队列贪心的更多相关文章

  1. 最高的奖励 - 优先队列&贪心 / 并查集

    题目地址:http://www.51cpc.com/web/problem.php?id=1587 Summarize: 优先队列&贪心: 1. 按价值最高排序,价值相同则按完成时间越晚为先: ...

  2. POJ2431 优先队列+贪心 - biaobiao88

    以下代码可对结构体数组中的元素进行排序,也差不多算是一个小小的模板了吧 #include<iostream> #include<algorithm> using namespa ...

  3. hdu3438 Buy and Resell(优先队列+贪心)

    Buy and Resell Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  4. ZOJ-3410Layton's Escape(优先队列+贪心)

    Layton's Escape Time Limit: 2 Seconds      Memory Limit: 65536 KB Professor Layton is a renowned arc ...

  5. CodeForces - 853A Planning (优先队列,贪心)

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

  6. poj2431(优先队列+贪心)

    题目链接:http://poj.org/problem?id=2431 题目大意:一辆卡车,初始时,距离终点L,油量为P,在起点到终点途中有n个加油站,每个加油站油量有限,而卡车的油箱容量无限,卡车在 ...

  7. H - Expedition 优先队列 贪心

    来源poj2431 A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Being ...

  8. 1350: To Add Which? (优先队列+贪心 或者 数组模拟)

    1350: To Add Which? Submit Page    Summary    Time Limit: 1 Sec     Memory Limit: 128 Mb     Submitt ...

  9. 牛客网 桂林电子科技大学第三届ACM程序设计竞赛 C.二元-K个二元组最小值和最大-优先队列+贪心(思维)

    链接:https://ac.nowcoder.com/acm/contest/558/C来源:牛客网 小猫在研究二元组. 小猫在研究最大值. 给定N个二元组(a1,b1),(a2,b2),…,(aN, ...

随机推荐

  1. pat1049. Counting Ones (30)

    1049. Counting Ones (30) 时间限制 10 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The task ...

  2. Reactor Pattern and Non-blocking IO--reference

    reference from:http://www.cs.bgu.ac.il/~spl051/Personal_material/Practical_sessions/Ps_12/ps12.html ...

  3. 零基础逆向工程28_Win32_02_事件_消息_消息处理函数

    1 第一个图形界面程序 步骤1:创建Windows应用程序 选择空项目 步骤2:在新建项窗口中选C++代码文件 创建一个新的cpp文件 步骤3:在新的cpp文件中添加:#include <Win ...

  4. C#利用WebClient 两种方式下载文件(一)

    WebClient client = new WebClient(); 第一种 string URLAddress = @"http://files.cnblogs.com/x4646/tr ...

  5. [opencv3.2cmake error ] sys/videoio.h no such file or directories

    I don't have /usr/include/sys/videoio.h at all Before that , I have ipp download question. So I down ...

  6. apache日志设置

    转自:http://hi.baidu.com/bxhack/item/71025d3e65987d88b611db5e apache日志存放位置 Windows: <Apache安装目录> ...

  7. hihocoder 1093 SPFA算法

    题目链接:http://hihocoder.com/problemset/problem/1093 , 最短路的SPFA算法. 由于点的限制(10w),只能用邻接表.今天也学了一种邻接表的写法,感觉挺 ...

  8. pat乙级1045

    从左到右扫描时记录扫描到当前下标为止的最大值,如果当前元素大于这个最大值,那么它就大于它左边的所有值.同理,从右到左扫描记录扫描到当前下标为止的最小值,如果当前元素小于这个最大小值,那么它就小于它右边 ...

  9. Problem C: 动态规划基础题目之数字三角形

    Problem C: 动态规划基础题目之数字三角形 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 208  Solved: 139[Submit][Sta ...

  10. ASP.NET各种技巧

    1.动态添加文件框 前台页面关键部分: <script type="text/javascript"> //添加一个选项 function AddFileCtrol() ...