Gym - 101350G Snake Rana(容器原理)
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 N, M, and K (1 ≤ N, M ≤ 104) (1 ≤ K ≤ 20).
The next K lines each contains distinct pair of integers x, y (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
3
2 2 1
2 2
6 6 2
5 2
2 5
10000 10000 1
1 1
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(容器原理)的更多相关文章
- Gym 101350G - Snake Rana
题意 有一个n*m的矩形,里面有k个炸弹,给出每个炸弹的坐标,计算在n*m的矩形中有多少子矩形内是不包含炸弹的. 分析 场上很是懵逼,赛后问学长说是容斥定理?一脸懵逼..容斥不是初中奥数用在集合上的东 ...
- C++智能指针,指针容器原理及简单实现(auto_ptr,scoped_ptr,ptr_vector).
目录 C++智能指针,指针容器原理及简单实现(auto_ptr,scoped_ptr,ptr_vector). auto_ptr scoped_ptr ptr_vector C++智能指针,指针容器原 ...
- 转 Spring源码剖析——核心IOC容器原理
Spring源码剖析——核心IOC容器原理 2016年08月05日 15:06:16 阅读数:8312 标签: spring源码ioc编程bean 更多 个人分类: Java https://blog ...
- 组队赛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 ...
- 4_9.springboot2.x之使用外置servlet容器原理解析
问题概述 嵌入式Servlet容器: 应用打成可执行的jar 优点:简单.便携: **缺点:**默认不支持JSP.优化定制比较复杂(使用定制器[ServerProperties.自定义WebServe ...
- Gym 100851G Generators (vector+鸽笼原理)
Problem G. Generators Input file: generators.in Output file: generators.outLittle Roman is studying li ...
- 简单解析Spring核心IOC容器原理
将大体流程解析了一边,具体可以看源代码一个方法一个方法的跟下 XmlBeanFactory的功能是建立在DefaultListableBeanFactory这个基本容器的基础上的,并在这个基本容器的基 ...
- 容斥 或者 单调栈 hihocoder #1476 : 矩形计数 和 G. Snake Rana 2017 ACM Arabella Collegiate Programming Contest
先说一个简单的题目(题目大意自己看去,反正中文):hihocoder上的:http://hihocoder.com/problemset/problem/1476 然后因为这个n和m的矩阵范围是100 ...
- C++ 顺序容器原理
容器分为顺序容器与关联容器,顺序容器也称为序列式容器.序列式容器按元素插入的顺序存储元素,这些元素可以进行排序,但未必是有序的.C++本身内置了一个序列式容器array(数组),STL另外提供了vec ...
随机推荐
- 【案例分享】crontab执行脚本异常问题
很多时候我们会遇见这种情况,我们千辛万苦写了一个脚本,经过测试,一切正常,然后放到了crontab里面执行,结果,不管怎么配置,就是执行不正常. 结果发现环境问题,居然是这个异常的元凶. 我们先在我们 ...
- linux(centos7) 常用命令和快捷键 持续验证更新中...
1.文件和目录cd 进入目录示例:cd /home 进入home目录 cd.. 返回上一级目录cd../.. 返回上两级目录cd - 返回上次所在目录cd ~ 返回根目录 ...
- SQL语句(理论)
1.SQL已经成为关系数据库的标准语言 2.SQL是一个非过程化的语言,因为他一次处理一个记录 3.SQL命令比较简单,最高级的命令几天之内便可掌握. 有属下类型的命令: 查询数据. 在表中插入.修改 ...
- AngularJS学习之旅—AngularJS SQL(十二)
一.使用 PHP 从 MySQL 中获取数据 <div ng-app="myApp" ng-controller="customersCtrl"> ...
- "'cl' 不是内部或外部命令,也不是可运行的程序"解决方案
最近使用VS2012+Qt5.1+QtCreator2.8.1来搭建Qt的开发环境(之前有用MinGW编译的经历,经常碰到gdb调试器崩溃的问题),全部换成想用VC的编译器和调试环境,但是觉得QtCr ...
- css_选择器
老师的博客:https://www.cnblogs.com/liwenzhou/p/7999532.html 参考w3 school:http://www.w3school.com.cn/css/cs ...
- python 文件名的操作
1.文件操作 open()文件句柄:获取文件的路径信息 open() 打开一个文件,获取文件句柄 read() 全部读出出文件中的内容 readline() 读取文件中逐一读取一行数据 readlin ...
- Python开发【第一篇】基础题目二
1 列表题 l1 = [11, 22, 33] l2 = [22, 33, 44] # a. 获取l1 中有,l2中没有的元素 for i in l1: if i not in l2: # b. 获取 ...
- SQL LEN() 函数
LEN() 函数 LEN 函数返回文本字段中值的长度. SQL LEN() 语法 SELECT LEN(column_name) FROM table_name SQL LEN() 实例 我们拥有下面 ...
- python学习之类的反射
在学习网络编程的时候用到反射,然后发现自己反射这部分的应用不是很熟练,决定返回来重新整理一下 对于类的反射,主要有四个用法,下面都说一下 1.hasattr 判断对象或者类是否存在指定的属性,看代码以 ...