codeforces 746C 模拟
1 second
256 megabytes
standard input
standard output
The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per t1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points x = 0 and x = s.
Igor is at the point x1. He should reach the point x2. Igor passes 1 meter per t2 seconds.
Your task is to determine the minimum time Igor needs to get from the point x1 to the point x2, if it is known where the tram is and in what direction it goes at the moment Igor comes to the point x1.
Igor can enter the tram unlimited number of times at any moment when his and the tram's positions coincide. It is not obligatory that points in which Igor enter and exit the tram are integers. Assume that any boarding and unboarding happens instantly. Igor can move arbitrary along the line (but not faster than 1 meter per t2 seconds). He can also stand at some point for some time.
The first line contains three integers s, x1 and x2 (2 ≤ s ≤ 1000, 0 ≤ x1, x2 ≤ s, x1 ≠ x2) — the maximum coordinate of the point to which the tram goes, the point Igor is at, and the point he should come to.
The second line contains two integers t1 and t2 (1 ≤ t1, t2 ≤ 1000) — the time in seconds in which the tram passes 1 meter and the time in seconds in which Igor passes 1 meter.
The third line contains two integers p and d (1 ≤ p ≤ s - 1, d is either 1 or
) — the position of the tram in the moment Igor came to the point x1 and the direction of the tram at this moment. If
, the tram goes in the direction from the point s to the point 0. If d = 1, the tram goes in the direction from the point 0 to the point s.
Print the minimum time in seconds which Igor needs to get from the point x1 to the point x2.
4 2 4
3 4
1 1
8
5 4 0
1 2
3 1
7
In the first example it is profitable for Igor to go by foot and not to wait the tram. Thus, he has to pass 2 meters and it takes 8 seconds in total, because he passes 1 meter per 4 seconds.
In the second example Igor can, for example, go towards the point x2 and get to the point 1 in 6 seconds (because he has to pass 3meters, but he passes 1 meters per 2 seconds). At that moment the tram will be at the point 1, so Igor can enter the tram and pass 1 meter in 1 second. Thus, Igor will reach the point x2 in 7 seconds in total.
题意 0到s线段中给出两个点x1和x2,从x1到x2,然后可以坐车,车开始在p点车头方向为d(d==1向右 d==-1向左),
汽车在0-S之间不停地开,到达0或S点会掉头,人可以在任意时间上、下车,汽车每t1秒走1,步行每t2秒走1,问人从x1到x2的最短时间。
官方解析
It is easy to show that if Igor faster than the tram the answer is |x1 - x2|·t2.
In the other case we need to use the following hint: the time of arrive does not depend on how much Igor walk before enter the tram, if the tram will reach the finish point faster than Igor. So Igor can wait the tram in the point x1.
The answer is minimum of the following values: the time during which Igor will reach the point x2 by foot and the time during which the tram will reach at first the point x1 and than the point x2.
这要比较汽车先经过x1再经过x2所花的时间和人从x1走到x2所花的时就可以了,然后分类讨论前者的情况 共有六种情况(注意合并后)。
AC代码
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
using namespace std;
const int maxn= ;
const int maxm= 1e9+;
const int inf = 0x3f3f3f3f;
typedef long long ll;
int main()
{
int s,x1,x2,t1,t2,d,p;
scanf("%d %d %d",&s,&x1,&x2);
scanf("%d %d",&t1,&t2);
scanf("%d %d",&p,&d);
int ans1,ans2;
ans1=abs(x1-x2)*t2;
if(d==) //向右三种
{
if(p<=x1&&x2>x1)
ans2=(x2-p)*t1;
else if(x2>x1)
ans2=(s-p+s+x2)*t1;
else if(x2<x1)
ans2=(s-p+s-x2)*t1;
}
else //向左三种
{
if(p>=x1&&x2<x1)
ans2=(p-x2)*t1;
else if(x2<x1)
ans2=(p+s+s-x2)*t1;
else if(x2>x1)
ans2=(p+x2)*t1;
}
printf("%d\n",min(ans1,ans2)); //取两者最小
}
codeforces 746C 模拟的更多相关文章
- CodeForces - 427B (模拟题)
Prison Transfer Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Sub ...
- CodeForces - 404B(模拟题)
Marathon Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Sta ...
- Codeforces 709B 模拟
B. Checkpoints time limit per test:1 second memory limit per test:256 megabytes input:standard input ...
- CodeForces - 404A(模拟题)
Valera and X Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit ...
- Codeforces 390A( 模拟题)
Inna and Alarm Clock Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64 ...
- Codeforces 452D [模拟][贪心]
题意: 给你k件衣服处理,告诉你洗衣机烘干机折叠机的数量,和它们处理一件衣服的时间,要求一件衣服在洗完之后必须立刻烘干,烘干之后必须立刻折叠,问所需的最小时间. 思路: 1.按照时间模拟 2.若洗完的 ...
- CodeForces - 796B 模拟
思路:模拟移动即可,如果球落入洞中停止移动.注意:有可能第一个位置就是洞!! AC代码 #include <cstdio> #include <cmath> #include ...
- CodeForces - 864C-Bus-(模拟加油站问题)
https://vjudge.net/problem/CodeForces-864C 题意:两地之间有个加油站,往返走k个单程,最少加油多少次. 大佬几十行代码就解决,我却要用一百多行的if语句模拟解 ...
- Codeforces 709C 模拟
C. Letters Cyclic Shift time limit per test:1 second memory limit per test:256 megabytes input:stand ...
随机推荐
- UITableView的性能优化
UITableView作为ios中使用最频繁的控件之一,其性能优化也是常常要面对的,尤其是当数据量偏大并且设备性能不足时.本文旨在总结tableview的几个性能优化tips,并且随着认识的深入,本文 ...
- Safari不能连接到服务器
系统偏好设置-网络-高级-代理,把"网页代理"和"安全网页代理"两个复选项去掉,最下面"使用被动FTP模式"复选项保留,即可解决!
- JavaWeb框架_Struts2_(五)----->Struts2的标签库
1. Struts2的标签库 1.1 Struts2标签库概述 Struts2的标签库可以分为以下3类:用户界面标签.非用户界面标签.AJAX标签; 2.1.1 Struts2标签库的分类和使用 1 ...
- JMeter参数化实现
参数化:指对每次发起的请求,参数名称相同,参数值进行替换,如登录三次系统,每次用不同的用户名和密码. 1.1.1. 从csv文件读取(CSV Data Set Config) 步骤: 1)新建一个文 ...
- 使用line-height来垂直居中在安卓设备并不居中,利用ji调整
先判断智能机浏览器的版本信息:方法有两种,但是第一种兼容性更好,但是使用了device插件 第一种: if (device.android()){ } 第二种: var ua = navigator. ...
- SQL server Error Number
描述 HY000 所有绑定列都是只读的. 必须是可升级的列,以使用 SQLSetPos 或 SQLBulkOperations 更改或插入行. HY000 已检测到一个旧 netlib (%s).请删 ...
- 单独mybatis得使用
今天同学说要学习mybatis后来他写了个程序让我看看,我看了一下发现包引错了,他写的是单独的mybatis,引入的却是spring-mybatis,所以会报错. 今天我记录一下单独mybatis的使 ...
- [js高手之路] es6系列教程 - 迭代器,生成器,for...of,entries,values,keys等详解
接着上文[js高手之路] es6系列教程 - 迭代器与生成器详解继续. 在es6中引入了一个新的循环结构for ....of, 主要是用来循环可迭代的对象,那么什么是可迭代的对象呢? 可迭代的对象一般 ...
- Nodejs的运行原理-调用篇
前言 之前做过Nodejs的架构篇, 有很多朋友留言给我,说没看懂里面的例子,这里我会重新梳理一下,再以http server为例,来解析Nodejs从前端到libuv的调用过程. 正文 回忆a. N ...
- linux下vsftpd的安装及配置使用详细步骤
vsftpd 是“very secure FTP daemon”的缩写,安全性是它的一个最大的特点. vsftpd 是一个 UNIX 类操作系统上运行的服务器的名字,它可以运行在诸如 Linux.BS ...