HDU4132 noj[1304] BJF: How Far Can Drive At Most 区间叠加 计算和 超级帅的题目
2013-05-06 00:22
393 查看
[1304] BJF: How Far Can Drive At Most
时间限制: 1000 ms 内存限制: 65535 K问题描述
Now I am going to drive on a street. The street is a straight line. It will cost me one unit oil per meter. And my car can contain V units at most. Unfortunately some zones of the street have been damaged badly. The number of damaged zones is Q. One zone
is represented as (l, r, C), means the zone between l to r is damaged, and it will cost me another C units of oil per peter. Please notice that zones may intersect. My question is how far can I drive at most.
输入
Several cases(cases <= 10). The first line is the case number T. Then T cases follow. For each case : First line two integers l (indicating the length of the street) and V (indicating the amount of oil my car can contain at most when I start)(1 <= len,
V <= 10 ^ 9). Second line of each case is an integer Q (0 <= Q <= 50000). Then Q lines follow, each with three integers (l, r, C), means the zone between l to r has been damaged and it will cost me another C units of oil per meter(1 <= l < r <= len, 1 <= C
<= 100).
输出
For each case, print the farthest I can drive, and output it with exactly two digits after the decimal point.
样例输入
2 100 100 2 10 20 5 10 30 14 1000 10000 3 10 20 4 10 30 14 10 15 5
样例输出
14.50 1000.00
提示
无
来源
加多宝凉茶
http://acm.hdu.edu.cn/showproblem.php?pid=4132 http://acm.nbut.cn:8081/Problem/view.xhtml?id=1304
题意:
有一条直线街道,因为有些区段有着不同程度的损坏,导致通过的车辆会消耗不同的油量。在没损坏的路上行驶是每米消耗 1 单位的油。
现在给出街道的总长 l 和总油量 v ,以及给出
Q 组损坏区间的耗油量(每米)。如果区间有重叠,则耗油量应该累加计算。
你需要计算出在这 v 单位的油量下,从原点出发最多行驶多少米
思路:
先拆分区间再对区间排序,逐个处理加判断
具体看代码
#include<stdio.h>
#include<algorithm>
using namespace std;
struct NODE
{
int pos;
int cost;
bool operator < (const NODE &aa) const
{
return pos < aa.pos;
}
}a[2*50000+2];
int n,len,cnt;
double v;
void solve()
{
int i,j;
double cost=0;
i=0;
while(i<cnt)
{
j=i;
while(j<cnt)
{
if(a[i].pos!=a[j].pos) break;
cost+=a[j].cost;
j++;
}
if(v-(a[j].pos-a[i].pos)*cost<=0)
{
printf("%.2lf\n",a[i].pos+v/cost);
return ;
}
v=v-(a[j].pos-a[i].pos)*cost;
i=j;
}
printf("%.2lf\n",(double)a[cnt-1].pos);
}
int main()
{
int cas;
scanf("%d",&cas);
while(cas--)
{
int left,right,c;
cnt=0;
scanf("%d %lf",&len,&v);
scanf("%d",&n);
int i;
a[cnt].pos=0;
a[cnt].cost=1;
cnt++;
for(i=0;i<n;i++)
{
scanf("%d %d %d",&left,&right,&c);
a[cnt].pos=left;
a[cnt].cost=c;
cnt++;
a[cnt].pos=right;
a[cnt].cost=-c;
cnt++;
}
a[cnt].pos=len;
a[cnt].cost=-1;
cnt++;
sort(a,a+cnt);
// for(i=0;i<cnt;i++)
// printf("%d\n",a[i].pos);
solve();
}
return 0;
}
相关文章推荐
- 区间损坏HDU4132 noj[1304] BJF: How Far Can Drive At Most 区间叠加 计算和 超级帅的题目
- hdu4588前缀 分区间计算
- Vijos 题目P1083小白逛公园(线段树,区间连续最大和)
- Codevs 题目1690 开关灯(线段树区间异或)
- BZOJ 题目3211: 花神游历各国(线段树区间减为平方根,区间求和)
- 题目1000:计算a+b
- 机器学习2016重大进展全盘点:超级计算成为主流,深度学习框架领域充满活力
- 编程之美---超级水王扩展题目
- 五十道编程小题目 --- 50 有五个学生,每个学生有3门课的成绩,计算出平均成绩,况原有的数据和计算出的平均分数存放在磁盘文件"stud"中java
- 计算几何题目整理(转)
- Java代码题目:计算奖金和完全平方数
- 叠加计算出错的解决方法
- Kaggle题目:用Random Forrest算法计算Titanic沉船事故人员生还状况
- [J] Dumb Typo(题目很简单,比赛错在不该自己计算,应该用电脑跑一遍的)
- 计算几何题目推荐(转)
- CCF CSP 编程题目和解答-----试题名称:日期计算-------201509-2
- NOJ 题目1642 简单的图论问题?(BFS)
- 刷题第四天:南邮NOJ【1010数的计算】
- 计算客 商品推荐走马灯(简单)(求区间全部连续的回文串价值)
- 计算几何题目列表——第一章