G - Traffic Management(模拟)

本文探讨了在理想化的无限直线路段上,多辆汽车以不同初始位置和速度行驶时,如何计算最后一次车辆碰撞发生的时间。通过设计算法,采用结构体存储车辆信息,并按位置逆序排列,实现对碰撞事件的高效预测。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Sancho was making a road trip with his family and got really bored, so he recorded the position and initial speed of every car on the highway. For Sancho, the highway is an infinite straight line, the starting time is 0, the cars are moving points, and no car will pass another car (Sancho is very idealistic).

The cars maintain their initial speed unless they are slowed down by other cars. Car A is slowed down by car B if B started in front of A, but after a while, A reached B. When this happens, both cars move together and A's speed becomes the same as B's.

Sancho knows that there will be only a finite amount of times that a car will be slowed down by another car, and wants to know when the last slowing down will take place. If no car will be slowed down, the answer is 0.

Input

The first line of the input contains a single integer N (1 ≤ N ≤ 105), indicating the number of cars.

N lines follow. The i-th line contains two integers Si and Vi (0 ≤ S, V ≤ 109), indicating the starting position of the i-th car and its speed. No two cars start in the same position.

Output

Output a single decimal number - the time of the last slow down. Your answer will be considered correct if the absolute or relative error is no greater than 10 - 4.

Namely: let's assume that your answer is a, and the official answer is b. The checker program will consider your answer correct, if .

Example

Input

4
0 10
10 3
20 3
30 2

Output

20.000000

题目大意:给出n个车的位置和速度,车和车之间会发生碰撞,碰撞会两个车合为一个,以速度小的那辆车的速度继续行驶,问最后一次发生碰撞的时间是多少

思路概括:用一个结构体将所有车的位置从大到小排好,然后依次遍历,如果开始的车速度比下一辆车的速度大或者相等的话,是不会发生碰撞的,我们就可以忽略这个车,如果下一辆车的速度比现在车的速度小的话,就会发生碰撞,我们就可以计算时间并取出最大值。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define lt k<<1
#define rt k<<1|1
using namespace std;
typedef long long ll;
typedef long double ld;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mem(a, b) memset(a, b, sizeof(a))
const double pi = acos(-1.0);
const double eps = 1e-6;
const ll mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 1e6 + 5;
struct node
{
    ll l, v;
}s[maxn];

bool cmp(node a, node b)
{
    if(a.l != b.l)
    {
        return a.l > b.l;
    }
}
int main()
{
    int n;
    scanf("%d", &n);
    for(int i=0;i<n;i++)
    {
        scanf("%lld %lld", &s[i].l, &s[i].v);
    }
    sort(s, s+n, cmp);
    double ans = 0.0;
    int tot = 0;
    for(int i=0;i<n;i++)
    {
        if(s[i].v <= s[tot].v) tot = i;
        else
        {
            ans = max(ans, 1.0 * (s[tot].l - s[i].l)/(s[i].v - s[tot].v));
        }
    }
    printf("%.6f\n", ans);
    return 0;
}

 

根据以下log,编写一段代码,提取出每个用例RPC操作的节点全称。Test cdrouter-1663: Verify Device:1 AutonXferComplPolicy Profile using GetParameterNames from top level Module: Device1_profiles.tcl Name: Device1_AutonXferComplPolicy_gpn_1 Description: step 1. Initiate a GetParameterNames on the top level object for the profile with NextLevel = false step 2. Verify all returned names against the profile definition step 3. Fail the test if any required parameters are missing References: BBF CWMP Data Model Device:1.14 Root Data Model "TR-181 Issue 1 Amendment 7" https://cwmp-data-models.broadband-forum.org/tr-181-1-7-0.html ------ INFO(cdrouter-1663): DHCP uses Connect-On-Demand, initiating LAN traffic INFO(cdrouter-1663): Starting test Device1_AutonXferComplPolicy_gpn_1 (1663) INFO(cdrouter-1663): Starting CWMP Profile verification test on AutonXferComplPolicy:1 SECTION(cdrouter-1663): Starting GetParameterNames on Device.ManagementServer.AutonomousTransferCompletePolicy. INFO(acs): Starting TR-069 GetParameterNames method FAIL: GetParameterNames failed due to a SOAP Fault 9005 FAIL: FaultString 'Invalid parameter name' SECTION(cdrouter-1663): Test Device1_AutonXferComplPolicy_gpn_1 (1663) has finished. Beginning test clean-up FAIL: Test Device1_AutonXferComplPolicy_gpn_1 (1663) failed Test cdrouter-1668: Verify Device:1 AutonXferComplPolicy Profile using GetParameterValues for all GetParameterNames full paths Module: Device1_profiles.tcl Name: Device1_AutonXferComplPolicy_gpn_and_gpv_7 Description: step 1. Initiate a GetParameterNames on the top level object for the profile with NextLevel = false step 2. Verify all returned names against the profile definition step 3. Fail the test if any required parameters are missing step 4. For each full parameter name, execute a GetParameterValues step 5. Verify all GetParameterValue RPCs succeeed References: BBF CWMP Data Model Device:1.14 Root Data Model "TR-181 Issue 1 Amendment 7" https://cwmp-data-models.broadband-forum.org/tr-181-1-7-0.html ------ INFO(cdrouter-1668): DHCP uses Connect-On-Demand, initiating LAN traffic INFO(cdrouter-1668): Starting test Device1_AutonXferComplPolicy_gpn_and_gpv_7 (1668) INFO(cdrouter-1668): Starting CWMP Profile verification test on AutonXferComplPolicy:1 SECTION(cdrouter-1668): Starting GetParameterNames on Device.ManagementServer.AutonomousTransferCompletePolicy. INFO(acs): Starting TR-069 GetParameterNames method FAIL: GetParameterNames failed due to a SOAP Fault 9005 FAIL: FaultString 'Invalid parameter name' SECTION(cdrouter-1668): Test Device1_AutonXferComplPolicy_gpn_and_gpv_7 (1668) has finished. Beginning test clean-up FAIL: Test Device1_AutonXferComplPolicy_gpn_and_gpv_7 (1668) failed
07-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值