Vasya and Book
https://codeforces.com/contest/1082/problem/A
题解:
一共四种情况
1、往左走没有到n就达到目的地(包括目的地为n)
2、往右走没有到1就达到目的地(包括目的地为1)
3、往左走到n,回头再达到目的地
4、往右走到1,回头再达到目的地
/*
*@Author: STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUGusing namespace std;
typedef long long ll;
const int N=10000;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const ll INF = 0x3f3f3f3f3f3f3f;
int t;
ll n,x,y,d,m;int main()
{
#ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout);
#endifscanf("%d",&t);while(t--){scanf("%I64d%I64d%I64d%I64d",&n,&x,&y,&d);if(labs(x-y)%d==0){cout << labs(x-y)/d << endl;}else{int l=(x-1)/d;if((x-1)%d)l++;int r=(n-x)/d;if((n-x)%d)r++;ll ans=INF;if((y-1)%d==0){ans=min(ans,l+(y-1)/d);}if((n-y)%d==0){ans=min(ans,r+(n-y)/d);}if(ans!=INF){cout << ans << endl;}else{cout << -1 << endl;}}}//cout << "Hello world!" << endl;return 0;
}
Vasya and Book相关推荐
- Codewars Vasya - Clerk--6 kyu--Python解法
Codewars Vasya - Clerk–6 kyu–Python解法 Codewars 是一个跟LeetCode类似的结题网站. Codewars题解专栏:Codewars题解 题目地址:Tra ...
- Codeforces Round #281 (Div. 2) C. Vasya and Basketball 二分
C. Vasya and Basketball 题目连接: http://codeforces.com/contest/493/problem/C Description Vasya follows ...
- Vasya and String CodeForces - 676C(尺取法)
High school student Vasya got a string of length n as a birthday present. This string consists of le ...
- CodeForces - 1058D D. Vasya and Triangle
D. Vasya and Triangle time limit per test1 second memory limit per test256 megabytes inputstandard i ...
- CodeForces 1058C C. Vasya and Golden Ticket
C. Vasya and Golden Ticket time limit per test1 second memory limit per test256 megabytes inputstand ...
- 【CodeForces - 1051C 】Vasya and Multisets (模拟)
题干: Vasya has a multiset ss consisting of nn integer numbers. Vasya calls some number xxnice if it a ...
- 【CodeForces - 1051A】Vasya And Password (构造,水题)
题干: Vasya came up with a password to register for EatForces - a string ss. The password in EatForces ...
- CF Edu54 E. Vasya and a Tree DFS+树状数组
Vasya and a Tree 题意: 给定一棵树,对树有3e5的操作,每次操作为,把树上某个节点的不超过d的子节点都加上值x; 思路: 多开一个vector记录每个点上的操作.dfs这颗树,同时以 ...
- Codeforces Round #281 (Div. 2) A. Vasya and Football 模拟
A. Vasya and Football 题目连接: http://codeforces.com/contest/493/problem/A Description Vasya has starte ...
- [CF1107E]Vasya and Binary String【区间DP】
题目描述 Vasya has a string s of length n consisting only of digits 0 and 1. Also he has an array a of l ...
最新文章
- 【activeMQ】一、入门
- 第51条:精简initialize与load的实现代码
- github客户端进行token认证
- 《金字塔原理》读书笔记
- arcpy利用XY创建点
- Linux终端下载百度云,Linux终端使用wget下载百度云资源
- 深度linux操作系统
- 手机浏览器的扫一扫功能在哪里,有什么作用
- 远程服务器638,638是什么意思
- 面试字节跳动后台开发(实习)
- C++自学历程——启程篇
- 知乎张瑞: 浅析机器学习理论与实践 | 业界对话
- 解决pip下载速度慢的问题
- Python绘制韦恩图并通过集合找到交集并集数据
- 宏碁传奇Go评测 怎么样
- 递归算法从入门到完全掌握
- 爬取简单静态网站——汽车之家二手车
- SQL的左连接 ,右连接,内连接和全外连接的4者区别
- python实现基金定投并可视化结果(及时止损)
- 聊一聊 C++ 中的 namespace
热门文章
- mysql查阅某个日期的语句_mysql查询指定日期时间内的sql语句及原理
- 有限服务器延时计算_新建三座超级数据中心,增超百万台服务器 阿里云数据中心选址有何逻辑?...
- html5 建筑物模型,基于HTML5的建筑物阴影实时模拟
- java变量访问权限_JAVA成员变量的访问权限
- java正则表达式去除重复_Java正则表达式:重复捕获组
- 00018计算机应用基础2019年4月,2019年4月自考计算机应用基础考前试题和答案00018.pdf...
- java 编写异常_Java基础编程之异常处理
- Tomcat 初始化端点错误--Error initializing endpoint
- 博士申请 | 约翰霍普金斯大学招收2022年入学trustworthy AI方向博士生
- ACL 2021|CHASE: 首个跨领域多轮Text2SQL中文数据集