code forces E A rectangle
来源:互联网 发布:mac创建win7安装盘 编辑:程序博客网 时间:2024/05/20 03:08
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
题意:求题目给出的对角点所形成的矩形所包含的六边形中心的个数!
可以发现所有的中心点都在横纵坐标奇偶相等的点处!
这样就是求在矩形区域内横纵坐标相等的点的个数!
AC-code
#include<stdio.h>int main(){__int64 x1,x2,y2,y1;while(scanf("%I64d%I64d%I64d%I64d",&x1,&y1,&x2,&y2)!=EOF){ __int64 x=x2-x1,y=y2-y1; printf("%I64d\n",(x-x/2)*(y-y/2)+(x/2)*(y/2));}return 0;}
- code forces E A rectangle
- code forces E. Danil and a Part-time Job
- code forces 1A
- code forces 377A
- code forces 505A
- Code Forces 587A
- Code Forces 588A
- [code forces] 762A
- code forces 393A Nineteen
- code forces 399A Pages
- code forces 402A Nuts
- code forces 2A Winner
- code forces 407A Triangle
- Code Forces 298 A EXAM
- Code Forces 37A Towers
- Code Forces 59A Word
- Code Forces 21 A(模拟)
- 【code forces】652A模拟
- DHTMLTree 详解
- 构建之法1、5、17章
- Android蓝牙开发全面总结
- App架构经验总结
- SqlServer索引及优化详解
- code forces E A rectangle
- python爬虫学习(一)
- Android性能优化
- 引导层界面的Canvas和Paint效果
- KSImageNamed 安装后无效解决方法(试过有效)
- mysql监视器MONyog的使用
- P2P通讯的C++实现-UDP Hole Punching方法
- Android NFC开发概述
- 安卓实现clean architecture的大体思路