l_migrant 2021-09-20 20:49 采纳率: 83.3%
浏览 29
已结题

为什么编译错误,原因是什么,怎么改正?报错信息已贴。(即刻采纳)

报错信息
C:\Users\l_mig\Documents\4.6_2404.cpp In function 'void chase(int)':
76 29 C:\Users\l_mig\Documents\4.6_2404.cpp
[Error] invalid operands of types '' and 'double' to binary 'operator-'

#include <cstdio>
#include <math.h>
#include <iostream>
using namespace std;
const int inf = 0x3f3f3f3f;
int n;
double v[10001],t[10001],s[10001],m[10001],ans,v0,t0,s0;
void chase(int);
void qsort(int,int);
int main()
{
    scanf("%d",&n);
    for(int i = 1; i <= n; i++)
    {
        scanf("%f%f",&v[i],&t[i]);
        v[i] /= 3.6;
        if(t[i] < 0)    s[i] = inf;
        if(!t[i])        v0 = v[i];
    }
    for(int i = 1; i <= n; i++)
    {
        if(v[i] > v0)
        {
            s[i] = v0 * t[i];
            m[i] = s[i] / (v[i] - v[0]);
        }
    }
    qsort(1,n);
    if(s0 + v0 * m[1] < 4500)
    {
        v0 = v[1];    t0 = m[1] + t[1];
        s0 += (v0 * t0);
    }            
    else
    {
        ans = (4500 - s0) / v0;
        cout << ceil(ans);
        return 0;
    }
    for(int i = 2; i<= n; i++)
    {
        chase(i);
        if(s0 + v0 * m[1] < 4500)
        {
            v0 = v[1];    t0 = m[1] + t[1];
            s0 += (v0 * t0);
        }            
        else
        {
            ans = (4500 - s0) / v0;
            cout << ceil(ans);
            return 0;
        }
    }
    
}
void qsort(int l,int r)
{
    int i = l, j = r, mid = (l + r) / 2;
    while(m[i] < m[mid])    i++;
    while(m[j] > m[mid])    j++;
    if(i <= j)
    {
        swap(m[i],m[j]);
        swap(v[i],v[j]);    
    }
    if(i < r)    qsort(i,r);
    if(j > l)    qsort(l,j);
}
void chase(int t)
{
    for(int i = t; i <= n; i++)
    {
        if(v[i] > v0)
        {
            s[i] = distance - v[i] * t0;
            m[i] = s[i] / (v[i] - v0);
        }
    }
    qsort(t,n);
}

原题如下:
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

  • 写回答

1条回答 默认 最新

  • 快乐鹦鹉 2021-09-20 21:01
    关注

    distance 从哪冒出来的?

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 9月22日
  • 创建了问题 9月20日

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)