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 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么