l_migrant 2021-09-21 20:42 采纳率: 83.3%
浏览 55
已结题

在oj平台中,为什么double time = (4500 / (v * 10.0 / 36.0))可以通过,而double time = (4500 / (v * 1.0 / 3.6))不能通过

oj上为 G++(5.3)
题目:
2404:Ride to Office
查看提交统计提问
总时间限制: 1000ms 内存限制: 65536kB
描述
Many staff of are living in a place called MZone, far from their office( 4.5 km ). Due to the bad traffic, many staff choose to ride a bike.

We may assume that all the people except "Weiwei" ride from home to office at a fixed speed. Weiwei is a people with a different riding habit – he always tries to follow another rider to avoid riding alone. When Weiwei gets to the gate of MZone, he will look for someone who is setting off to the Office. If he finds someone, he will follow that rider, or if not, he will wait for someone to follow. On the way from his home to office, at any time if a faster student surpassed Weiwei, he will leave the rider he is following and speed up to follow the faster one.

We assume the time that Weiwei gets to the gate of MZone is zero. Given the set off time and speed of the other people, your task is to give the time when Weiwei arrives at his office.
输入
There are several test cases. The first line of each case is N (1 <= N <= 10000) representing the number of riders (excluding Weiwei). N = 0 ends the input. The following N lines are information of N different riders, in such format:

Vi [TAB] Ti

Vi is a positive integer <= 40, indicating the speed of the i-th rider (kph, kilometers per hour). Ti is the set off time of the i-th rider, which is an integer and counted in seconds. In any case it is assured that there always exists a nonnegative Ti.
输出
Output one line for each case: the arrival time of Weiwei. Round up (ceiling) the value when dealing with a fraction.
样例输入
4
20 0
25 -155
27 190
30 240
2
21 0
22 34
0
样例输出
780
771


#include <cstdio>
#include <iostream>
using namespace std;
int n,v,t;
int main()
{
    while(cin >> n)
    {
        if(n == 0)    break;
        int ans = 999999,s = 0;
        for(int i = 1; i <= n; i++)
        {
            scanf("%d%d",&v,&t);
            if(t >= 0)
            {
                double time = (4500 / (v * 10.0 / 36.0));
                if(time - (int) time > 0.0)        time++;
                s = time + t;
                if(ans > s)        ans = s;
            }
        }
        printf("%d\n",ans);
    }
}
  • 写回答

1条回答 默认 最新

  • uyoj661 2021-09-21 21:25
    关注

    仅供参考

    
    
    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<algorithm>
    #define INF 999999999
    #define N 10001
    using namespace std;
    struct node{
        int v;
        int start;
        int endd;
    }a[N];
    int main()
    {
        int n;
        int t;
     
        while(cin>>n&&n)
        {
            for(int i=1;i<=n;i++)
            {
                cin>>a[i].v>>a[i].start;
                t=16200/a[i].v;
                if(16200.0/a[i].v>t)
                    t++;
                a[i].endd=a[i].start+t;
            }
            int min=INF;
            for(int i=1;i<=n;i++)
                if(a[i].start==0&&a[i].endd<min)
                    min=a[i].endd;
            for(int i=1;i<=n;i++)
                if(a[i].start>0&&a[i].endd<min)
                    min=a[i].endd;
            cout<<min<<endl;
        }
        return 0;
    }
    
    

    句号肯定不行呀

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 10月6日
  • 已采纳回答 9月28日
  • 修改了问题 9月22日
  • 修改了问题 9月22日
  • 展开全部

悬赏问题

  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题
  • ¥15 github训练的模型参数无法下载
  • ¥15 51单片机显示器问题
  • ¥20 关于#qt#的问题:Qt代码的移植问题
  • ¥50 求图像处理的matlab方案
  • ¥50 winform中使用edge的Kiosk模式
  • ¥15 关于#python#的问题:功能监听网页
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题