Gym - 101911H Theater Square (找规律)

The Theater Square can be represented as a rectangle having height
n
n
and length
m
m
, divided into square
1×1
1×1
cells. Let’s denote the cell located at the intersection of
i
i
-th row and
j
j
-th column as
(i,j)
(i,j)
. The rows are numbered from top to bottom, the columns — from left to right.
There is a rectangular fountain inside the Teather Square. The cell in its left upper corner is
(
x
1
,
y
1
)
(x1,y1)
, the cell in its right lower corner is
(
x
2
,
y
2
)
(x2,y2)
.
The Theater Square soon will be paved with tiles having height
1
1
and length
2
2
. Every cell (except cells inside the fountain) should be paved, and no cell should be covered by more than one tile. All tiles will be laid out horizontally, so the cells covered by each tile are in the same row. To pave the whole Theater Square it might be necessary to break some tiles. After breaking a tile, two new tiles of size
1×1
1×1
are formed (which cannot be broken further). You may consider that the mayor, who ordered the paving of the Theater Square, has infinite number of tiles
1×2
1×2
.
Since broken tiles are not beautiful, among all possible ways to pave the Theater Square the mayor wants to choose a way such that the number of tiles to be broken into two lesser tiles is minimum possible. Pay attention that tiles should be laid horizontally, no tile can cover cells in different rows.
Help the mayor! Tell him the minimum possible number of tiles to be broken.
Input
The first line contains two integers
n
n
and
m
m
(1≤n,m≤2⋅
10
5
)
(1≤n,m≤2⋅105)
— the height and the length of the Theater Square, respectively.
The second line contains four numbers
x
1
,
y
1
,
x
2
,
y
2
(1≤
x
1

x
2
≤n,1≤
y
1

y
2
≤m)
x1,y1,x2,y2 (1≤x1≤x2≤n,1≤y1≤y2≤m)
— the coordinates of left upper corner and right lower corner of the fountain.
Output
Print one number — minimum possible number of tiles mayor has to break in order to pave the whole Theater Square.
Examples
Input
6 5
1 2 3 4
Output
5
Input
6 1
3 1 4 1
Output
2
Input
1 12
1 3 1 8
Output
0
Note
One of the optimal ways to pave the Theater Square in the first example:
在这里插入图片描述
5
5
tiles are to be broken.
问题链接: http://codeforces.com/gym/101911/problem/H
问题简述: 有一个n×m大小的广场,给定喷泉左上角及右下角坐标位置。一个瓦砖大小是1×2(横着放),打碎一个瓦砖则变成1×1,判断要打碎多少个瓦砖才能铺满广场
问题分析: 一道简单的签到题,竖方向是不用管的,因为瓦砖只能横着放,求出喷泉上下左右面需要放置的1×1瓦砖数量的合除与2再加上打碎之后只需要使用一个的瓦砖数即可
AC通过的C++语言程序如下:

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<bitset>
#include<utility>
#include<functional>
#include<iomanip>
#include<sstream>
#define ll long long
#define endl '\n'
#include<ctime>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    ll n,m,x1,y1,x2,y2;
    cin>>n>>m;
    cin>>y1>>x1>>y2>>x2;
    ll h=y2-y1+1;
    ll u=((x1-1)%2)*h;
    ll v=((m-x2)%2)*h;
    ll w=(n-h)*(m%2);
    ll ans=(u+v+w)/2;
    ans+=(u+v+w)%2;
    cout<<ans;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_44012745/article/details/89073718