Codeforces--630E--A rectangle(规律)
2016-03-08 19:27
351 查看
E -A rectangleCrawling in process...Crawling failedTime Limit:500MSMemory Limit:65536KB 64bit IO Format:%I64d & %I64uSubmitStatusDescriptionDeveloping 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 rectangulararea 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), wherex1 ≤ x2 andy1 ≤ y2, then all cells having center coordinates(x, y) such thatx1 ≤ x ≤ x2 andy1 ≤ y ≤ y2 will be filled. Orthogonal coordinates system is set upso that one of cell sides is parallel to OX axis, all hexagon centers have integer coordinates and for each integerx there are cells having center with suchx coordinate and for each integer y there are cells having center with suchy coordinate. It is guaranteed that differencex2 - x1 is divisible by2.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.InputThe 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.OutputOutput one integer — the number of cells to be filled.Sample InputInput
1 1 5 5Output
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;}[/code]
相关文章推荐
- Codeforces 630F - Selection of Personnel
- wait和notifyAll的方法使用案例分析
- Retrofit 代替 HttpRequest
- [转]Python os.path模块
- Uva10976——Fractions Again?!
- JAVA的agent使用总结(用ASM进行操作)
- Codeforces 86C Genetic engineering(AC自动机+DP)
- C语言中参数的传递
- POJ_P2311 Cutting Game(博弈+SG函数)
- infinite scroll和masonry实现的json类型瀑布流
- SpringMVC的两个简单入门的例子(-)
- 让多个Fragment 切换时不重新实例化
- 基本算法prim学习总结性文章
- ZOJ 3926 Parity Modulo P(XJB)
- ZOJ 3923 In the Rain(数学)
- C++中的继承和组合区别使用
- 项目2胖子不想说体重
- 弱网络下的游戏服务器设计
- 文章标题
- 代码才是公司资产