Laser CodeForces - 15B
2018-02-16 14:57
351 查看
Laser
CodeForces - 15BPetya is the most responsible worker in the Research Institute. So he was asked to make a very important experiment: to melt the chocolate bar with a new laser device. The device consists of a rectangular field of n × m cells and a robotic arm. Each cell of the field is a 1 × 1 square. The robotic arm has two lasers pointed at the field perpendicularly to its surface. At any one time lasers are pointed at the centres of some two cells. Since the lasers are on the robotic hand, their movements are synchronized — if you move one of the lasers by a vector, another one moves by the same vector.
The following facts about the experiment are known:
initially the whole field is covered with a chocolate bar of the size n × m, both lasers are located above the field and are active;
the chocolate melts within one cell of the field at which the laser is pointed;
all moves of the robotic arm should be parallel to the sides of the field, after each move the lasers should be pointed at the centres of some two cells;
at any one time both lasers should be pointed at the field. Petya doesn't want to become a second Gordon Freeman.
You are given n, m and the cells (x1, y1) and (x2, y2), where the lasers are initially pointed at (xi is a column number, yi is a row number). Rows are numbered from 1 to m from top to bottom and columns are numbered from 1 to n from left to right. You are to find the amount of cells of the field on which the chocolate can't be melted in the given conditions.
Input The first line contains one integer number t (1 ≤ t ≤ 10000) — the number of test sets. Each of the following t lines describes one test set. Each line contains integer numbers n, m, x1, y1, x2, y2, separated by a space (2 ≤ n, m ≤ 109, 1 ≤ x1, x2 ≤ n, 1 ≤ y1, y2 ≤ m
4000
). Cells (x1, y1) and (x2, y2) are distinct.
Output Each of the t lines of the output should contain the answer to the corresponding input test set.
Example Input
2 4 4 1 1 3 3 4 3 1 1 2 2Output
8 2
题意:给出n*m的一块巧克力,再给出两个点,两点只能同时移动,两点所占位置巧克力会融化,问所有能走位置走遍之后还剩下几块巧克力。
思路:题目就是给两个矩形,然后算两个点所走位置的并集对于全集的补集。点都可以变成左上方一个点和右下方,然后可以分成两种情况。第一种是两个所走矩形不相交,第二种是相交。
上图表示相同颜色是一样长的,,图比较水,见谅。两个点表示给你的两个点。
上面表示两种情况。求得是黑框内红框外的面积。code:#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
int main(){
int t;
cin >> t;
while(t--){
int n,m,x1,y1,x2,y2;
ll a,b;
ll sum = 0;
cin >> n >> m >> x1 >> y1 >> x2 >> y2;
if(y1 > y2)
swap(y1,y2);
if(x1 > x2)
swap(x1,x2);//x1,y1是左上的点,x2,y2是右下的点
a = n - x2 + x1;//求一个红色矩形的长和宽
b = m - y2 + y1;
sum = a * b * 2;//两个矩形的面积
if(a * 2 > n && b * 2 > m){//如果重叠,减去重叠部分
sum -= (a * 2 - n) * (b * 2 - m);
}
sum = (ll)n * m - sum;
cout << sum << endl;
}
return 0;
}
相关文章推荐
- [刷题笔记]Codeforces 15B
- Review of Codeforces 5A and 5B(Python)
- Codeforces 617B Chocolate 【dp】
- [CodeForces]-675A-Infinite Sequence
- CodeForces - 729D Sea Battle(思维题)
- CodeForces - 825B Five-In-a-Row(棋盘模拟)
- Meeting --- Codeforces
- CodeForces 617B Chocolate
- CodeForces 616 D. Longest k-Good Segment(尺取)
- Codeforces-706C Hard problem
- codeforces 761D - Dasha and Very Difficult Problem
- CodeForces - 825C Multi-judge Solving(简单题)
- 【数位DP】 codeforces 55D && FZU chriswho
- codeforces 617E XOR and Favorite Number (莫队算法)
- codeforces 622D D. Optimal Number Permutation(找规律)
- codeforces 706A A. Beru-taxi
- CodeForces 437C The Child and Toy
- [贪心]codeforces - 651A Joysticks
- Codeforces #277.5 (Div. 2) B. BerSU Ball(DP:LCS)
- Codeforces 617D Polyline (Round #340 (Div. 2) D题)