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 xcoordinate 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.
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 one integer — the number of cells to be filled.
1 1 5 5
13
题意:如图所示的六边形网格,问在给出的矩形区域内,包含多少个六边形的中心
题解:
不难发现,在矩形区域内的点,仅仅x和y奇偶性相同的点才是满足条件的,因此就便于处理了
x的奇数个数乘上y的奇数个数,x的偶数个数乘上y的偶数个数,然后相加
#include<stdio.h>
typedef long long ll;
int main()
{
ll x1,x2,y1,y2;
while(~scanf("%lld%lld%lld%lld",&x1,&y1,&x2,&y2))
{
ll a=x2-x1+1,b=y2-y1+1;
printf("%lld\n",(a-a/2)*(b-b/2)+(a/2)*(b/2));
}
return 0;
}