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个数字里面出现过的可以写 ...
随机推荐
- topcoder srm 570 div1
problem1 link 找到周期,每个周期的增量是相同的. problem2 link 对于分给某一个公司的有$c$个联通分量,其中$k$个联通分量只有1个节点,$c$个联通分量一共有$x$个节点 ...
- [CodeForces - 463B] Caisa and Pylons
题目链接:http://codeforces.com/problemset/problem/463/B 求个最大值 AC代码: #include<cstdio> #include<c ...
- 关于ComponentOne For WinForm 的全新控件 – DataFilter数据切片器(Beta)
概述 数据切片器在电子商务网站上很常见 - 它们可以帮助用户快速过滤所选商品,并且所有过滤选项都可以在一个地方使用,通常包含核心控件类型为:清单,范围栏和单选按钮等.在ComponentOne For ...
- MapReduce :基于 FileInputFormat 的 mapper 数量控制
本篇分两部分,第一部分分析使用 java 提交 mapreduce 任务时对 mapper 数量的控制,第二部分分析使用 streaming 形式提交 mapreduce 任务时对 mapper 数量 ...
- Yahoo Programming Contest 2019 F - Pass
F - Pass 思路: dp[i][j] 表示到第 i 个球为止放了 j 个蓝球的方案数 第 i 个球来自的位置的最右边是min(i, n) 转移方程看代码 代码: #pragma GCC opti ...
- vue form表单验证
<el-select v-model="ruleForm.region" placeholder="请选择活动区域"> <el-option ...
- Unity---判断某个点是否在摄像机的视景范围内
using UnityEngine; [RequireComponent(typeof(Camera))] public class VisualDetectionCamera : MonoBehav ...
- Python自学:第二章 动手试一试
print(1 + 7) print(16 - 8) print(2 * 4) print(8 / 1) 输出为: 8 8 8 8.0 message = " print("I l ...
- Android Studio 使用本地gradle配置详解
由于国内墙的原因,我们的Gradle无法使用 但是我们可以通过去下载我们想要的Gradle版本 然后再AndoidStudio内去配置本地的版本 进而去实现了Gradle的配置 注意一: so我们按照 ...
- 2015-10-19 sql1
SQL SERVER(一) 一.设置登陆验证 1.右键点击数据库->属性->安全性设置密码登陆 2.数据库下找到安全性->登录名->sa,右键点击sa->属性(修 ...