l_migrant
2021-09-21 20:42
采纳率: 100%
浏览 53

在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;
    }
    
    

    句号肯定不行呀

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题