CodeForce Div 2 C. Masha and two friends
题目链接: 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的更多相关文章
- 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 Round #524 (Div. 2) C. Masha and two friends
C. Masha and two friends 题目链接:https://codeforc.es/contest/1080/problem/C 题意: 给出一个黑白相间的n*m的矩阵,现在先对一个子 ...
- codeforce div 377
#include <bits/stdc++.h> using namespace std; #define pb push_back #define lb lower_bound #def ...
- Codeforces Round #524 (Div. 2) C. Masha and two friends(思维+计算几何?)
传送门 https://www.cnblogs.com/violet-acmer/p/10146350.html 题意: 有一块 n*m 的棋盘,初始,黑白块相间排列,且左下角为白块. 给出两个区间[ ...
- Codeforces Round #524 (Div. 2) C. Masha and two friends 几何:判断矩形是否相交以及相交矩形坐标
题意 :给出一个初始的黑白相间的棋盘 有两个人 第一个人先用白色染一块矩形区域 第二个人再用黑色染一块矩形区域 问最后黑白格子各有多少个 思路:这题的关键在于求相交的矩形区间 给出一个矩形的左下和 ...
- 【分类讨论】【set】Codeforces Round #407 (Div. 2) B. Masha and geometric depression
模拟一下那个过程,直到绝对值超过l,或者出现循环为止. 如果结束之后,绝对值是超过l的,就输出当前写在黑板上的数量. 如果出现循环,则如果写在黑板上的数量非零,则输出inf(注意!如果陷入的循环是一个 ...
- Codeforces Round #524 (Div. 2) C. Masha and two friends 思路
题目:题目链接 思路:直接计数显然是不好处理的,但分情况讨论只要不写错这题是一定可以出的,但这样基本做完这个题就没时间做其他题了,但当时我就这么蠢的这样做了,比赛一个半小时的时候突然发现一个似乎可行的 ...
- 524 (Div. 2) Masha and two friends
Codeforces Round #524 (Div. 2) C. Masha and two friends 题目链接 题意:较为简单,初始给定这个白黑相交的格子,第一遍把坐标范围内的全部涂白,第二 ...
- 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 ...
随机推荐
- 手把手教你如何使用Cocos2d Console 进行html5项目发布
手把手教你如何使用Cocos2d Console 进行html5项目发布 1.首先需要先安装Cocos2d Console运行需要的工具. 详情参见 这篇文章 http://www.cocoach ...
- java web后台工作原理
多时候我们都想知道,web容器或web服务器(比如Tomcat或者jboss)是怎样工作的?它们是怎样处理来自全世界的http请求的?它们在幕后做了什么动作?Java Servlet API(例如Se ...
- Python列表以及列表的处理方法
在Python中,当我们需要存储大量的数据时,可使用列表存储,列表本质是一种有序的集合 格式:列表名 = [列表元素1,列表元素2,列表元素3,...列表元素n] 如果想创建一个只有单个元素的列表,格 ...
- java 继承、重载、重写与多态
首先是java 继承.重载和重写的概念 继承: 继承的作用在于代码的复用.由于继承意味着父类的所有方法亦可在子类中使用,所以发给父类的消息亦可发给衍生类.如果Person类中有一个eat方法,那么St ...
- RabbitMQ 的安装----Linux环境
CentOS7 安装RabbitMq 参考------> https://www.cnblogs.com/liaojie970/p/6138278.html https://www.cnbl ...
- Java EE设计模式(主要简单介绍工厂模式,适配器模式和模板方法模式)
Java EE设计模式分为三种类型,共23种: 创建型模式:单例模式.抽象工厂模式.建造者模式.工厂模式.原型模式. 结构型模式:适配器模式.桥接模式.装饰模式.组合模式.外观模式.享元模式.代理模式 ...
- 使用mbedtls的使用说明和AES加密方法(原来的PolarSSL)
关于PolarSSL mbed TLS(以前称为PolarSSL)是TLS和SSL协议的实现,并且需要相应的加密算法和支持代码.这是双重许可与Apache许可证 2.0版(与GPLv2许可也可).网站 ...
- Linux 登陆配置读取顺序
Linux用户在登陆到Linux服务器时,一些登陆的提示欢迎信息,以及特定的环境配置等等都按预先设定好的配置来生效.Linux中的这个shell环境会读取很多不同的配置文件来达成上述目的,同时还有登陆 ...
- log4j 2.+框架
今天听网友介绍说Log4j2说效率比lOG4J高而且敲级好用.晚上有空就花了几个时间研究了一下.发现嗯,的确好用.我还清楚的记得Log4j1.2的时候我们需要设置log4j需要通过一个properti ...
- docker查看挂载目录Volume
使用docker inspect命令查看container的volume信息,按照书本上面敲,发现一直报错: 使用命令如下: sudo docker inspect --format "{{ ...