Old Macdonald wants to build a new hen house for his hens. He buys a new rectangular area of size N by M. The night before he builds the hen house, snake Rana devises an evil plan to plant bombs in K distinct cells in the area to kill the hens and eat them for dinner later.

The morning of, Old Macdonald notices that each of the K cells, where snake Rana planted a bomb, have a marking on them. That won’t stop him though, all he must do is build the hen house in an area with no bombs.

Assume that rows are numbered from top to bottom, and columns are numbered from left to right. Old Macdonald now wants to know the number of ways he can choose sub-rectangles of top left coordinates (x1, y1) and bottom right coordinates (x2, y2) (x1 ≤ x2) (y1 ≤ y2) such that there are no bombs in the sub rectangle.

Input

The first line of input is T – the number of test cases.

The first line of each test case is three integers NM, and K (1 ≤ N, M ≤ 104) (1 ≤ K ≤ 20).

The next K lines each contains distinct pair of integers xy (1 ≤ x ≤ N) (1 ≤ y ≤ M)- where (x, y) is the coordinate of the bomb.

Output

For each test case, output a line containing a single integer - the number of sub-rectangles that don’t contain any bombs.

Example
Input
3
2 2 1
2 2
6 6 2
5 2
2 5
10000 10000 1
1 1
Output
5
257
2500499925000000

题意:
给了一个矩阵,里面有炸弹,求不含炸弹的子矩阵个数。
思路:
状压枚举每种状况,减去奇数个炸弹的情况,加上偶数个炸弹的情况。
计算情况种数的方法,就是计算出与当前点有关的区间重合的左上角和右上角,把左上角和右上角的个数相乘就行了。
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define ls (t<<1)
#define rs ((t<<1)+1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int inf = 2.1e9;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-);
ll ans=;
int x[maxn],y[maxn];
int n,m;
void solve(int p){
int k=;
int maxx=,maxy=;
int minx=inf,miny=inf;
int t=;
while(p){
if(p&){
maxx=max(maxx,x[t]);
maxy=max(maxy,y[t]);
minx=min(minx,x[t]);
miny=min(miny,y[t]);
k++;
}
p>>=;
t++;
}
if(k&){
k=-;
}
else{
k=;
}
ans+=1ll*k*(minx)*miny*(n-maxx+)*(m-maxy+);
} int main()
{
int T;
scanf("%d",&T);
while(T--){
int k;
scanf("%d%d%d",&n,&m,&k);
int tot=<<k;
ans=1ll*n*(n+)*m*(m+)/;
for(int i=;i<=k;i++){
scanf("%d%d",&x[i],&y[i]);
} for(int i=;i<tot;i++){
solve(i);
}
printf("%lld\n",ans);
}
return ;
}

