Codeforces--630E--A rectangle(规律)
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
1 1 5 5
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(规律)的更多相关文章
- 【codeforces 630E】A rectangle
[题目链接]:http://codeforces.com/problemset/problem/630/E [题意] 给你一个矩形的区域; 然后让你统计这个矩形区域内,有多少个正六边形. [题解] 规 ...
- codeforces D. Queue 找规律+递推
题目链接: http://codeforces.com/problemset/problem/353/D?mobile=true H. Queue time limit per test 1 seco ...
- Codeforces 626B Cards(模拟+规律)
B. Cards time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp ...
- codeforces 630 I(规律&&组合)
I - Parking Lot Time Limit:500MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- CodeForces 135 B. Rectangle and Square(判断正方形和 矩形)
题目:http://codeforces.com/problemset/problem/135/B 题意:给8个点 判断能否用 4个点构成正方形,另外4个点构成 矩形. 输出 第一行是正方形 ,第二行 ...
- Segments CodeForces 909B (找规律)
Description You are given an integer N. Consider all possible segments (线段,划分)on the coordinate axis ...
- Really Big Numbers CodeForces - 817C (数学规律+二分)
C. Really Big Numbers time limit per test 1 second memory limit per test 256 megabytes input standar ...
- CodeForces 42C Safe cracking 规律题
题目链接:点击打开链接 3个数为一组,找最大的一个数让它降低,则显然是有解的,分类讨论一下就可以 #include<cstdio> #include<cstring> #inc ...
- 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= ...
- Codeforces 480B Long Jumps 规律题
题目链接:点击打开链接 题意: 输出n l x y 有一根直尺长度为l 上面有n个刻度. 以下n个数字是距离开头的长度(保证第一个数字是0,最后一个数字是l) 要使得 直尺中存在某2个刻度的距离为x ...
随机推荐
- 【译】x86程序员手册12-4.2系统指令
4.2 Systems Instructions 系统指令 Systems instructions deal with such functions as: 系统指令具有以下功能: Verifica ...
- HDU_3549_网络流(最大流)
Flow Problem Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tota ...
- What is gradle sync in Android Studio?
What is it? And what does it do? Gradle sync is a gradle task that looks through all of your depende ...
- day06-数字类型、字符串类型内置方法
目录 数字类型内置方法 字符串类型内置方法 有序 or 无序 可变 or 不可变 数字类型内置方法 1. int()强制类型转化成整型 age_str = '18' # 定义字符串 age = int ...
- windows程序设为开机自启动
在Windows文件管理器中输入 %APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup 把程序快捷方式放到此处即可.
- loader__demo_css
环境 node + yarn + webpack4.0 + webpack-cli + style-loader css-loader 文件结构 │ package.json │ webpack.co ...
- 【3】数据筛选2 - requests
目录 1.概述 2.下载安装 3.入门程序 4.请求对象:请求方式 5.请求对象:GET参数传递 6.请求对象:POST参数传递 7.请求对象: ...
- 用Twebbrowser做可控编辑器与MSHTML(插入表格)
在插入表格问题上出现与结果想象不一样的问题.看代码 <table border="1" cellpadding="0" width="100%& ...
- 【codeforces 757D】Felicity's Big Secret Revealed
[题目链接]:http://codeforces.com/problemset/problem/757/D [题意] 给你一个01串; 让你分割这个01串; 要求2切..n+1切; 对于每一种切法 所 ...
- [TyvjP1515] 子串统计 [luoguP2408] 不同子串个数(后缀数组)
Tyvj传送门 luogu传送门 经典题 统计一个字符串中不同子串的个数 一个字符串中的所有子串就是所有后缀的前缀 先求出后缀数组,求出后缀数组中相邻两后缀的 lcp 那么按照后缀数组中的顺序遍历求解 ...