Codeforces Round #524 (Div. 2)C 二维坐标系求俩矩形面积交
题:https://codeforces.com/contest/1080/problem/C
题意:给n*m的二维坐标系,每个位置(xi,yi)都表示一个方格,(1,1)的位置是白色,整个坐标系黑白相间分布。有俩个操作,第一个操作是选定一个矩阵用白色给覆盖,第二个操作选定一个矩阵用黑色覆盖,问最后的白色块和黑色块各是多少?
分析:我们先分别独立地求这俩次操作,然后因为黑色覆盖在后,所以我们就把俩次操作可能相交的部分进行减去相应的贡献即可,也就是对面积交进行处理。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll area(ll x1,ll y1,ll x2,ll y2){
ll a=x2-x1+,b=y2-y1+;
ll ans=a*b/;
if(a*b%!=&&((x1+y1)%==))
ans++;
return ans;
}
ll cross(ll x1,ll y1,ll x2,ll y2,ll x3,ll y3,ll x4,ll y4){
ll lx=max(x1,x3);
ll ly=max(y1,y3);
ll rx=min(x2,x4);
ll ry=min(y2,y4);
if(lx>rx||ly>ry)
return ; ll a=rx-lx+,b=ry-ly+;
ll ans=a*b/;
if(a*b%!=&&((lx+ly)%==))
ans++;
return a*b-ans;
} int main()
{
int t;
cin>>t;
while(t--){
ll n,m;
cin>>n>>m;
ll x1,y1,x2,y2,x3,y3,x4,y4;
cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
///单独对第一次操作进行统计
ll sw=n*m/;//w
if((n*m)&)
sw++;
sw+=(x2-x1+)*(y2-y1+)-area(x1,y1,x2,y2);///加上覆盖白后增加的S
///单独对第二次操作进行统计
ll fullblack=area(x3,y3,x4,y4);
///面积交的部分
ll Sjiao=cross(x1,y1,x2,y2,x3,y3,x4,y4);
///处理答案
ll ans=sw-fullblack-Sjiao;
cout<<ans<<" "<<n*m-ans<<endl;
}
return ;
}
Codeforces Round #524 (Div. 2)C 二维坐标系求俩矩形面积交的更多相关文章
- 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)(前三题题解)
这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...
- Codeforces Round #524 (Div. 2) codeforces 1080A~1080F
目录 codeforces1080A codeforces 1080B codeforces 1080C codeforces 1080D codeforces 1080E codeforces 10 ...
- 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) B. Margarite and the best present
B. Margarite and the best present 题目链接:https://codeforces.com/contest/1080/problem/B 题意: 给出一个数列:an=( ...
- Codeforces Round #524 (Div. 2) D. Olya and magical square
D. Olya and magical square 题目链接:https://codeforces.com/contest/1080/problem/D 题意: 给出一个边长为2n的正方形,每次可以 ...
- Codeforces Round #524 (Div. 2) F
题解: 首先这个东西因为强制在线区间查询 所以外面得套线段树了 然后考虑几条线段怎么判定 我们只需要按照右端点排序,然后查询的时候查找最右节点的前缀最大值就可以了 然后怎么合并子区间信息呢 (刚开始我 ...
- Codeforces Round #524 (Div. 2)
A. Petya and Origamitime limit per test1 secondmemory limit per test256 megabytesinputstandard input ...
随机推荐
- MyBatis的初始化过程。
对于任何框架而言,在使用前都要进行一系列的初始化,MyBatis也不例外.本章将通过以下几点详细介绍MyBatis的初始化过程. 1.MyBatis的初始化做了什么 2. MyBatis基于XML配置 ...
- java web实现在线编辑word,并将word导出(一)
前段时间领导交代了一个需求:客户需要一个能够web在线编辑文字,如同编辑word文档一样,同时能够将编辑完成的内容导出为word文档并下载到本地. 我们选择了前台使用富文本插件的形式用于编辑内容,使用 ...
- WebSocket实现简易聊天室
前台页面: <html> <head> <meta http-equiv="Content-Type" content="text/html ...
- CentOS7使用firewalld的基本命令
转自:https://www.cnblogs.com/moxiaoan/p/5683743.html.Thanks for 莫小安 1.firewalld的基本使用 启动: systemctl ...
- you-get使用
1.pip install you-get 2.如果出错 查看错误bug you-get http://www.iqiyi.com/v_19rrnqxz7k.html#vfrm=2-4-0-1 ...
- (day 1)创建项目--3【创建应用】
创建步骤 1.打开命令行,进入项目中manage.py的同级目录 2.在命令行输入 python manage.py startapp blog 3.添加应用名到settings.py的INSTALL ...
- 转载:Apache优化:修改最大并发连接数
本文转自:https://blog.csdn.net/bjash/article/details/50394894 Apache是一个跨平台的web服务器,由于其简单.稳定安全的特性,被广泛应用于计算 ...
- IOS下的safari不支持localStorage?
同事在统计日志的时候,想用localStorag去记载一些什么,但是在各大浏览器都运行的良好的基础上,唯独IOS下的safari一直静静无声,没有任何反应.打印localStorage都是Object ...
- 01Java-方法
一:动手动脑 1.编写一个方法,使用以上算法生成指定数目(比如1000个)的随机整数 package reserve; import java.util.Scanner; import java.ut ...
- 38. docker cloud 简介及 关联 git hub
1.概念 提供 容器的管理, 编排, 部署 的托管服务 2.功能 image 管理 创建 stack 创建服务 service 添加 节点 作为 docker host 自动关联云服务商 AWS A ...