524 (Div. 2) Masha and two friends
Codeforces Round #524 (Div. 2)
C. Masha and two friends
题目链接
题意:较为简单,初始给定这个白黑相交的格子,第一遍把坐标范围内的全部涂白,第二遍把坐标范围内的全部涂黑,问最终各个颜色的数目。
思路:写一个函数,求白黑相间矩阵内的黑色格子的数目,如果格子数为偶数,白=黑。如果为奇数,当矩阵左下角坐标x1+y1为奇数,黑色多一。然后黑色格子数处理三次,第一次减少,第二次增加,第三次(重叠的部分)增加,数目为范围内的原来的黑色格子数。
知识点,判断矩阵相交
long long x5,y5,x6,y6;
x5=max(x1,x3);y5=max(y1,y3);
x6=min(x2,x4);y6=min(y2,y4);
if(x5<=x6&&y5<=y6)

#include <iostream>
#include<cstring>
#include<iomanip>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
ll n,m;
ll num_black(ll x1,ll y1,ll x2,ll y2)
{
ll ans=(x2-x1+1)*(y2-y1+1);
if(ans&1 &&(x1+y1)&1)return ans/2+1;else return ans/2;
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int t;
cin>>t;
ll n,m,x1,x2,y1,y2,x3,y3,x4,y4;
ll black;
while(t--)
{
cin>>n>>m>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
black=num_black(1,1,m,n);
black-=num_black(x1,y1,x2,y2);
// cout<<black<<endl;
black+=(x4-x3+1)*(y4-y3+1)-num_black(x3,y3,x4,y4);
// cout<<black<<endl;
ll x5,y5,x6,y6;
x5=max(x1,x3);y5=max(y1,y3);
x6=min(x2,x4);y6=min(y2,y4);
if(x5<=x6&&y5<=y6)black+=num_black(x5,y5,x6,y6);
cout<<n*m-black<<" "<<black<<endl;
}
return 0;
}
524 (Div. 2) Masha and two friends的更多相关文章
- Codeforces Round #524 (Div. 2) Masha and two friends矩形
题目 题意: 给一个n*m块大的黑白相间的矩形,在这个举行中操作,要先把第一个矩形(左下角坐标(x1,y2),右上角坐标(x2,y2)) 全部涂成白色,再把第二个矩形(左下角坐标(x3,y3), ...
- Codeforces Round #524 (Div. 2)(前三题题解)
这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...
- 竞赛题解 - CF Round #524 Div.2
CF Round #524 Div.2 - 竞赛题解 不容易CF有一场下午的比赛,开心的和一个神犇一起报了名 被虐爆--前两题水过去,第三题卡了好久,第四题毫无头绪QwQ Codeforces 传送门 ...
- Codeforces Round #524 (Div. 2) C. Masha and two friends(矩形相交)
C. Masha and two friends time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces Round #524 (Div. 2) C. Masha and two friends
C. Masha and two friends 题目链接:https://codeforc.es/contest/1080/problem/C 题意: 给出一个黑白相间的n*m的矩阵,现在先对一个子 ...
- Codeforces Round #524 (Div. 2) C. Masha and two friends(思维+计算几何?)
传送门 https://www.cnblogs.com/violet-acmer/p/10146350.html 题意: 有一块 n*m 的棋盘,初始,黑白块相间排列,且左下角为白块. 给出两个区间[ ...
- Codeforces Round #524 (Div. 2) C. Masha and two friends 几何:判断矩形是否相交以及相交矩形坐标
题意 :给出一个初始的黑白相间的棋盘 有两个人 第一个人先用白色染一块矩形区域 第二个人再用黑色染一块矩形区域 问最后黑白格子各有多少个 思路:这题的关键在于求相交的矩形区间 给出一个矩形的左下和 ...
- Codeforces Round #524 (Div. 2) C. Masha and two friends 思路
题目:题目链接 思路:直接计数显然是不好处理的,但分情况讨论只要不写错这题是一定可以出的,但这样基本做完这个题就没时间做其他题了,但当时我就这么蠢的这样做了,比赛一个半小时的时候突然发现一个似乎可行的 ...
- Codeforces Round #524 (Div. 2) Solution
A. Petya and Origami Water. #include <bits/stdc++.h> using namespace std; #define ll long long ...
随机推荐
- xcode9 报错 “Swift Language Version” (SWIFT_VERSION) build setting must be set to a supported value for targets which use Swift
用xcode编译后会出现这个错误的情况: 1.使用cocopod导入第三方swift包后,swift的包是比较老的swift开发的. 2.用xcode9 打开老的swift(比如swift2.0)的工 ...
- ASCII、Unicode和UTF-8编码的区别
归纳: 编码 大小 支持语言 ASCII 1个字节 英文 Unicode 2个字节(生僻字4个) 所有语言 UTF-8 1-6个字节,英文字母1个字节,汉字3个字节,生僻字4-6个字节 所有语言 具体 ...
- Lua Linux环境下安装
首先下载Lua包 解压缩 进入执行make linux 如果碰到lua.c:67:31: fatal error: readline/readline.h: No such file or direc ...
- ssh的tunnel隧道打洞
分正向和反向. 假设,本地机器可以ssh连上远程机器.本地机器在下面叫做SSHClient, 远程机器叫做SSHServer. 一. 正向代理(本地转发) 在SSHClient机上执行: : SSHS ...
- Godot游戏引擎 3.0 Beta2 于12月21日发布
Beta版继续在修复bug.其官方表示原计划在今年的圣诞节发布3.0 Stable版的,但看来只能继续跳票. 由于开发力量比较单薄,新版本的开发进展算是比较慢的,但3.0这个版本值得期待. Godot ...
- git push origin master和git push有什么区别?
1.master是主分支,还可以建一些其他的分支用于开发.2.git push origin master的意思就是上传本地当前分支代码到master分支.git push是上传本地所有分支代码到远程 ...
- Spring Security 使用数据库用户进行认证
本文参考或摘录自:http://haohaoxuexi.iteye.com/blog/2157769 本文使用Spring Security自带的方式连接数据库对用户进行认证. 1.Spring Se ...
- 教你一招:更新/替换系统 hosts,轻松访问国外站点
更新 hosts 下面介绍的操作均可能覆盖现有 hosts ,进行操作前请先确认是否需要备份. 推荐使用本项目的 Host Tools 来自动化 备份/配置 工作. 若更新 hosts 未立即生效,请 ...
- hdoj:2023
#include <iostream> #include <string> #include <vector> ][],b[],c[]; using namespa ...
- CSS实现响应式全屏背景图
body { /* 加载背景图 */ background-image: url(images/background-photo.jpg); /* 背景图垂直.水平均居中 */ background- ...