A. Vasya and Book ( Codeforces Educational Codeforces Round 55 )
题意:当前在看书的第 x 页,每次可以向前或者向后翻 d 页,这个书一共 n 页,问能否用最小操作翻到第 y 页。
题解:三种情况:1、直接翻能到的一定最短。 2、先翻到第一页,然后往后翻,翻到第 y 页。3、先翻到第 n 页,然后往前翻,翻到第 y 页。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int ans,t,n,x,y,d;
cin >> t;
while(t--)
{
ans = 0;
cin >> n >> x >> y >> d;
if(abs(x-y) %d == 0)
{
ans = abs(x-y) / d;
printf("%d\n",ans);
continue;
}
else {
int x1;
if(x % d == 0) x1 = x /d;
else x1 = x / d +1;
if((y-1) % d == 0)
{
x1 += (y-1) / d;
}
else x1 = -1;
int x2;
if(abs(n - x) % d == 0) x2 = abs(n - x) / d;
else x2 = abs(n - x) / d + 1;
if((n-y)%d==0)
{
x2 += (n-y)/d;
}
else x2 = -1;
if(x1 == -1 && x2 == -1) ans = -1;
else if(x1 == -1 && x2 >= 0) ans = x2;
else if(x2 == -1 && x1 >= 0) ans = x1;
else ans = min(x1,x2);
printf("%d\n",ans);
}
}
return 0;
}
A. Vasya and Book ( Codeforces Educational Codeforces Round 55 )的更多相关文章
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...
- Codeforces 1082 A. Vasya and Book-题意 (Educational Codeforces Round 55 (Rated for Div. 2))
A. Vasya and Book time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- D. Vasya And The Matrix(Educational Codeforces Round 48)
D. Vasya And The Matrix time limit per test2 seconds memory limit per test256 megabytes inputstandar ...
- codeforces Educational Codeforces Round 5 A. Comparing Two Long Integers
题目链接:http://codeforces.com/problemset/problem/616/A 题目意思:顾名思义,就是比较两个长度不超过 1e6 的字符串的大小 模拟即可.提供两个版本,数组 ...
- codeforces Educational Codeforces Round 16-E(DP)
题目链接:http://codeforces.com/contest/710/problem/E 题意:开始文本为空,可以选择话费时间x输入或删除一个字符,也可以选择复制并粘贴一串字符(即长度变为两倍 ...
- Codeforces Educational Codeforces Round 15 E - Analysis of Pathes in Functional Graph
E. Analysis of Pathes in Functional Graph time limit per test 2 seconds memory limit per test 512 me ...
- Codeforces Educational Codeforces Round 15 D. Road to Post Office
D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Educational Codeforces Round 15 C. Cellular Network
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- vmware下的linux没有网络问题解决思路
这里几天一直在搞vm下的linux主机的网络问题,这里做个总结 这里使用的NAT连接方式 1.首先保证本机联网正常 2.检查虚拟机相应的服务(VMware NET Service 和 VMware W ...
- jmeter进行压测的步骤
1)安装jmeter和Badboy. 2)用badboy录制脚本,保存之后直接导出. 3)用jmeter打开badboy录制的脚本,假如是有参数的话,需要写一个csv的参数化文件,在jmeter中添加 ...
- js实现图片上传本地预览
演示地址:https://xibushijie.github.io/static/uploadImg.html <!DOCTYPE> <html> <head> & ...
- iOS进阶之多线程--NSThread详解
NSThread简介 NSThread是苹果官方提供面向对象操作线程的技术,简单方便,可以直接操作线程对象,不过需要自己控制线程的生命周期.在平时使用很少,最常用到的无非就是 [NSThread cu ...
- JDBC中PreparedStatement相比Statement的好处
Statement对象: 用于执行不带参数的简单SQL语句: 特点: a. 只执行单条的sql语句: b. 只能执行不带参数的sql语句: c.运行原理的角度,数据库接收到sql语句后需要对该条sql ...
- java web编程 servlet3
- es6 javascript的Class 类的继承
原文链接:https://blog.csdn.net/qq_30100043/article/details/53542531 1 基本用法 Class 之间可以通过extends关键字实现继承, 这 ...
- android studio创建模拟器
开发环境: 操作系统: windows10 教育版 1903 Android studio : Android Studio 3.5.1Build #AI-191.8026.42.35.590020 ...
- jmeter性能测试监控
Jmeter监控服务器资源配置如下: 1.进入https://jmeter-plugins.org/downloads/all/下载plugins-manager.jar,放置到jmeter安装目录/ ...
- openGL起飞篇
我的技术路线:glfw+glad(有了glfw,什么glew,freeglut都不要了) GLFW:直接下载,然后新建vs项目,在<VC++>的<包含目录>添加include路 ...