跳到正文

题解

题解:P15639 [ICPC 2022 Tehran R] Flower Festival

Night_Echo约 1 分钟
原文
文章信息与版本

文章信息

收录
2026年3月6日
更新
2026年3月7日
篇幅
约 1 分钟
题目
P15639

版本

  1. v1当前

思路

我们定义一个 double 类型的数组 t[110],来存第 ii 辆车到达玫瑰广场的时间。然后找出最小的 t[i] 对应的车辆编号,就得到答案了。

Code

C++
#include<bits/stdc++.h>
using namespace std;
int n,f;
int id;//车辆编号
double t[110],minn=1e9;//注意minn要初始化成一个很大的数(其实10000就够用了)
int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>f;
    for(int i=1;i<=n;i++){
        int x,v;
        cin>>x>>v;
        t[i]=(double)(f-x)/v;//算出第i辆车到达玫瑰广场的时间
    }
    for(int i=1;i<=n;i++){
        if(t[i]<minn){
            minn=t[i];
            id=i;
        }
    }
    cout<<id;
    return 0;
}
原文