【CodeForces - 124D】Squares (旋转坐标系,计算几何,思维)

题干:

You are given an infinite checkered field. You should get from a square (x1; y1) to a square (x2; y2). Using the shortest path is not necessary. You can move on the field squares in four directions. That is, when you are positioned in any square, you can move to any other side-neighboring one.

A square (xy) is considered bad, if at least one of the two conditions is fulfilled:

  • |x + y| ≡ 0 (mod 2a),
  • |x - y| ≡ 0 (mod 2b).

Your task is to find the minimum number of bad cells one will have to visit on the way from (x1; y1) to (x2; y2).

Input

The only line contains integers abx1, y1, x2 and y2 — the parameters of the bad squares, the coordinates of the initial and the final squares correspondingly (2 ≤ a, b ≤ 109 and |x1|,|y1|,|x2|,|y2| ≤ 109). It is guaranteed that the initial and the final square aren't bad.

Output

Print a single number — the minimum number of bad cells that one will have to visit in order to travel from square (x1; y1) to square (x2; y2).

Examples

Input

2 2 1 0 0 1

Output

1

Input

2 2 10 11 0 1

Output

5

Input

2 4 3 -1 3 7

Output

2

Note

In the third sample one of the possible paths in (3;-1)->(3;0)->(3;1)->(3;2)->(4;2)->(4;3)->(4;4)->(4;5)->(4;6)->(4;7)->(3;7). Squares (3;1) and (4;4) are bad.

题目大意:

   给你两个平面内的点,坐标可能很大,但是不会超过int,在平面内可以上下左右走,问你从( x1 , y1 )走到( x2 , y2 )最少可能经过坏点的数量(坏点即为满足| x + y | % 2a ==0 或者| x - y | % 2b == 0) 

解题报告:

   本题想要坏点最少,而坏点所在的直线其实是满足一定规律的,就是等间距分布。
画到这里其实就已经很明显了,要使两点之间的路线坏点最少,肯定就是在这些直线之间尽量多的走交点,这里还要注意一个问题,就是跨象限的问题(x+y=0 和 x-y=0)。

题解

AC代码:

