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. phpCURL抓取网页内容

    参考代码1:<?php // 创建一个新cURL资源 $ch = curl_init(); // 设置URL和相应的选项 curl_setopt($ch, CURLOPT_URL, " ...

  2. 获取qq音乐json数据---某课网音乐app学习

    移动端qq音乐地址:https://m.y.qq.com/ .抓取QQ音乐数据 请求首页时,有如下链接,回调了jsonp https://c.y.qq.com/splcloud/fcgi-bin/p. ...

  3. CAD得到自定义实体拖放夹点(com接口VB语言)

    主要用到函数说明: MxDrawXCustomEvent::MxDrawXCustomEntity::getGripPoints 自定义实体事件,得到拖放夹点,详细说明如下: 参数 说明 LONGLO ...

  4. js的一些老司机写法

    //取整 parseInt(a,10); //Before Math.floor(a); //Before a>>0; //Before ~~a; //After a|0; //After ...

  5. uva 524(Prime Ring Problem UVA - 524 )

    dfs练习题,我素数打表的时候j=i了,一直没发现实际上是j=i*i,以后可记住了.还有最后一行不能有空格...昏迷了半天 我的代码(紫书上的算法) #include <bits/stdc++. ...

  6. Miller Rabbin素数测试

    步骤 ①先写快速幂取模函数 ②MR算法开始 (1)传入两个参数一个是底数一个是n也就是幂数,如果n是一个合数那么可以判定,这个数一定不是素数 (2)然后开始寻找一个奇数的n去计算,如果最后满足a^d% ...

  7. 746. Min Cost Climbing Stairs(动态规划)

    On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed). Once you pay ...

  8. yum http源

    统一集群内,有一个yum本地源即可,集群内其他机器的yum可配成http源 方法: yum1:本地yum源节点 yum2:集群内其他节点 yum1: ①service httpd start ②mki ...

  9. 【LeetCode Weekly Contest 26 Q3】Friend Circles

    [题目链接]:https://leetcode.com/contest/leetcode-weekly-contest-26/problems/friend-circles/ [题意] 告诉你任意两个 ...

  10. App的登陆注册接口安全设计

    最近一APP产品,我担任的主要模块之一是后台登录注册模块的接口开发.基本完成,就说说并记录一下关于登录注册接口的一些东西,因为也涉及到接口的安全方面的问题. 1.先一般的app的登录注册接口安全设计上 ...