Codeforces Round #524 (Div. 2) Masha and two friends矩形
题意:
给一个n*m块大的黑白相间的矩形,在这个举行中操作,要先把第一个矩形(左下角坐标(x1,y2),右上角坐标(x2,y2)) 全部涂成白色,再把第二个矩形(左下角坐标(x3,y3),右上角坐标(x4,y4)) 全部涂成黑色。 求涂了这两个矩形之后的 白色块数量和黑色块数量。
思路:
上图。因为在第二步中全涂成黑色,可能会 覆盖第一个矩形的一部分。如果先求白色块,然后通过n*m-白色再求出黑色的方法,不太好求。所以先求黑色块数量,再通过n*m-黑色 求白色。
答案黑色块的数量设为numblack ( 即nb ),nb = n*m中总的黑色数量 - s1中的黑色数量 - s2中的黑色数量 - s3中的黑色数量 + (s2+s3)的面积, 等价于nb = n*m中总的黑色数量 - (s1+s2)中的黑色数量 - (s2+s3)中的黑色数量 + s2中的黑色数量 + (s2+s3)的面积。这样比较好求。
而求一个矩形中黑色方块的数量,容易知道不是 白==黑 ,就是 白与黑相差为1(其中矩形左下角是黑色的话,黑色的数量就会比白色多1,这也是必要条件)
xx1=max(x[1],x[3]);
xx2=min(x[2],x[4]);
yy1=max(y[1],y[3]);
yy2=min(y[2],y[4]); 如果 xx1<=xx2 && yy1<=yy2 ,则有重叠面积,s2部分存在。
#include<iostream>
#include<cstdio>
#include <cctype>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<cmath>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
#define mem(a,x) memset(a,x,sizeof(a))
#define se second
#define fi first
const ll mod=;
const int INF= 0x3f3f3f3f;
const int inf= ;
const int N=1e5+; int t,n,m;
ll x[],y[];
ll nb; ll numblack(ll x1,ll y1,ll x2,ll y2)
{
// 矩形里 黑色数量要+1的唯一情况:
if((x2-x1+)%== && (y2-y1+)%== && (x1+y1)%==)
return (x2-x1+)*(y2-y1+)/ +;
else
return (x2-x1+)*(y2-y1+)/ ;
} int main()
{
cin>>t;
while(t--)
{
scanf("%d%d",&n,&m);
for(int i=;i<=;i++)
scanf("%d%d",&x[i],&y[i]); nb = numblack(,,m,n);
nb-= numblack( x[],y[],x[],y[] );
nb-= numblack( x[],y[],x[],y[] ); ll xx1=max(x[],x[]);
ll xx2=min(x[],x[]);
ll yy1=max(y[],y[]);
ll yy2=min(y[],y[]);
if(xx1<=xx2 && yy1<=yy2) //如果重叠 加上重合部分(容斥定理)
nb+= numblack( xx1,yy1,xx2,yy2 ); nb+= (x[]-x[]+)*(y[]-y[]+);
cout<<1LL*n*m-nb<<' '<<nb<<endl;
}
}
Codeforces Round #524 (Div. 2) Masha and two friends矩形的更多相关文章
- Codeforces Round #524 (Div. 2)(前三题题解)
这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...
- 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) F. Katya and Segments Sets(主席树)
https://codeforces.com/contest/1080/problem/F 题意 有k个区间,区间的种类有n种,有m个询问(n,m<=1e5,k<=3e5),每次询问a,b ...
- Codeforces Round #524 (Div. 2) E. Sonya and Matrix Beauty(字符串哈希,马拉车)
https://codeforces.com/contest/1080/problem/E 题意 有一个n*m(<=250)的字符矩阵,对于每个子矩阵的每一行可以任意交换字符的顺序,使得每一行每 ...
- Codeforces Round #524 (Div. 2) Solution
A. Petya and Origami Water. #include <bits/stdc++.h> using namespace std; #define ll long long ...
随机推荐
- 特征抽取: sklearn.feature_extraction.FeatureHasher
sklearn.feature_extraction.FeatureHasher(n_features=1048576, input_type="dict", dtype=< ...
- webpack的配置 @3.6.0
1.下载对应版本的webpack npm install webpack@3.6.0 -save --dev 2.新建webpack.config.js文件,目录结构↑ 3. >>webp ...
- LeetCode 746. 使用最小花费爬楼梯(Min Cost Climbing Stairs) 11
746. 使用最小花费爬楼梯 746. Min Cost Climbing Stairs 题目描述 数组的每个索引做为一个阶梯,第 i 个阶梯对应着一个非负数的体力花费值 cost[i].(索引从 0 ...
- 自己实现CountDownLatch
自己实现的CountDownLatch ,只是模拟他的功能而已.jdk中的实现采用的是AQS public class MyCountDownLatch { private final int tot ...
- 020 Android 常用颜色对应表
1.Android colors.xml常用颜色汇总 <?xml version="1.0" encoding="utf-8"?> <reso ...
- Zuul【文件上传】
1.搭建一个eureka-server注册中心工程 该工程比较简洁,没有太多配置,不在描述,单节点,服务端口:8888 2.创建zuul-gateway网关工程 2.1.工程pom依赖 <dep ...
- springboot项目启动报错Failed to configure a DataSource: 'url' attribute is not specified and no embedde
springboot项目启动报错Failed to configure a DataSource: 'url' attribute is not specified and no embedde 创建 ...
- 字符串char vchar性能对比补充
Value CHAR(4) Storage Required VARCHAR(4) Storage Required '' ' ' 4 bytes '' 1 byte 'ab' 'ab ' 4 ...
- PAT(B) 1033 旧键盘打字(C) 字符
题目链接:1033 旧键盘打字 (20 point(s)) 题目描述 旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现.现在给出应该输入的一段文字.以及坏掉的那些键,打出的结果文字会是 ...
- Ajax跨越请求失败,解决
跨越请求 1.1什么是跨域(两个不同系统之间的访问.调用) (1)域名不同,即两个不同的应用. (2)域名相同,但是端口不同,即同一个应用中的不同子系统. 1.2 Ajax跨域请求的缺陷 (1)创建t ...