题目链接: 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. python 在内网windows环境下pip三方包

    我没用过Linux环境. 一般情况下,内网安装三方包,只需要在pypi找到对应python版本(2.7,3.6,...),系统位数(32位,64位)的whl包,cmd命令行cd进入相关目录,pip i ...

  2. Python 3 基本操作列举

    1.字符串 2,列表 3.random库 计算机产生的随机数都是有一个种子开始的伪随机序列,相同的随机种子产生相同的伪随机数序列. >>> random.seed(10) >& ...

  3. 异构去堆叠 | 一种完美提升网络高可用SLA的方案

    行业内接入网络去堆叠已经逐步成为主流方向,在大型互联网公司也已经批量部署.但由于京东集团不同的业务需求及历史原因,没有条件完全复制目前主流的ARP转主机路由方式的去堆叠方案,这促使我们设计一种尽可能满 ...

  4. redis总结(一)的持久化的取舍和选择以及作用

    1.redis持久化 在客户端发布save的过程中有可能造成阻塞,如一千万条数据同时保存并生成二进制RDB文件的时候,此时就会延迟堵塞. 文件策略是如果存在老的RDB文件,会用新的文件替代老的文件如下 ...

  5. js /Date(1550273700000)/ 格式转换

    self.FormatJsonDate = function (jsonStr) { var tmp = ""; if (jsonStr == null || jsonStr == ...

  6. Curve 曲线 工具

    最近研究了曲线绘制的工具,主要是2D方程的绘制.综合了许多工具,完成了一下两个脚本. 绘制的工具: using UnityEngine; using System.Collections; using ...

  7. mysql事件调用存储过程总结

    第一次写事件调用存储过程,在网上找了一些资料,特此做下总结,巩固一下: 事件调用存储过程主要有三种: (1)创建事件马上执行,调用存储过程 CREATE EVENT if not exists Eve ...

  8. Mac下安装证书fiddlerRoot.cer

    Step 1: 设置Mac的代理如下 Step 2:打开127.0.0.1:8888,下载fiddlerRoot.cer; Step 3:下载好了,双击安装,但是默认这个证书是不可信的,你需要在钥匙串 ...

  9. 解决Exception in thread "main" java.nio.BufferOverflowException报错

    学习bytebuffer时,写了简单的demo报错: 错误的提示:Exception in thread "main" java.nio.BufferOverflowExcepti ...

  10. [C++]几种排序

    本文为大大维原创,最早于博客园发表,转载请注明出处!!! 1.冒泡: #include<cmath> #include<cstdlib> #include<ctime&g ...