Codeforces Round #386 Div. 2C - Tram

88 篇文章 0 订阅
86 篇文章 0 订阅

题意:

人从x1走到x2,每t2秒走1米。车的方向是-1  /   1     每t1秒走1米。询问人打到x2最短时间

思路

分类套路。

pos写的时候智障了,-把车速写成人了



#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
    int s,x1,x2;
    cin>>s>>x1>>x2;
    int tc,tr;
    cin>>tc>>tr;
    int pos,to;
    cin>>pos>>to;
    int from,need;
    if(x2<x1)
    {
        from=-1;
        need=x1-x2;
    }
    else
    {
        from=1;
        need=x2-x1;
    }
    int dis,dis1,dis2,timec,timer,time3,ans;
    dis=0;
    if(from==1)
    {
    //  x1  pos x2
        if(pos<=x1)
        {
            if(to==1)
            {
                timec=(x2-pos)*tc;
                timer=need*tr;
            }
            else
            {
                timec=(pos+x2)*tc;
                timer=(need)*tr;
            }
        }
        else
        {
            //r  c
            if(to==1)
            {
                timec=(s-pos+s+x2)*tc;
                timer=need*tr;
            }
            else
            {
                timec=(pos+x2)*tc;
                timer=need*tr;
            }
        }
    }
    else
    {
        //x2  pos x1
        if(pos>=x1)
        {   //x2 x1 pos
            if(to==1)
            {
                timec=(s-pos+s-x2)*tc;
                timer=need*tr;
            }
            else
            {
                timec=(pos-x2)*tc;
                timer=need*tr;
            }
        }
        else
        {
            //x2 pos x1
            if(to==1)
            {
                timec=(s-pos+s-x2)*tc;
                timer=need*tr;
            }
            else
            {
                timec=(pos+s+s-x2)*tc;
                timer=need*tr;
            }
        }

    }

        ans=min(timec,timer);
        cout<<ans<<endl;
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值