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. bzoj 1835 base 基站选址 - 动态规划 - 线段树

    题目传送门 需要高级权限的传送门 题目大意 有$n$个村庄坐落在一条直线上,第$i \ \ \ (i>1)$个村庄距离第$1$个村庄的距离为$D_i$.需要在这些村庄中建立不超过$K$个通讯基站 ...

  2. bzoj1133: [POI2009]Kon

    bzoj1133: [POI2009]Kon 链接 https://www.lydsy.com/JudgeOnline/problem.php?id=1133 思路 f[i][k]表示前i个,选了k个 ...

  3. Vue常见指令

    文本相关指令 <div id="app"> <!-- 插值表达式 --> <p>{{ msg }}</p> <!-- eg:原 ...

  4. 6、zabbix使用进阶(02)

    zabbix知识点: zabbix可视化 自定义图形(graphs) 屏幕(screen) 宏(macros)  用户参数(User parameters):用户自定义items key的方式来实现自 ...

  5. 01.什么是Vue.js

    VUE.JS 什么是Vue.js Vue.js 是目前最火的一个前端框架,React是最流行的一个前端框架(React除了开发网站,还可以开发手机App, Vue语法也是可以用于进行手机App开发的, ...

  6. ckeditor5 增加居中alignment

    https://ckeditor.com/docs/ckeditor5/latest/builds/guides/integration/installing-plugins.html 克隆下来 gi ...

  7. 【shell脚本】 变量基础学习整理

    1.linux系统环境 echo 'echo /etc/profile ' >> /etc/profile echo 'echo /etc/bashrc' >> /etc/ba ...

  8. C#反射详解

    http://blog.csdn.net/educast/article/details/2894892(转) 两个现实中的例子:1.B超:大家体检的时候大概都做过B超吧,B超可以透过肚皮探测到你内脏 ...

  9. day34 GIL锁 线程队列 线程池

    一.Gil锁(Global Interpreter Lock) python全局解释器锁,有了这个锁的存在,python解释器在同一时间内只能让一个进程中的一个线程去执行,这样python的多线程就无 ...

  10. regex back-reference

    \<number>表示反向引用,引用group(number)表示的内容 最外层括号的group-id就是1,向内依次增加 ")) # output is [('111', '1 ...