HDU-2273 The buses
来源:互联网 发布:香港代购mac口红多少钱 编辑:程序博客网 时间:2024/05/01 00:14
The buses
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 659 Accepted Submission(s): 173
Total Submission(s): 659 Accepted Submission(s): 173
Problem Description
Garfield applied for a good job recently, and he will go to work soon by car or bus. Garfield is very broody, sometimes when he sits on the bus to wait for the traffic light, he thinks about how long all the buses pass the traffic turning.
Now we describe the situations when the buses stop at the traffic turning to wait for the traffic light. First the light is red, then when the light changes to green, all the buses are prepared to move. And at the beginning, all the buses are close to each other without any space, and they have different lengths and the largest speeds. We assume any car can reach the speed that isn’t beyond the maximal speed at once.
Now Garfield wants you to calculate minimal time all the buses pass the turning.
Now we describe the situations when the buses stop at the traffic turning to wait for the traffic light. First the light is red, then when the light changes to green, all the buses are prepared to move. And at the beginning, all the buses are close to each other without any space, and they have different lengths and the largest speeds. We assume any car can reach the speed that isn’t beyond the maximal speed at once.
Now Garfield wants you to calculate minimal time all the buses pass the turning.
Input
There are many cases. For each case, there is two intergers N(1<=N<=100), representing the number of the buses. There are two interges in the following N lines, for the length Li(meter, 1<=Li<=10) and the maximal speed Si(meter/second, 1<=Si<=10) of the i-th bus.
Output
For each case, print the result obtaining two digits after the decimal point.
SampleInput
21 22 3
SampleOutput
1.50
水题:
第一次以组队的形式参加组队赛,
感谢盛巨巨提供的代码。
思路如下:
此题关键点,决定整体时间的是速度最小的那辆车。
若速度最小的车排在最后,所经过的路程最长(多出全部的车长),时间最长。
所以最小的车应放在第一位,时间即总车长/最小速度;
还是用了结构体来存储数据(原谅我提的想法),其实还可以更加简单点的。
代码如下
#include <iostream>#include <stdio.h>#include <algorithm>using namespace std;struct Node{int len;int v;}bus[101];bool cmp(Node a,Node b){ return a.v<b.v;}int main(){ int n,i; double s; while(cin>>n) { s=0; for(i=0;i<n;i++) { cin>>bus[i].len; cin>>bus[i].v; } sort(bus,bus+n,cmp); for(i=0;i<n;i++) { s+=bus[i].len; } printf("%.2lf\n",s/bus[0].v); } return 0;}
0 0
- HDU-2273 The buses
- hdoj-2273-The buses
- PKU1167 the buses
- poj 1167 The Buses
- POJ 1167 The Buses
- poj 1167 the buses
- HDU2273-The buses
- POJ 1167 The Buses 笔记
- IOI 1994 169:The Buses
- Buses
- 【搜索+强剪枝】PKU-1167-The Buses
- The Buses (poj 1167 搜索)
- POJ 1167 The Buses 暴搜+剪枝
- Address Lines and Buses
- CF D. Buses
- Shared buses vs NoCs
- CF 101B - Buses
- cf459C Pashmak and Buses
- 【JZOJ3870】【NOIP2014八校联考第4场第1试10.19】单词检索(search)
- 文件编程示例
- c#中decimal ,double,float的区别
- 分解和合并:Java 也擅长轻松的并行编程!
- Struts2学习之3(文件的上传下载,OGNL表达式,常用标签,表单重复提交)
- HDU-2273 The buses
- 读Linux源码分析ov5640在三星exynos4412平台上的使用
- 机器学习数据集
- 2017
- java之线程池简单实现
- 开博客,庆祝!(蜂鸣器马里奥)(测试)
- github安装失败
- Firebug: 已拦截跨源请求:同源策略禁止读取位于XXX的远程资源。(原因:CORS 头缺少 'Access-Control-Allow-
- 素数判定