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 ...
随机推荐
- iOS 类似2048、4096小游戏-OC
大概思路(初步制作,粗工制造):demo 1.Collection 创建cell 2.cell上添加一个view,用来添加手势 3.字典用来存放数据->每次执行StarGame数组接收没有数字的 ...
- c#创建access数据库和数据表
由于在程序中使用了ADOX,所以先要在解决方案中引用之,方法如下: 解决方案资源管理器(项目名称)-->(右键)添加引用-->COM--> Microsoft ADO Ext. ...
- open-falcon(v0.2)部署手册(源码编译)
今天安装falcon-plus,下面为用基础环境配置. centos 6.8 alisql5.6.32 redis-3.2.8 cmake-3.9.1 bison-3.0 openssl-1.0 ...
- Docker(七):Docker容器卷管理
1.使用容器卷的原因:Docker容器产生的数据,如果不通过commit生成新的镜像,数据会在容器删除后丢失.为了能持久化保存和共享容器的数据,Docker提出了两种管理数据的方式:数据卷和数据卷容器 ...
- 顶点/片元 shader 总结
Cg顶点程序必须在结构中传递顶点数据.几种常用的顶点结构定义在文件UnityCG.cginc中,有如下三种结构体: 1.appdata_base: 包含顶点位置,法线和一个纹理坐标.2.appdata ...
- css实现一行居中显示,两行靠左显示,超过两行以引号省略
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Python 项目实践三(Web应用程序)第三篇
接着上节的继续学习,现在要显示所有主题的页面 有了高效的网页创建方法,就能专注于另外两个网页了:显示全部主题的网页以及显示特定主题中条目的网页.所有主题页面显示用户创建的所有主题,它是第一个需要使用数 ...
- dJango前言之 socketserver源码
socketserver源码分析: ftpserver=socketserver.ThreadingTCPServer(('127.0.0.1',8080),FtpServer) ftpserver. ...
- Head First设计模式之外观模式
一.定义 外观模式提供了一个统一的接口,用来访问子系统中的一群接口.外观定义了一个高层接口,让子系统更容易使用. 外观模式不只是简化了接口,也将客户从组件的子系统中解耦. 外观和适配器可以包装许多类, ...
- StringMVC @RequestMapping method属性
@RequestMapping(value="/testMethod",method=RequestMethod.POST) public String testMethod(){ ...