Gym - 101350G Snake Rana(容器原理)的更多相关文章

  1. Gym 101350G - Snake Rana

    题意 有一个n*m的矩形,里面有k个炸弹,给出每个炸弹的坐标,计算在n*m的矩形中有多少子矩形内是不包含炸弹的. 分析 场上很是懵逼,赛后问学长说是容斥定理?一脸懵逼..容斥不是初中奥数用在集合上的东 ...

  2. C++智能指针,指针容器原理及简单实现(auto_ptr,scoped_ptr,ptr_vector).

    目录 C++智能指针,指针容器原理及简单实现(auto_ptr,scoped_ptr,ptr_vector). auto_ptr scoped_ptr ptr_vector C++智能指针,指针容器原 ...

  3. 转 Spring源码剖析——核心IOC容器原理

    Spring源码剖析——核心IOC容器原理 2016年08月05日 15:06:16 阅读数:8312 标签: spring源码ioc编程bean 更多 个人分类: Java https://blog ...

  4. 组队赛Day1第一场 GYM 101350 G - Snake Rana (容斥)

    [题意] 给一个N×M的矩阵, K个地雷的坐标.求不含地雷的所有矩形的总数. T组数据. N M都是1e4,地雷数 K ≤ 20 Input 3 2 2 1 2 2 6 6 2 5 2 2 5 100 ...

  5. 4_9.springboot2.x之使用外置servlet容器原理解析

    问题概述 嵌入式Servlet容器: 应用打成可执行的jar 优点:简单.便携: **缺点:**默认不支持JSP.优化定制比较复杂(使用定制器[ServerProperties.自定义WebServe ...

  6. Gym 100851G Generators (vector+鸽笼原理)

    Problem G. Generators Input file: generators.in Output file: generators.outLittle Roman is studying li ...

  7. 简单解析Spring核心IOC容器原理

    将大体流程解析了一边,具体可以看源代码一个方法一个方法的跟下 XmlBeanFactory的功能是建立在DefaultListableBeanFactory这个基本容器的基础上的,并在这个基本容器的基 ...

  8. 容斥 或者 单调栈 hihocoder #1476 : 矩形计数 和 G. Snake Rana 2017 ACM Arabella Collegiate Programming Contest

    先说一个简单的题目(题目大意自己看去,反正中文):hihocoder上的:http://hihocoder.com/problemset/problem/1476 然后因为这个n和m的矩阵范围是100 ...

  9. C++ 顺序容器原理

    容器分为顺序容器与关联容器,顺序容器也称为序列式容器.序列式容器按元素插入的顺序存储元素,这些元素可以进行排序,但未必是有序的.C++本身内置了一个序列式容器array(数组),STL另外提供了vec ...

随机推荐

  1. asp.net core 2.1 部署IIS(win10/win7)

    asp.net core 2.1 部署IIS(win10/win7) 概述 与ASP.NET时代不同,ASP.NET Core不再是由IIS工作进程(w3wp.exe)托管,而是使用自托管Web服务器 ...

  2. Kafka相关内容总结(Kafka集群搭建手记)

    简介 Kafka is a distributed,partitioned,replicated commit logservice.它提供了类似于JMS的特性,但是在设计实现上完全不同,此外它并不是 ...

  3. 用idhttp打开网页或下载文件时如何显示进度

    在它的workbegin work事件中写代码 procedure TfrmDownLoad.IdHTTP1WorkBegin(Sender: TObject;   AWorkMode: TWorkM ...

  4. python3 deque(双向队列)

    创建双向队列 import collections d = collections.deque() append(往右边添加一个元素) import collections d = collectio ...

  5. Svn在工作中的实践感悟

    Svn是一款管理项目代码的版本控制系统,是基于集中式的版本控制系统.在工作中,由于实际开发工作的需要,部门是使用Svn来管理日常的项目开发任务.使用这么长时间了,来谈谈对Svn的感悟. 首先,说下工作 ...

  6. mysql导出表的字段及相关属性

    需要导出数据库中表的字段及属性,制成表格保存到word中 首先找到要导的库, 在查询页面输入sql SELECT COLUMN_NAME 列名, COLUMN_TYPE 数据类型, DATA_TYPE ...

  7. 网络流问题 P2763 试题库问题

    题目描述 «问题描述: 假设一个试题库中有n道试题.每道试题都标明了所属类别.同一道题可能有多个类别属性.现要从题库中抽取m 道题组成试卷.并要求试卷包含指定类型的试题.试设计一个满足要求的组卷算法. ...

  8. 微信小程序支付,带java源码

    先说下这个的背景吧... 本人是做java后端的,自认为还有很大的发展空间(嘻嘻,你懂的),看过一段时间的小程序可是没有支付成功...最近公司要做小程序项目,老大让我看下小程序,折腾了好几天,参照着h ...

  9. 好程序员web前端分享值得参考的css理论:OOCSS、SMACSS与BEM

    好程序员web前端分享值得参考的css理论:OOCSS.SMACSS与BEM 最近在The Sass Way里看到了Modular CSS typography一文,发现文章在开头部分就提到了OOCS ...

  10. richedit缩放

    本程序下载地址: 要使文本在richedit控件上进行放大缩小,可以通过设置字体的大小,从而来达到缩放文本的目的. 下面是一个例子:通过调整滚动条,从而控制richedit文本缩放. 程序运行结果如下 ...