Codeforces Round #524 (Div. 2) C. Masha and two friends 思路
题目:题目链接
思路:直接计数显然是不好处理的,但分情况讨论只要不写错这题是一定可以出的,但这样基本做完这个题就没时间做其他题了,但当时我就这么蠢的这样做了,比赛一个半小时的时候突然发现一个似乎可行的规律,但因为时间问题没有证,当时那个思路已经快写完了也没有换思路写,就杯具了,最后那个写了一坨的代码耗了我所有时间还错到了第四组数据。比赛结束用不到二十分钟证明并写出了那个规律的思路。最后赛后交题收获一发AC。
首先通过横纵坐标相加后的奇偶性我们可以直接判断该点的颜色,并且通过左下角颜色可以直接计算出该区域的黑白块数量,具体式子可以参考下面的代码,其次没有涂色时白色和黑色数量我们可以直接算出,然后只考虑涂白色时,我们算这个区域内黑色方块数量,更新白色和黑色方块数量,然后只考虑涂黑色方块,我们计算不考虑上次涂白色的情况下有多少白色被更新为黑色,最后考虑黑白重合的区域,对于这个区域,我们计算有多少最开始是黑色,然后被涂成白色,然后被涂成黑色并且没有在上一步计数的方块数量,这个区域坐标为(max(x1, x3),max(y1, y3)),(min(x2, x4), min(y2, y4))。
自己还是心态太差了,做题很容易紧张,尤其当时间很紧迫时,组队赛甚至因为时间问题吼过队友,,,回想自己在时间紧迫时太容易急躁了,不只是在比赛方面,生活各方面都是这样,明知道急躁时没用的还是很难改,这个题当时静下来想一下当时是可以直接换思路过的,要改呀。
AC代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <set> #define INF 0x3f3f3f3f #define FRER() freopen("in.txt", "r", stdin);
#define FREW() freopen("out.txt", "w", stdout); using namespace std; int main()
{
//FRER();
int t;
cin >> t;
long long n, m, black, white, x1, y1, x2, y2, x3, y3, x4, y4;
while(t--) {
cin >> n >> m;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
black = n * m / ;
white = n * m - black; if((x1 + y1) & ) {
white += ((x2 - x1 + ) * (y2 - y1 + ) + ) / ;
black -= ((x2 - x1 + ) * (y2 - y1 + ) + ) / ;
}
else {
white += ((x2 - x1 + ) * (y2 - y1 + )) / ;
black -= ((x2 - x1 + ) * (y2 - y1 + )) / ;
} if((x3 + y3) & ) {
black += (x4 - x3 + ) * (y4 - y3 + ) / ;
white -= (x4 - x3 + ) * (y4 - y3 + ) / ;
}
else {
black += ((x4 - x3 + ) * (y4 - y3 + ) + ) / ;
white -= ((x4 - x3 + ) * (y4 - y3 + ) + ) / ;
} long long x5 = max(x1, x3), y5 = max(y1, y3), x6 = min(x2, x4), y6 = min(y2, y4);
if(x6 >= x5 && y6 >= y5) {
if((x5 + y5) & ) {
black += ((x6 - x5 + ) * (y6 - y5 + ) + ) / ;
white -= ((x6 - x5 + ) * (y6 - y5 + ) + ) / ;
}
else {
black += ((x6 - x5 + ) * (y6 - y5 + )) / ;
white -= ((x6 - x5 + ) * (y6 - y5 + )) / ;
}
}
cout << white << " " << black << endl;
}
return ;
}
Codeforces Round #524 (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的矩阵,现在先对一个子 ...
- 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 几何:判断矩形是否相交以及相交矩形坐标
题意 :给出一个初始的黑白相间的棋盘 有两个人 第一个人先用白色染一块矩形区域 第二个人再用黑色染一块矩形区域 问最后黑白格子各有多少个 思路:这题的关键在于求相交的矩形区间 给出一个矩形的左下和 ...
- Codeforces Round #524 (Div. 2)(前三题题解)
这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...
- Codeforces Round #524 (Div. 2) Masha and two friends矩形
题目 题意: 给一个n*m块大的黑白相间的矩形,在这个举行中操作,要先把第一个矩形(左下角坐标(x1,y2),右上角坐标(x2,y2)) 全部涂成白色,再把第二个矩形(左下角坐标(x3,y3), ...
- Codeforces Round #524 (Div. 2) F. Katya and Segments Sets(主席树)
https://codeforces.com/contest/1080/problem/F 题意 有k个区间,区间的种类有n种,有m个询问(n,m<=1e5,k<=3e5),每次询问a,b ...
- Codeforces Round #524 (Div. 2) E. Sonya and Matrix Beauty(字符串哈希,马拉车)
https://codeforces.com/contest/1080/problem/E 题意 有一个n*m(<=250)的字符矩阵,对于每个子矩阵的每一行可以任意交换字符的顺序,使得每一行每 ...
- Codeforces Round #524 (Div. 2) Solution
A. Petya and Origami Water. #include <bits/stdc++.h> using namespace std; #define ll long long ...
随机推荐
- 《C#高效编程》读书笔记09-避免在API中使用转换操作符
转换操作符为类之间引入了一种"可替换性"(substitutability)."可替换性"表示一个类的实例可以替换为另一个类的实例. public class ...
- Android入门:Service入门介绍
一.Service介绍 Service类似于Windows中的服务,没有界面,只是在后台运行:而服务不能自己运行,而是需要调用Context.startService(Intent intent);或 ...
- 常见的生成全局唯一id有哪些?他们各有什么优缺点?
分布式系统中全局唯一id是我们经常用到的,生成全局id方法由很多,我们选择的时候也比较纠结.每种方式都有各自的使用场景,如果我们熟悉各种方式及优缺点,使用的时候才会更方便.下面我们就一起来看一下常见的 ...
- hibernate课程 初探单表映射1-5 hibernate第一个demo
hibernate 开发步骤:(hibernate4.2+mysql6.0) 1 hibernate配置文件(hibernate.cfg.xml) 2 持久化类 3 对象-关系映射文件 4 hiber ...
- Magento 中一个订单的“生命历程”
当我们在网上愉快的买买买的时候, 你知道在这些屏幕“背后”正在进行着什么吗? 1. 当一个产品被加入到购物车后, 实际上发生了什么? 当第一个产品被加入到购物车, 系统首先会生成一个 quote (q ...
- linux 链接的使用 创建和删除符号连接
1 . 使用方式 :ln [option] source_file dist_file -f 建立时,将同档案名删除. ...
- mybatis-分页和缓存
1.分页 1.1在dao接口中配置分页参数: package com.java1234.mappers; import java.util.List;import java.util.Map; imp ...
- 使用后台程序的第一个程序hello word
1.在advanced\backend\SiteController.php中输入 2.在advanced\backend\Views文件夹下添加名字为say.php的文件,文件名必须和控制器中的视图 ...
- mongostat查看mongodb运行状态使用命令介绍
mongostat是mongodb自带的一个用来查看mongodb运行状态的工具 使用说明 mongostat -h 字段说明 启用后的状况是这样的 insert query update del ...
- 【转】Nginx搭建反向代理服务器过程详解
阅读目录 1.1 反向代理初印象 1.2 反向代理的作用 2.1 Nginx是神马? 2.2 Nginx的应用现状 2.3 Nginx的核心特点 3.1 准备一个ASP.NET网站部署到IIS服务器集 ...