参考代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<sstream>
#include<string>
#include<bitset>
using namespace std;
typedef long long LL;
const LL LINF = (1LL <<63);
const int INF = 1 << 31;
const int NS = 1010;
const int MS = 19;
const int MOD = 1000000007;
const double eps = 1e-8;
bool isequal(double xa, double xb)
{
return bool(fabs(xa - xb) < eps);
}
struct node{
int id;
double x,y,v;
void print()
{
printf("ID:%2d (%.2lf, %.2lf, %.2lf)\n", id, x, y, v);
}
}c[NS];
node p[NS];
double t[NS];
double ans[NS];
int n;
bool cmpx(node ca, node cb)
{
return ca.x > cb.x;
}
bool cmpy(node ca, node cb)
{
if(!isequal(ca.y, cb.y))
return ca.y < cb.y;
return ca.x > cb.x;
}
int getPos(double* p, int st, int len)
{
return 0;
}
int main()
{
#ifndef ONLINE_JUDGE
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
#endif
int nCase = 0;
while(~scanf("%d", &n))
{
for(int i = 0; i < n; i++)
{
c[i].id = i;
scanf("%lf %lf %lf", &c[i].x, &c[i].y, &c[i].v);
p[i].id = c[i].id;
p[i].x = c[i].x;
p[i].y = c[i].y;
p[i].v = c[i].v;
t[i] = 0;
}
sort(p, p+n, cmpy);
sort(c, c+n, cmpx);
double curpos;
for(int i = 0; i < n; i++)
{
double v = c[i].v;
curpos = c[i].x;
double ti = 0;
for(int j = 0; j < n; j++)
{
if(p[j].y <= c[i].x) continue ;
ti += (p[j].y - curpos) / v;
ti = max(t[j], ti);
t[j] = ti;
//t[j]记录位置大于等于x[i]的点到达p[j].y的时间最大值
if(p[j].id == c[i].id)
{
ans[c[i].id] = t[j];
break;
}
curpos = p[j].y;
}
}
// printf("case:%d\n", ++nCase);
for(int i = 0; i < n; i++)
{
printf("%.2lf\n", ans[i]);
}
}
return 0;
}