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 ...
随机推荐
- twindows下omcat8安装后,不能启动服务
原因可能是cmd安装时,不是以管理员的身份运行cmd命令的.解决办法,以管理员身份运行cmd,进入tomcat安装/解压的bin目录下,先执行 service.bat remove 命令卸载服务,之后 ...
- Android基础之6.0系统以上的权限分配
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle saved ...
- oh-my-zsh安装与使用
使用oh-my-zsh之前确保安装过zsh 通过脚本安装: sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussel ...
- Ubuntu18.04 更换源
在虚拟机新建一个Ubuntu18.04.1-live-server-amd64当做服务器 在安装软件时报错: slave@slave:~$ sudo -s[sudo] password for sla ...
- php开发中遇到的一些问题
php警告提示A session had already been started – ignoring session_start() 解决方案 判断 如果session_id 不存在,说明没有储存 ...
- 【PAT】B1044 火星数字(20 分)
/* 火星文有两位,第二位为0不输出 */ #include<stdio.h> #include<algorithm> #include<string.h> #in ...
- 串口-CreateFile的使用
在32位的windows系统中,串口和其他通信设备是作为文件处理的.对串口的操作和对文件的操作是完全一样的.通信以调用CreateFile()开始. 函数原型如下: HANDLE CreateFile ...
- Orcale新增、修改、删除字段
一.新增字段 alert table user add( userName VARCHAR2(255 CHAR) ) ; 设置字段不为空, 给出默认值 alert table user add( us ...
- Beta冲刺! Day4 - 砍柴
Beta冲刺! Day4 - 砍柴 今日已完成 晨瑶:追进度 昭锡:改主页UI(还在 永盛:完成大部分接口和接口文档,上线代码 立强:文章去广告,适配手机屏幕.第三方编辑器整合到记录模块. 炜鸿:完成 ...
- Ceph基础知识和基础架构认识
1 Ceph基础介绍 Ceph是一个可靠地.自动重均衡.自动恢复的分布式存储系统,根据场景划分可以将Ceph分为三大块,分别是对象存储.块设备存储和文件系统服务.在虚拟化领域里,比较常用到的是Cep ...