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. CSS——行内元素的margin与padding

    行内元素: 1.margin:0 20px:只可以定义左右. 2.pading:20px 20px 20px 20px:上下左右都有效 例如span: <!DOCTYPE html> &l ...

  2. Oracle基础理论笔记(一):模式概念

    ---oracle 10g 1.在oracle数据库中,数据对象是以模式为单位进行组织和管理的.模式是指一系列的逻辑数据结构或对象的集合. 2.模式与用户名相对应,一个模式只能对应一个用户,并且该模式 ...

  3. 170925_1 Python socket 创建TCP的服务器端和客户端

    [Python版本]3.6 [遇到的问题] 客户端和服务器端都遇到:TypeError: a bytes-like object is required, not 'str' [解决方案] 参考:ht ...

  4. id拼接保存到单个字段后作为表连接的查询条件

    SELECT q.id, concat(q. NAME) qname, d.id did, d. NAME FROM question_po q LEFT JOIN data_configuratio ...

  5. HyperLink的使用

    <asp:HyperLink ID="Hyperlink2" NavigateUrl='<%# string.Format("AddOrganizition. ...

  6. 如何创建一个项目,让gitlab自动触发jenkins进行构建

    前进是:你已经配置好jenkins+gitlab自动化布置了,这里只是常规构建新的项目时,需要做的配置,记录下来,以免忘了又着急 参考这篇博客: https://www.jianshu.com/p/e ...

  7. Ansible实现zabbix服务器agent端批量部署

    项目需求:由于搭建zabbix,需要每台服务器都需要安装监控端(agent)正常的的操作是一台一台去安装,这样确实有点浪费时间,这里为大家准备了一款开源 的自动化运维工具Ansible,相信大家也很熟 ...

  8. 【原创】基于NodeJS Express框架开发的一个VIP视频网站项目及源码分享

    项目名称:视频网站项目 开发语言:HTML,CSS(前端),JavaScript,NODEJS(expres)(后台) 数据库:MySQL 开发环境:Win7,Webstorm 上线部署环境:Linu ...

  9. cogs——49. 跳马问题

    49. 跳马问题 水题 dfs裸基础 #include<cstdio> using namespace std; ]={,,,,}, ans,my[]={,-,,-,}; inline v ...

  10. 第二节:web爬虫之lxml解析库

    lxml是python的一个解析库,支持HTML和XML的解析,支持XPath解析方式,而且解析效率非常高.