LOJ550 Matching 构造
题意:$T$组询问,每组询问给出一个$N \times M$的网格和一个$K$,每一次你可以消除网格中的两个块,如果两个块的曼哈顿距离小于$K$,则不会得到分数,否则得到等同于它们曼哈顿距离的分数,问最多能得到多少分数。$T \leq 10^5 , N,M \leq 10^6 , K < min(N,M)$
我们考虑网格分成四块,从左上到右下边长分别为$\lfloor \frac{M}{2} \rfloor \times \lceil \frac{N}{2} \rceil , \lfloor \frac{N}{2} \rfloor \times \lceil \frac{M}{2} \rceil , \lfloor \frac{N}{2} \rfloor \times \lceil \frac{M}{2} \rceil , \lfloor \frac{M}{2} \rfloor \times \lceil \frac{N}{2} \rceil$,就像下图这样

然后红色的和红色的一一匹配,蓝色的和蓝色的一一匹配即可,那么$K$的限制就相当于没有了
所以答案是$\lfloor \frac{M}{2} \rfloor \times \lceil \frac{N}{2} \rceil \times (\lfloor \frac{N}{2} \rfloor + \lceil \frac{M}{2} \rceil) + \lfloor \frac{N}{2} \rfloor \times \lceil \frac{M}{2} \rceil \times (\lfloor \frac{M}{2} \rfloor + \lceil \frac{N}{2} \rceil)$
注意下取整的时候一定要打上括号!!!
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
for(cin >> N ; N ; N--){
long long L , N , M;
cin >> N >> M >> L;
cout << (N / ) * ((M + ) / ) * ((N + ) / + M / ) + (N + ) / * (M / ) * (N / + (M + ) / ) << endl;
}
;
}
LOJ550 Matching 构造的更多相关文章
- Spatial Pyramid Matching 小结
Spatial Pyramid Matching 小结 稀疏编码系列: (一)----Spatial Pyramid 小结 (二)----图像的稀疏表示——ScSPM和LLC的总结 (三)----理解 ...
- Aho - Corasick string matching algorithm
Aho - Corasick string matching algorithm 俗称:多模式匹配算法,它是对 Knuth - Morris - pratt algorithm (单模式匹配算法) 形 ...
- [IR] String Matching
BWT KMP Boyer-Moore BWT [IR] BWT+MTF+AC 中已经介绍了BWT (Burrows–Wheeler_transform)数据转换算法, 这种变换方式不仅方便压缩,同时 ...
- LeetCode 失败的尝试 10. regular expression matching & 正则
Regular Expression Matching 看到正则就感觉头大,因为正则用好了就很强大.有挑战的才有意思. 其实没有一点思路.循环的话,不能一一对比,匹配模式解释的是之前的字符.那就先遍历 ...
- VK Cup 2016 - Round 1 (Div. 2 Edition) C. Bear and Forgotten Tree 3 构造
C. Bear and Forgotten Tree 3 题目连接: http://www.codeforces.com/contest/658/problem/C Description A tre ...
- real-Time Correlative Scan Matching
启发式算法(heuristic algorithm)是相对于最优化算法提出的.一个问题的最优算法求得该问题每个实例的最优解.启发式算法可以这样定义:一个基于直观或经验构造的算法,在可接受的花费(指计算 ...
- Codeforces 639B——Bear and Forgotten Tree 3——————【构造、树】
Bear and Forgotten Tree 3 time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- Codeforces Round #508 (Div. 2) E. Maximum Matching(欧拉路径)
E. Maximum Matching 题目链接:https://codeforces.com/contest/1038/problem/E 题意: 给出n个项链,每条项链左边和右边都有一种颜色(范 ...
- (第七场)A Minimum Cost Perfect Matching 【位运算】
题目链接:https://www.nowcoder.com/acm/contest/145/A A.Minimum Cost Perfect Matching You have a complete ...
随机推荐
- JS输入框正则校验
1. 开发中需要对etl组件统一进行input输入框校验,允许为空,可以不校验,默认校验长度和特殊字符,代码如下,记录以备复用. /** * 数据值校验工具类 */ var checkService ...
- PostgreSQL 10 如何使用 PgAdmin3
自从 PgAdmin4 出来以后,PgAdmin3 就停止开发了,PgAdmin 官网下载的 PgAdmin3 无法支持 PostgreSQL 10 或者更高版本的数据库服务器端. 但是 PgAdmi ...
- Selenium Webdriver 动态设置 Proxy
Step 1: Visiting "about:config" driver.get("about:config"); Step 2 : Run script ...
- c#权限验证
在开发过程中,需要对访问者的身份做权限验证(再filter中进行权限过滤). 在每次进入控制器方法之前进行调用:如 [ControllerAuth] [RoutePrefix("Clinic ...
- python第六十天-----RabbitMQ
RabbitMQ消息队列:默认为消息轮循模式,按client端启动是顺序接收 server端 import pika connection = pika.BlockingConnection(pika ...
- Linux运维面试题之--网页打开缓慢如何优化
服务器负载过高或者网页打开缓慢,简单说说你的优化思路 ? 首先我们要发现问题的过程,通过操作系统,数据库,程序设计,硬件角度四个维度找到问题所在 找到瓶颈点的位置 制定好优化方案,形成处理问题的体系 ...
- Python getting started guide
Get up in the morning. The first thing is to write a blog, although it uses machine translation, it ...
- 【转】struct和typedef struct在C/C++中的区别
分三块来讲述: 1 首先://注意在C和C++里不同 在C中定义一个结构体类型要用typedef: typedef struct Student { int a; }Stu; 于是在声明变量的时候就可 ...
- java集合类List
1.List Vector:线程安全的. ArrayList:适合查找与顺序添加. LinkedList:适合随机插入与删除. 1.1ArrayList与LinkedList的add添加 1.1.1A ...
- 【原创】Linux常用命令记录
1. 查看网络状态分布 #!/bin/sh netstat -apn >/dev/ \ | awk 'BEGIN {printf("%-15s%-15s%-15s%-15s\n&quo ...