Codeforces 1080C- Masha and two friends

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的更多相关文章
- CodeForces - 907A Masha and Bears
A. Masha and Bears time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces 856D - Masha and Cactus(树链剖分优化 dp)
题面传送门 题意: 给你一棵 \(n\) 个顶点的树和 \(m\) 条带权值的附加边 你要选择一些附加边加入原树中使其成为一个仙人掌(每个点最多属于 \(1\) 个简单环) 求你选择的附加边权值之和的 ...
- [Codeforces]856D - Masha and Cactus
题目大意:给出一棵树和若干条可以加入的边,要求加入若干条边使图是仙人掌并且加入的边权和最大,仙人掌定义为没有一个点属于超过1个环.(n,m<=200,000) 做法:这题的仙人掌跟平时见到的不太 ...
- Codeforces 1080C 题解(思维+二维前缀和)
题面 传送门 题目大意: 有一个黑白的棋盘,现在将棋盘上的一个子矩形全部染成黑色,另一个子矩形全部染成白色 求染完色后黑,白格子的总数 分析 我们可以发现,对于一个(1,1)到(x,y)的矩形,若xy ...
- Codeforces Round #524 (Div. 2) codeforces 1080A~1080F
目录 codeforces1080A codeforces 1080B codeforces 1080C codeforces 1080D codeforces 1080E codeforces 10 ...
- 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 887B Cubes for Masha 两种暴力
B. Cubes for Masha time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- 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 - 789B B. Masha and geometric depression---(水坑 分类讨论)
CodeForces - 789B 当时题意理解的有点偏差,一直wa在了14组.是q等于0的时候,b1的绝对值大于l的时候,当b1的绝对值大于l的时候就应该直接终端掉,不应该管后面的0的. 题意告诉你 ...
- codeforces 789 B. Masha and geometric
链接 B. Masha and geometric depression 题意 给你一个等比数列的首项和公比q,然后给出一个上限l,m个数字,在这个等比数列里,小于l且没有在m个数字里面出现过的可以写 ...
随机推荐
- freeswitch 修改系统最大呼叫量
freeswitch 中有2个参数限制系统的最大呼叫量,以防止资源耗尽. max_session控制最大并发数.默认值1000:sps控制最大每秒呼叫量,默认值30 命令临时生效:fsctl max_ ...
- mvc 之 配置EF+oralce
只需要在项目中加载nuGet包就可以了 操作:工具--nuGet包管理器--程序包管理器控制台 在 PM>处输入 install-package entityframework 加载sqlser ...
- CF438E The Child and Binary Tree
思路 设F(x)的第x项系数为权值和为x的答案 题目中要求权值必须在集合中出现,这个不好处理,考虑再设一个C,C的第x项如果是1代表x出现在值域里,如果是0,代表x没有出现在值域里,然后由于二叉树可以 ...
- codeforce 955c --Sad powers 思路+二分查找
这一题的题意是 定义一个数,该数特点是为a的p次方 (a>0,p>1) 再给你n个询问,每个询问给出一个区间,求区间内该数的数目. 由于给出的询问数极大(10e5) 所以,容易想到应该 ...
- gulp点滴
var gulp = require('gulp'), connect = require('gulp-connect'), browserify = require('gulp-browserify ...
- Python自学:第三章 访问列表元素
#输出并首字母大写 bicycles = ['trek','cannondale','redline','specialized'] print(bicycles[0].title()) 输出为: T ...
- JQuery 获取select被选中的value和text
html代码: <select name="test" > <option value="0">请选择</option> & ...
- openssl dgst(生成和验证数字签名)
openssl系列文章:http://www.cnblogs.com/f-ck-need-u/p/7048359.html 该伪命令是单向加密工具,用于生成文件的摘要信息,也可以进行数字签名,验证数字 ...
- vue的组件之间传值方法
父组件 <template> <div> 这是父组件 <children v-bind:parentToChild="toChild" v-on:sh ...
- 基于c#的windows基础设计(学习日记2)【关于多态】
这次的多态很简单,没什么知识点 . 直接贴代码了: public abstract class Animal //建立一个抽象类 { private bool m_sex; private strin ...