#include<bits/stdc++.h>
using namespace std;
int a,b,x1,y1,x2,y2;
int x,y;
int main()
{
//	cout << (5/-2)<<endl;cin>>a>>b>>x1>>y1>>x2>>y2;//向左旋转45°建立坐标系 ,精彩 x=x1;y=y1;x1=x+y;y1=y-x;x=x2;y=y2;x2=x+y;y2=y-x;a*=2;b*=2;//看是否都大于0,处理坐标轴那一点 x1=x1/a+(x1>0);x2=x2/a+(x2>0);y1=y1/b+(y1>0);y2=y2/b+(y2>0);//只走交点,也就是,看横着的线和竖着的线哪个多,走哪个,另外一个肯定顺便就能走完了, cout<<max(abs(y2-y1),abs(x2-x1))<<endl;return 0;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441376.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

java图形设计_java图形界面设计含答案

十一章 图形用户界面程序设计入门一&#xff0e;选择题&#xff1a;1. 容器Panel和applet缺省使用的布局编辑策略是 BA、BorderLayout B、FlowLayoutC、GridLayout D、CarLayout2. .applet类的直接父类是&#xff1a; BA、Component类 B、Container类C、Frame类 D、Panel类3. .…

【qduoj - 夏季学期创新题】骑士游历(递推dp)

题干&#xff1a; 描述 输入 输入包含多组数据&#xff0c;第一行T表示数据组数接下来每行六个整数n&#xff0c;m&#xff0c;x1&#xff0c;y1&#xff0c;x2&#xff0c;y2(分别表示n&#xff0c;m&#xff0c;起点坐标&#xff0c;终点坐标) 输出 输出T行&#xff0c;表示…

java ee 6 源码_Java EE 6开发手册·高级篇(第4版)

资源名称&#xff1a;Java EE 6开发手册高级篇(第4版)内容简介&#xff1a;《Java EE 6 开发手册?高级篇(第4 版)》是一本面向实战、以示例为驱动、在Java 平台企业版6(Java EE 6)上开发企业级应用的指南。该指南基于The Java EE 6 Tutorial: Basic Concepts&#xff0c;Fourt…

【qduoj - 夏季学期创新题】矩形剖分(递归,dp)

题干&#xff1a; 描述 对一个给定的矩形&#xff0c;将其划分成尽可能少的正方形&#xff0c;输出正方形的最少个数。例如&#xff0c;如下图所示的情况&#xff0c;则输入为3和4&#xff0c;输出为4。 输入 输入两个整数中间用空格分开。 输出 输出最少分割成的正方形的个…

java8 nio_Java8之 NIO的学习

一、什么是NIO&#xff1f;Java NIO(New IO)是从Java 1.4版本开始引入的一个新的IO API&#xff0c;可以替代标准的Java IO API。NIO与原来的IO有同样的作用和目的&#xff0c;但是使用的方式完全不同&#xff0c;NIO支持面向缓冲区的、基于通道的IO操作。NIO将以更加高效的方式…

【牛客 - 125A】灰魔法师(打表,暴力)

题干&#xff1a; 给出长度为n的序列a, 求有多少对数对 (i, j) (1 < i < j < n) 满足 ai aj 为完全平方数。 输入描述: 第一行一个整数 n (1 < n < 105) 第二行 n 个整数 ai (1 < ai < 105) 输出描述: 输出一个整数&#xff0c;表示满足上述条件的数…

学分绩点计算编程java_方便我们计算学分绩点的JavaScript

基于目前我们学校教务处的管理系统, 依靠Javascript的帮忙, 我们可以很方便地计算成绩.测试用HTML:style"width: 100%; border-collapse: collapse;">课程代码课程名称课程性质成绩补考成绩重修成绩学分绩点辅修标记24109505数据库系统实验专业基础课优秀0.54.502…

【POJ - 2663】Tri Tiling (简单dp)

题干&#xff1a; In how many ways can you tile a 3xn rectangle with 2x1 dominoes? Here is a sample tiling of a 3x12 rectangle. Input Input consists of several test cases followed by a line containing -1. Each test case is a line containing an integer …

java 反射 代码_java反射机制学习代码

根据http://www.iteye.com/topic/137944文档进行学习代码如下:package reflectTest;import java.lang.reflect.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.*;class A{}class B extends A{}class C extends B{}class TestClass …

【POJ - 1556】The Doors (计算几何,线段相交)

题干&#xff1a; You are to find the length of the shortest path through a chamber containing obstructing walls. The chamber will always have sides at x 0, x 10, y 0, and y 10. The initial and final points of the path are always (0, 5) and (10, 5). Th…

java处理linux中的 m_Linux下处理BOM头和^M的简单方法

Linux在网络服务器、嵌入式设备的市场上占有较大份额&#xff0c;Microsoft Windows在桌面操作系统上占有较大的份额&#xff0c;因此有很多的人喜欢用Windows去控制操作Linux。既然用Windows去控制Linux&#xff0c;难免导致Windows系统上的产生的文件以某种途径传到了Linux系…

【POJ - 1696】Space Ant (凸包,最小极角,排序)

题干&#xff1a; The most exciting space discovery occurred at the end of the 20th century. In 1999, scientists traced down an ant-like creature in the planet Y1999 and called it M11. It has only one eye on the left side of its head and just three feet al…

2019蓝桥杯Java决赛题答案_2019第十届蓝桥杯JavaB组省赛真题详解

目录题解待更新第一题&#xff1a;组队题目描述做为篮球队教练&#xff0c;你须要从如下名单中选出 1 号位至 5 号位各一名球员&#xff0c; 组成球队的首发阵容。每位球员担任 1 号位至 5 号位时的评分以下表所示。请你计算首发阵容 1 号位至 5 号位的评分之和最大多是多少&am…

【FZU - 1759】Super A^B mod C (数论,快速幂,快速乘,欧拉降幂,指数循环节,模板)

题干&#xff1a; Given A,B,C, You should quickly calculate the result of A^B mod C. (1<A,C<1000000000,1<B<10^1000000). Input There are multiply testcases. Each testcase, there is one line contains three integers A, B and C, separated by a si…

java map统计学生名单_Java含自己的总结:集合,学生,遍历,ArrayList,Set,Map,泛型,班级,发牌—诗书画唱...

声明一个ArrayList&#xff0c;存储一条学生信息&#xff0c;内容为 1 张三 22 男&#xff0c;将信息进行遍历出来package list;import java.util.ArrayList;import java.util.Iterator;public class student{public static void main(String[] args) {ArrayList jiHe…

【AtCoder - 4242 】To Infinity(思维)

题干&#xff1a; Problem Statement Mr. Infinity has a string S consisting of digits from 1 to 9. Each time the date changes, this string changes as follows: Each occurrence of 2 in S is replaced with 22. Similarly, each 3 becomes 333, 4becomes 4444, 5 b…

java面向对象编程集合边框_JAVA 面向对象 集合框架

1.Java集合框架提供了一套性能优良、使用方便的接口和类&#xff0c;它们位于java.util包中如果并不知道程序运行时会需要多少对象&#xff0c;或者需要 更复杂方式存储对象——可以使用Java集合框架2.java集合框架包括接口、具体类、算法接口&#xff1a;Collection&#xff1…

【HDU - 2072 】单词数(字符串读入技巧,sstream大法,水题,字符串读入格式)

题干&#xff1a; lily的好朋友xiaoou333最近很空&#xff0c;他想了一件没有什么意义的事情&#xff0c;就是统计一篇文章里不同单词的总数。下面你的任务是帮助xiaoou333解决这个问题。 Input 有多组数据&#xff0c;每组一行&#xff0c;每组就是一篇小文章。每篇小文章都…

java生成world文件_HelloWorld.java文件如何创建?

原创HelloWorld.java文件如何创建&#xff1f;编辑:小丸子 来源:PC下载网时间:2017-10-17 19:55:54相信各位刚接触JAVA的新人都希望尽快编写出自己的第一个程序,今天PC下载网小编和你一起学习HelloWorld程序1.首先我们先点击“开始”—然后是“所有程序”—在然后是“附件”—记…

【HDU - 1251 】统计难题(字典树,求拥有公共前缀的字符串数量)

题干&#xff1a; Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己的前缀). Input 输入数据的第一部分是一张单词表,每行一个单词,单词的长度不超过10,它们代表的是…