题目链接: http://codeforces.com/contest/1080/problem/C

思路:双向延长两个矩形方块的4边,会形成一个被分割为9块的更大立方体。

计算所有的9个方框。方框中心的点只有可能在黑框,白框或者在外面。中心点在黑框中则按照黑色渲染了棋盘计算,其余同理。

详细见代码。

注意点:

1.题目上方框的信息给出的是方块号的信息而非坐标信息。需要转换成坐标信息

2.求两者的中点得用double转换,如果用float转换精度会有偏差。

3.sort函数应该是sort(x+1, x+5),心态崩了。

 #include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
#define ll long long
//#define local using namespace std; const int MOD = 1e9+;
const int inf = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int maxn = 3e5 + ;
ll x1, x2, x3, x4;
ll y11, y2, y3, y4; int judge(ll lowx, ll lowy, ll highx, ll highy) {
double x = double(lowx + highx)/2.0;
double y = double(lowy + highy)/2.0;
if (x>x3 && x < x4 && y > y3 && y < y4) {
return ;
} else if (x>x1 && x < x2 && y > y11 && y < y2) {
return ;
} else {
return ;
}
} int main() {
#ifdef local
if(freopen("/Users/Andrew/Desktop/data.txt", "r", stdin) == NULL) printf("can't open this file!\n");
#endif int q;
scanf("%d", &q);
ll n, m;
ll x[], y[];
while (q--) {
scanf("%lld%lld", &n, &m);
ll white = n*m/;
ll black = n*m/;
if ((n*m) % ) {
white++;
}
scanf("%lld%lld%lld%lld", &x1, &y11, &x2, &y2);
scanf("%lld%lld%lld%lld", &x3, &y3, &x4, &y4);
x1 -= ; x3 -= ;
y11 -= ; y3 -= ;
x[] = x1; x[] = x2;
x[] = x3; x[] = x4;
sort(x+,x+);
y[] = y11; y[] = y2;
y[] = y3; y[] = y4;
sort(y+, y+);
for (int i = ; i < ; ++i) {
for (int j = ; j < ; ++j) {
if (x[i+]==x[i] || y[j+]==y[j]) continue;
ll tmp = (x[i+]-x[i])*(y[j+]-y[j]);
if (judge(x[i], y[j], x[i+], y[j+]) == ) {
continue;
} else if (judge(x[i], y[j], x[i+], y[j+]) == ) {
if (tmp % ) {
if ((x[i] + y[j]) % == ) {// white
white += tmp/;
black -= tmp/;
}
else {
white += tmp/ + ;
black -= (tmp/+);
}
} else {
white += tmp/;
black -= tmp/;
}
} else {
if (tmp % ) {
if ((x[i] + y[j]) % == ) {// black
white -= tmp/;
black += tmp/;
}
else {
white -= (tmp/+);
black += (tmp/+);
}
} else {
white -= tmp/;
black += tmp/;
}
}
}
}
printf("%lld %lld\n", white, black);
} #ifdef local
fclose(stdin);
#endif
return ;
}

思路2:

可以证明得到:白色与黑色相交方块的左下角坐标是:(max(x1, x3), max(y1, y3)) 右下角坐标是(min(x2, x4), min(y2, y4))

CodeForce Div 2 C. Masha and two friends的更多相关文章

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

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

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

  3. codeforce div 377

    #include <bits/stdc++.h> using namespace std; #define pb push_back #define lb lower_bound #def ...

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

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

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

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

  6. 【分类讨论】【set】Codeforces Round #407 (Div. 2) B. Masha and geometric depression

    模拟一下那个过程,直到绝对值超过l,或者出现循环为止. 如果结束之后,绝对值是超过l的,就输出当前写在黑板上的数量. 如果出现循环,则如果写在黑板上的数量非零,则输出inf(注意!如果陷入的循环是一个 ...

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

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

  8. 524 (Div. 2) Masha and two friends

    Codeforces Round #524 (Div. 2) C. Masha and two friends 题目链接 题意:较为简单,初始给定这个白黑相交的格子,第一遍把坐标范围内的全部涂白,第二 ...

  9. CodeForce 517 Div 2. B Curiosity Has No Limits

    http://codeforces.com/contest/1072/problem/B B. Curiosity Has No Limits time limit per test 1 second ...

随机推荐

  1. 2017年4月13日用VS写C程序遇到的一些问题

    在网上找到一篇展示计算机浮点数格式的文章,且有C代码如下: #include <stdio.h> #include <stdlib.h> #include <string ...

  2. xcode10关于clang -lstdc++.6.0.9报错问题

    因为xcode10已经废弃了libstdc++.6.0.9这个库,所以只需要在你的工程中删除这个库,然后添加libc++这个库就可以了.别的没什么,如果xcode10报错mutable开头的,大部分是 ...

  3. 阶段01Java基础day25网络编程

    26.01_网络编程(网络编程概述) A:计算机网络 是指将地理位置不同的具有独立功能的多台计算机及其外部设备,通过通信线路连接起来,在网络操作系统,网络管理软件及网络通信协议的管理和协调下,实现资源 ...

  4. Burpsuite安全测试测试指导

    1    Burpsuite简介 Burpsuite是一款安全领域非常重要的Web扫描工具(或者说是平台),它用于攻击Web应用程序.在Burp Suite上集成了各种扫描工具插件,各个集成插件可以组 ...

  5. EditPlus软件自动补全文档htmlbar.acp设置 及 模板文件格式

    1.在htmlbar.acp文件末尾添加如下内容,可自动补全: #T=HTML <html>    ^! </html>   #T=HEAD <head>    ^ ...

  6. c/c++ include 头文件的方式

    在编写c/c++代码时,#include 头文件有两种方式:一个是#include “文件名”,一个是#include <文件名>.区别在于: 前者在程序编译时系统首先在源程序所在的目录( ...

  7. Kali WSL折腾笔记-在Windows10上使用Kali子系统

    前言 Windows10在发布WSL(Windows Subsystem for Linux)后经过多次更新,现在使用体验已经比较良好,下面简单记录一下我在安装Kali WSL中遇到的种种问题,为各位 ...

  8. 2017年java面试题库【归类篇】

    一.Java基础 1.String类为什么是final的. 2.HashMap的源码,实现原理,底层结构. 3.说说你知道的几个Java集合类:list.set.queue.map实现类咯... 4. ...

  9. 记一次idea启动tomcat后控制台乱码的坑

    IDEA的编码配置大致跟<IntelliJ IDEA 控制台中文乱码解决方案>一样 但是启动后依旧乱码!why? 后来想起来,之前因为在win10控制台下跑tomcat乱码,所以,改过一个 ...

  10. python从零开始 -- 第2篇之python版本差异

    python从零开始 -- 第2篇之python版本差异 第0篇开始,咱们就说选择 python 3.x,一般来说,咱们面临选择的时候总是想了解更多一点,并且版本之间的对比能引申出很多有意思的故事和知 ...