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的更多相关文章

  1. Codeforces Round #524 (Div. 2) Masha and two friends矩形

    题目 题意:    给一个n*m块大的黑白相间的矩形,在这个举行中操作,要先把第一个矩形(左下角坐标(x1,y2),右上角坐标(x2,y2)) 全部涂成白色,再把第二个矩形(左下角坐标(x3,y3), ...

  2. Codeforces Round #524 (Div. 2)(前三题题解)

    这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...

  3. 竞赛题解 - CF Round #524 Div.2

    CF Round #524 Div.2 - 竞赛题解 不容易CF有一场下午的比赛,开心的和一个神犇一起报了名 被虐爆--前两题水过去,第三题卡了好久,第四题毫无头绪QwQ Codeforces 传送门 ...

  4. 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 ...

  5. Codeforces Round #524 (Div. 2) C. Masha and two friends

    C. Masha and two friends 题目链接:https://codeforc.es/contest/1080/problem/C 题意: 给出一个黑白相间的n*m的矩阵,现在先对一个子 ...

  6. Codeforces Round #524 (Div. 2) C. Masha and two friends(思维+计算几何?)

    传送门 https://www.cnblogs.com/violet-acmer/p/10146350.html 题意: 有一块 n*m 的棋盘,初始,黑白块相间排列,且左下角为白块. 给出两个区间[ ...

  7. Codeforces Round #524 (Div. 2) C. Masha and two friends 几何:判断矩形是否相交以及相交矩形坐标

    题意 :给出一个初始的黑白相间的棋盘  有两个人  第一个人先用白色染一块矩形区域 第二个人再用黑色染一块矩形区域 问最后黑白格子各有多少个 思路:这题的关键在于求相交的矩形区间 给出一个矩形的左下和 ...

  8. Codeforces Round #524 (Div. 2) C. Masha and two friends 思路

    题目:题目链接 思路:直接计数显然是不好处理的,但分情况讨论只要不写错这题是一定可以出的,但这样基本做完这个题就没时间做其他题了,但当时我就这么蠢的这样做了,比赛一个半小时的时候突然发现一个似乎可行的 ...

  9. Codeforces Round #524 (Div. 2) Solution

    A. Petya and Origami Water. #include <bits/stdc++.h> using namespace std; #define ll long long ...

随机推荐

  1. redis内部数据结构深入浅出

    最大感受,无论从设计还是源码,Redis都尽量做到简单,其中运用到的原理也通俗易懂.特别是源码,简洁易读,真正做到clean and clear, 这篇文章以unstable分支的源码为基准,先从大体 ...

  2. 高性能Javascript(2) DOM编程

    第三部分 DOM编程 文档对象模型(DOM)是一个独立于语言的,使用XML和HTML文档操作的应用程序接口(API).在浏览器中,主要与HTML文档打交道,在网页应用中检索XML文档也很常见.DOM ...

  3. 关于tomcat不同版本的maxPostSize

    tomcat7.0.63之前: maxPostSize The maximum size in bytes of the POST which will be handled by the conta ...

  4. KMP算法——从入门到懵逼到了解

    本博文參考http://blog.csdn.net/v_july_v/article/details/7041827 关于其它字符串匹配算法见http://blog.csdn.net/WINCOL/a ...

  5. [docker]docker自带的overlay网络实战

    overlay网络实战 n3启动consul docker run -d -p 8500:8500 -h consul --name consul progrium/consul -server -b ...

  6. golang slice

    golang 在for range一个slice时,会读出其cap长度.在for的过程中,即使动态append该slice,最终for也会在第一次读取的cap长度处停止. package main i ...

  7. linux下yum安装最新稳定版nginx

    ## 摘抄nginx官网文档 URL:http://nginx.org/en/linux_packages.html#stable To set up the yum repository for R ...

  8. Numpy 定义矩阵的方法

    import numpy as np #https://www.cnblogs.com/xzcfightingup/p/7598293.html a = np.zeros((2,3),dtype=in ...

  9. centos7 centos中apache运行php需要连接mysql一直连不上,telnet访问mysql出错Connection closed by foreign host

    执行命令: getsebool -a|grep httpd 发现 httpd_can_network_connect off 解决:  setsebool httpd_can_network_conn ...

  10. Mac zsh切换bash bash切换zsh

    切换bash    ————>>>chsh -s /bin/bash 切换zsh      ------->>>chsh -s /bin/zsh