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 ...
随机推荐
- Unity项目 - 简单时钟 Clock
项目展示 Github项目地址:简单时钟 Clock 制作流程 表盘绘制: 采用Aseprite 像素绘图软件绘制表盘及指针.本例钟表素材大小 256x256,存储格式为png,但发现导入Unity后 ...
- 前端开发 Angular
https://www.angularjs.net.cn/tutorial/18.html
- 【CF1095F】 Make It Connected(最小生成树)
题目链接 如果没有特殊边的话显然答案就是权值最小的点向其他所有点连边. 所以把特殊边和权值最小的点向其他点连的边丢一起跑最小生成树就行了. #include <cstdio> #inclu ...
- [破解版]Unity3d引擎最新稳定版本4.5.5下载(官方最新稳定版本)
来源:http://www.unitymanual.com/thread-28912-1-1.html unity4.5.5 Mac版下载地址:http://pan.baidu.com/s/1hqzi ...
- 【Python】单例模式
单例 class MusicPlayer(object): instance = None def __new__(cls, *args, **kwargs): if cls.instance is ...
- java数据库数据导入excel
data导出入excel中 controller: package com.longfor.hrssc.api.controller; import com.longfor.hrssc.api.mod ...
- RobotFramework+Eclipse的安装和配置(一)
最近想学robotframwork来做自动化,那立马就来开始上手 想动手,起码要先下载工具,工具及框架 工具介绍 Robotframework:一款自动化测试框架. Eclipse:一款编辑工具,可以 ...
- Oracle IMP-00010 不是有效的导出文件,标头验证失败 解决方法
用IMP导入dmp文件时,出现IMP-00010 不是有效的导出文件,标头验证失败问题. 第一种:网上搜索到的大多解决方法是说导出文件时使用的Oracle版本不一致问题,需要修改dmp文件的版本号.如 ...
- IDEA远程连接和上传文件到服务器
公司电脑是win,所以远程控制服务器就不能用之前自己笔记本ubuntu自带的终端了. 后来在万能的群友的提醒下,IDEA本身就自带了远程功能,摸索了一下,使用IDEA连接服务器并且可以上传文件了. 这 ...
- XML知识学习
第一部分[基础篇]: https://www.w3school.com.cn/xml/xml_intro.asp W3C教程地址 什么是 XML? XML 指可扩展标记语言(EXtensible Ma ...