时间限制:10000ms
单点时限:1000ms
内存限制:256MB
描述
In the city, there is a one-way straight highway starts from the northern end, traverses the whole city southward, and finishes at the southern end. Due to some financial difficulties, there is only one lane on this highway, which means that overtaking other cars in front is impossible.
The highway is quite busy. Lots of different cars are running on it every day. For each car, it is running on the highway at the point which X km far from the northern end in Minute 0, and will leave at the point which Y km far from the northern end. Each car also has a speed limit L km/min. During the whole trip on the highway, each car should run as fast as possible without exceeding its speed limit or overtaking other cars in front. In addition, no two or more cars will be at the same point at Minute 0. Cars can be regarded as points and the distance between two cars can be infinitely small.
Given the information of N cars, please calculate the leaving time for each car.
输入
The first line contains one integer N. 2 <= N <= 1000.
Then follows N line. Each line contains three integers X, Y and L, showing the information of this car. 0 <= X < Y <= 1000000, 0 < L <= 10.
输出
Output N real numbers, one per line – the leaving time (in minute) of each car, preserving the input order of cars. Your answers should be rounded to 2 digits after the decimal point and the output must contain exactly 2 digits after the decimal point.
样例输入
3
3 5 1
1 4 2
0 8 3
样例输出
2.00
1.50
3.00
#include "iostream"
#include "algorithm"
#include "string.h"
#include "stdio.h"
using namespace std;
#define max(a, b) a > b ? a : b
int N;
int p[1001];
double t[1001];
struct Node
{
int x, y, v;
double ans;
int id;
bool operator < (const Node &node) const //按x从大到小排
{
return x > node.x;
}
};
bool cmp(const Node &node1, const Node &node2) //按id从小到大排
{
return node1.id < node2.id;
}
Node node[1001];
int main()
{
cin >> N;
int i = 0;
for(i=0; i<N; i++)
{
cin >> node[i].x >> node[i].y >> node[i].v;
node[i].id = i;
p[i] = node[i].y;
}
memset(t, 0, sizeof(t));
sort(p, p + N);
sort(node, node + N);
for(i=0; i<N; i++) //x[i]从大到小
{
double tt = 0;
int now = node[i].x;
for(int j=0; j<N; j++)
{
if(p[j] > node[i].x)
{
tt += (double)(p[j] - now) / node[i].v;
tt = max(tt, t[j]);
t[j] = tt;
if(p[j] == node[i].y)
{
node[i].ans = tt;
break;
}
now = p[j];
}
}
}
sort(node, node+N, cmp);
for(i=0; i<N; i++)
printf("%.2lf\n", node[i].ans);
return 0;
}