题目链接: 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. 20190219备份 java spring boot 学习链接(日/英)

    Building web applications with Spring Boot and Kotlin https://www.slideshare.net/masuda220/spring-82 ...

  2. 关于org.apache.jasper.JasperException解决方法

    没有导入jstl.jar包 解决办法:在项目pom.xml中添加maven项目的jstl.jar 如果导入jstl.jar包 解决办法:检查jstl.jar版本是否与项目兼容,不兼容则切换jstl.j ...

  3. lvs用户空间命令ipvsadm

    ipvs工作在内核空间,而ipvsadm工作在用户空间,是负责管理集群服务编写规则的命令行工具 ipvsadm需要手动安装. $ yum -y install ipvsadm ipvsadm管理命令 ...

  4. Oracle组成介绍

    Oracle Database 11g是一些特殊文件的集合,这些文件是用数据库配置助手创建的,然后用OEM Grid Control完成相关工作.这些数据库文件是通过一组共享内存进程来进行访问的,这组 ...

  5. web传输过程中的gzip压缩

    最近在做项目的时候用到了gzip,发现它的压缩能力还是很强大的,基本能够压缩50%的文本文件大小.以前有所了解,但不够深入,现在详细了解下. 什么是gzip 在哪里使用gzip gzip对于不同类型文 ...

  6. Nginx+Tomcat配置负载均衡-动静分离(二)

    配置动静分离的时候遇到了一些问题,一个是配置nginx配置文件有问题导致访问不到服务器,另一个问题是配置静态资源的路径和实际的资源目录不匹配导致404,502等错误 结合上一篇的基础,在此将动静分离的 ...

  7. 生物信息学工具--bowtie&bowtie2

    Bowtie和Bowtie2使用 [怪毛匠子整理] Source URL: http://www.bbioo.com/lifesciences/40-112837-1.html Bowtie和Bowt ...

  8. 【Java】关于项目启动大请求量高负载时如何确保db等资源不出错的问题

      如果一个项目启动时(单机), 瞬间来了1000个访问, 如何确保db等资源不会压垮呢? 现在想想我当时回答的并不好, 而现在看公司框架才发现其实有针对于这一块做过专门的优化的.下面就来分享下公司关 ...

  9. Beta发布用户使用报告

    用户数量:13人 姓名如下(包括化名):张小斌.王瑞瑞.蛋蛋.小美.晨曦.小丽.张利刚.小闫.小谢.小崔.小欢欢.小胡胡.小霞霞 寻找的用户多为王者荣耀交流协会成员的同学,对PSP Daily软件有极 ...

  10. CAShapeLayer绘图

    之前讲过使用UIBezierPath在UIView的drawRect中绘图, 今天我们讲下另外一种方式: CAShaperLayer 先说说使用CAShapeLayer的优点: GPU执行, GPU执 ...