CodeForces - 630E A rectangle (数学规律)
2016-03-09 08:39
931 查看
CodeForces
- 630E
A rectangle
Submit Status
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 andy1 ≤ 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
Output
Source
Experimental Educational Round: VolBIT Formulas Blitz
//题意:
给你两个点的坐标,(x1,y1),(x2,y2),分别表示左下端点和右上端点,问在此矩形中一共可以将几个六边形涂黑(如图所示)。找规律题,就不多说了。。
- 630E
A rectangle
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 andy1 ≤ 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
Source
Experimental Educational Round: VolBIT Formulas Blitz
//题意:
给你两个点的坐标,(x1,y1),(x2,y2),分别表示左下端点和右上端点,问在此矩形中一共可以将几个六边形涂黑(如图所示)。找规律题,就不多说了。。
#include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> #define INF 0x3f3f3f3f #define ll long long #define N 10010 #define M 1000000007 using namespace std; int main() { ll x1,x2,y1,y2; while(scanf("%lld%lld%lld%lld",&x1,&y1,&x2,&y2)!=EOF) { ll ny=(y2-y1+2)/2; ll nx=(x2-x1+1)/2; ll sum=ny*(x2-x1+1)-nx; printf("%lld\n",sum); } return 0; }
相关文章推荐
- 线程生命周期
- Could not publish server configuration for Tomcat v8.0 Server at localhost. Multiple Contexts have a
- lintcode-easy-Two Strings Are Annagrams
- GIS+=地理信息+数据库技术——[网络公开课]Oracle技术分享
- C语言——内存管理
- Slyce,这家硅谷创业公司的来头你知道吗
- 调用私有的虚函数
- 自己删了双系统出现的grub界面
- spring AOP实例
- SQL取数据库名,取表名,取列名
- HDU 2435 There is a war (网络流-最小割)
- HDU 5636 Shortest Path(Floyed,枚举)
- HDU 5636 Shortest Path(Floyed,枚举)
- HDU 1418:抱歉 【欧拉定理】
- 微软将把 SQL Server 带到 Linux
- 面试了有几家了,总结一下,为下次面试做准备
- 浅谈.NET中接口和类的区别
- python解无忧公主数学题108
- 诚挚邀请大家3.12号参加在广州的微软 MVP 开源社区巡讲(分布式大数据,NET)
- lintcode-easy-Triangle