AC代码

#include <bits/stdc++.h>
#define ll long long
const int maxn=1e6+10;
using namespace std;
inline ll paintw(ll x1,ll y1,ll x2,ll y2)
{
ll n=x2-x1+1;
ll m=y2-y1+1;
// 左下角是黑色,向下取整
if((x1+y1)&1)
return n*m/2;
// 左下角是白色,向上取整
else
return (n*m+1)/2;
}
inline ll paintb(ll x1,ll y1,ll x2,ll y2)
{
ll n=x2-x1+1;
ll m=y2-y1+1;
return n*m-paintw(x1,y1,x2,y2);
}
int main(int argc, char const *argv[])
{
int t;
ll n,m;
cin>>t;
ll x1,x2,x3,x4;
ll y1,y2,y3,y4;
while(t--)
{
cin>>n>>m;
cin>>x1>>y1>>x2>>y2;
cin>>x3>>y3>>x4>>y4;
// 求出第一块区域的黑色数量和第二块区域的白色数量
ll b1=paintb(x1,y1,x2,y2);
ll w2=paintw(x3,y3,x4,y4);
ll answ;
// 左下角一定是白色,所以整个区域的白色数量向上取整
// 第一块的白色数量增加b1,第二块白色数量较少w2
answ=(n*m+1)/2+b1-w2;
ll minx=min(x2,x4);ll maxx=max(x1,x3);
ll miny=min(y2,y4);ll maxy=max(y1,y3);
// 如果两区域有相交的部分,把该部分变成黑色
if(minx>=maxx&&miny>=maxy)
answ-=paintb(maxx,maxy,minx,miny);
cout<<answ<<" "<<n*m-answ<<endl;
}
return 0;
}

Codeforces 1080C- Masha and two friends的更多相关文章

  1. CodeForces - 907A Masha and Bears

    A. Masha and Bears time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  2. Codeforces 856D - Masha and Cactus(树链剖分优化 dp)

    题面传送门 题意: 给你一棵 \(n\) 个顶点的树和 \(m\) 条带权值的附加边 你要选择一些附加边加入原树中使其成为一个仙人掌(每个点最多属于 \(1\) 个简单环) 求你选择的附加边权值之和的 ...

  3. [Codeforces]856D - Masha and Cactus

    题目大意:给出一棵树和若干条可以加入的边,要求加入若干条边使图是仙人掌并且加入的边权和最大,仙人掌定义为没有一个点属于超过1个环.(n,m<=200,000) 做法:这题的仙人掌跟平时见到的不太 ...

  4. Codeforces 1080C 题解(思维+二维前缀和)

    题面 传送门 题目大意: 有一个黑白的棋盘,现在将棋盘上的一个子矩形全部染成黑色,另一个子矩形全部染成白色 求染完色后黑,白格子的总数 分析 我们可以发现,对于一个(1,1)到(x,y)的矩形,若xy ...

  5. Codeforces Round #524 (Div. 2) codeforces 1080A~1080F

    目录 codeforces1080A codeforces 1080B codeforces 1080C codeforces 1080D codeforces 1080E codeforces 10 ...

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

  7. codeforces 887B Cubes for Masha 两种暴力

    B. Cubes for Masha time limit per test 1 second memory limit per test 256 megabytes input standard i ...

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

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

  9. CodeForces - 789B B. Masha and geometric depression---(水坑 分类讨论)

    CodeForces - 789B 当时题意理解的有点偏差,一直wa在了14组.是q等于0的时候,b1的绝对值大于l的时候,当b1的绝对值大于l的时候就应该直接终端掉,不应该管后面的0的. 题意告诉你 ...

  10. codeforces 789 B. Masha and geometric

    链接 B. Masha and geometric depression 题意 给你一个等比数列的首项和公比q,然后给出一个上限l,m个数字,在这个等比数列里,小于l且没有在m个数字里面出现过的可以写 ...

随机推荐

  1. Kubernetes 路由问题&网络问题

    error 信息: kubectl 获取node的host地址 kubectl get pods -n $namespace -o wide 或者在Kubernetes的service中进行查看 ku ...

  2. visualSFM

    Ubuntu18.04配置VisualSFM参考:https://www.jianshu.com/p/cc0b548313e9 VisualSFM有GPU和NO_GPU两个版本,本文安装VisualS ...

  3. android to hide the keybord

    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hi ...

  4. 元注解——java.lang.annotation.Target(1.8)

    参考资料:https://docs.oracle.com/javase/8/docs/api/java/lang/annotation/Target.html 普通注解’只能用来注解’代码’,而’元注 ...

  5. springboot集成h2以及可视化操作

    1.新建项目

  6. ubuntu18.04中python虚拟环境的安装

    一:下载虚拟环境安装包 sudo apt install virtualenv sudo apt install virtualenvwrapper pwd  查看当前目录 ls -all 查看是否有 ...

  7. 第 8 章 容器网络 - 067 - 如何部署 Calico 网络?

    0.准备工作 Calico 是一个纯三层的虚拟网络方案,Calico 为每个容器分配一个 IP,每个 host 都是 router,把不同 host 的容器连接起来. 与 VxLAN 不同的是,Cal ...

  8. 脚本可执行,但无HTML测试报告文件生成,其造成的原因是在PyCharm的执行模式错误

    定义测试报告两种写法: 1)测试报告直接在本地绝对路径下生成 # 导入HTMLTestRunner模块 import HTMLTestRunner # 通过open()方法以二进制写模式('wb')打 ...

  9. css新单位vw,vh在响应式设计中的应用

    考虑到未来响应式设计的开发,如果你需要,浏览器的高度也可以基于百分比值调整.但使用基于百分比值并不总是相对于浏览器窗口的大小定义的最佳方式,比如字体大小不会随着你窗口改变而改变,如今css3引入的新单 ...

  10. 『TensorFlow』变量初始化

    变量初始化实质 initializer操作的流程是调用Variable节点组中的Assign节点为节点操作单元分配初始值 变量初始化方法 tf.Variable_initializer([variab ...