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 ...
随机推荐
- Html骨架、基本语法
万丈高楼平地起,勿贪快,脚踏实地,才能仰望星空 一.HTML骨架 标准骨架 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitio ...
- DateTime类使用二:常用时间段操作(经典)
//大家在做报表或查询的时候都会有给用户预设一些可选的日期范围(如上图) //如本年度销售额.本季度利润.本月新增客户 //C#里内置的Da ...
- Java中Json字符串转换为对象的方法(多层List集合)
借鉴自:http://www.jb51.net/article/91142.htm 在将json字符串转换成对象flightInfo时,当flightInfo对象中有List<flightCla ...
- jQuery 的自定义事件
jQuery 中,想要自动触发自定义事件,必须满足2个条件: 1.事件必须是通过on 来绑定的. 2.事件必须是通过trigger / triggerHandler 来触发. 格式如下: $(fun ...
- shell脚本登录数据库
#!/bin/bashHOSTNAME="localhost" #数据库信息 PORT="3306" USERNAME="root" PAS ...
- Docker环境下的Mysql8 实现主从数据库数据同步方案
本文记录下通过MySQL Replication在Docker环境下,通过多个容器 实现数据库主从配置. MySQL Replication就不多解释了,简单说就是MySQL非常出色的一个功能,该功能 ...
- 总结vue中父向子,子向父以及兄弟之间通信的几种方式
子向父方式1:通过props,如例子中子组件test1.vue向父组件App.vue传值 App.vue代码 <template> <div id="app"&g ...
- bom与dom的区别
文档对象模型(Document Object Model,简称DOM),是W3C组织推荐的处理可扩展标志语言的标准编程接口.Document Object Model的历史可以追溯至1990年代后期微 ...
- Aforge.net识别简易数字验证码问题
参考:https://www.bbsmax.com/A/rV57LjWGdP/ https://blog.csdn.net/louislong007/article/details/47683035 ...
- tuxedo 提供buildserver命令编译服务器进程
转自:http://blog.sina.com.cn/s/blog_5413cc0f0100nbgc.html 事实上buildserver只完成预编译,它会调用当前操作系统中已经安装的默认C编译器来 ...