E -
A rectangle

Crawling in process...
Crawling failed
Time Limit:500MS    
Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

Developing tools for creation of locations maps for turn-based fights in a new game, Petya faced the following problem.

A field map consists of hexagonal cells. Since locations sizes are going to be big, a game designer wants to have a tool for quick filling of a field part with identical enemy units. This action will look like following: a game designer will select a rectangular
area on the map, and each cell whose center belongs to the selected rectangle will be filled with the enemy unit.

More formally, if a game designer selected cells having coordinates
(x1, y1) and
(x2, y2), where
x1 ≤ x2 and
y1 ≤ y2, then all cells having center coordinates
(x, y) such that
x1 ≤ x ≤ x2 and
y1 ≤ y ≤ y2 will be filled. Orthogonal coordinates system is set up
so that one of cell sides is parallel to OX axis, all hexagon centers have integer coordinates and for each integer
x there are cells having center with such
x coordinate and for each integer y there are cells having center with such
y coordinate. It is guaranteed that difference
x2 - x1 is divisible by
2.

Working on the problem Petya decided that before painting selected units he wants to output number of units that will be painted on the map.

Help him implement counting of these units before painting.

Input

The only line of input contains four integers x1, y1, x2, y2
( - 109 ≤ x1 ≤ x2 ≤ 109,  - 109 ≤ y1 ≤ y2 ≤ 109)
— the coordinates of the centers of two cells.

Output

Output one integer — the number of cells to be filled.

Sample Input

Input
1 1 5 5
Output
13

从图中可以看出,x为整数时x=x1的直线总是落在六边形的中心线上,
所以会多包含一部分六边形,(x2-x1+1)可以得到一行有多少个,
y=y1总是落在六边形的边上,但是还会包含一部分,(y2-y1+2)个 ,
这些都可以从图中看出
#include<iostream>
using namespace std;
int main()
{
__int64 x1,x2,y1,y2;
while(cin>>x1>>y1>>x2>>y2)
{
__int64 ans=(x2-x1+1)*(y2-y1+2)/2-(x2-x1+1)/2;
cout<<ans<<endl;
}
return 0;
}

Codeforces--630E--A rectangle(规律)的更多相关文章

  1. 【codeforces 630E】A rectangle

    [题目链接]:http://codeforces.com/problemset/problem/630/E [题意] 给你一个矩形的区域; 然后让你统计这个矩形区域内,有多少个正六边形. [题解] 规 ...

  2. codeforces D. Queue 找规律+递推

    题目链接: http://codeforces.com/problemset/problem/353/D?mobile=true H. Queue time limit per test 1 seco ...

  3. Codeforces 626B Cards(模拟+规律)

    B. Cards time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp ...

  4. codeforces 630 I(规律&&组合)

    I - Parking Lot Time Limit:500MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Subm ...

  5. CodeForces 135 B. Rectangle and Square(判断正方形和 矩形)

    题目:http://codeforces.com/problemset/problem/135/B 题意:给8个点 判断能否用 4个点构成正方形,另外4个点构成 矩形. 输出 第一行是正方形 ,第二行 ...

  6. Segments CodeForces 909B (找规律)

    Description You are given an integer N. Consider all possible segments (线段,划分)on the coordinate axis ...

  7. Really Big Numbers CodeForces - 817C (数学规律+二分)

    C. Really Big Numbers time limit per test 1 second memory limit per test 256 megabytes input standar ...

  8. CodeForces 42C Safe cracking 规律题

    题目链接:点击打开链接 3个数为一组,找最大的一个数让它降低,则显然是有解的,分类讨论一下就可以 #include<cstdio> #include<cstring> #inc ...

  9. CodeForces - 1003-B-Binary String Constructing (规律+模拟)

    You are given three integers aa, bb and xx. Your task is to construct a binary string ssof length n= ...

  10. Codeforces 480B Long Jumps 规律题

    题目链接:点击打开链接 题意: 输出n l x y 有一根直尺长度为l 上面有n个刻度. 以下n个数字是距离开头的长度(保证第一个数字是0,最后一个数字是l) 要使得 直尺中存在某2个刻度的距离为x ...

随机推荐

  1. ibatis知识点

    1:ibatis是apache的一个开源的项目,是一个O/R mapping解决方案,优点,小巧,灵活.2:搭建环境:导入ibatis相关jar包,jdbc驱动包等3:配置文件: jdbc连接的属性文 ...

  2. JS高级——instanceof语法

    基本语法 对象 instanceof 构造函数 基本使用 <script> function Person() { } //p--->Person.prototype--->O ...

  3. 回顾Google IO 2016 -Keynote【图解】

    Google IO大会倒计时进行中~~ 两名演奏者在使用高空“古筝”. 最后5秒倒计时~~~~全场轰动~ 倒计时结束,IO大会正式开始.屏幕中,一个人把纯白的唱片放入唱片机中. 然后欢快的音乐响起,台 ...

  4. 如何在eclipse中设置断点并调试程序

    eclipse导入源码后可以看见代码但并不能调试,(解决方法) 1.eclipse默认的运行环境不是jdk中的jre.将jre换成jdk: 2. 先去掉勾,apply,在打上勾,apply 参考:ht ...

  5. 【sqli-labs】 less58 GET -Challenge -Double Query -5 queries allowed -Variation1 (GET型 挑战 双查询 只允许5次查询 变化1)

    单引号闭合成功,但是union select结果不对 http://192.168.136.128/sqli-labs-master/Less-58/?id=0' union select 1,2,3 ...

  6. cstring 转 string

    都通过基本类型来转换即可:CString可以转换为基本类型LPCTSTR,LPCTSTR根据项目编码可以是const char*或者const wchar_t*:string可以用c_str()转换为 ...

  7. centos7 安装 PostgreSql

    确定你是管理员,然后运行命令: yum -y install postgresql-server postgresql-contrib 初始化数据库 postgresql-setup initdb 启 ...

  8. CAD全屏显示控件

    主要用到函数说明: MxDrawXCustomFunction::Mx_FullScreen 全屏显示控件,详细说明如下: 参数 说明 int iFull = 2 0: 不完屏,1:全屏,2:自动切换 ...

  9. JS获取图片的原始宽度和高度

    页面中的img元素,想要获取它的原始尺寸,以宽度为例,可能首先想到的是元素的innerWidth属性,或者jQuery中的width()方法.如下: <img id="img" ...

  10. 【转载】IDEA:XML配置提示URI is not registered

    在idea开发中,遇到xml提示URI is not registered....其实是idea找不到约束文件,下面讲解一下如何解决这一个问题吧. 现的问题是,xml文件右边有提示,提示内容为:URI ...