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 ...
随机推荐
- Python第十一天 异常处理 glob模块和shlex模块 打开外部程序和subprocess模块 subprocess类 Pipe管道 operator模块 sorted函数 os模块 hashlib模块 platform模块 csv模块
Python第十一天 异常处理 glob模块和shlex模块 打开外部程序和subprocess模块 subprocess类 Pipe管道 operator模块 sorted函 ...
- python调用C程序代码
DHT11的驱动使用C语言编写 然后用python调用C的程序 显示温湿度 pycall.py文件如下: #!/usr/bin/env python # -*- coding:utf-8 -*- ...
- 微信小程序测试方法总结
最近的新项目是小程序加web端后台管理 主要找了些文章方便自己使用也分享给大家: 小程序官方文档 https://developers.weixin.qq.com/miniprogram/design ...
- 用SQL语句实现:当A列大于B列时选择A列否则选择B列,当B列大于C列时选择B列否则选择C列。
数据库中有A B C三列,用SQL语句实现:当A列大于B列时选择A列否则选择B列,当B列大于C列时选择B列否则选择C列. 方法一: select (case when a>b then a el ...
- Netty初体验
package netty_starter; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.ChannelFut ...
- 【Teradata】变更viewpoint web登录地址
1.使用root用户登录原viewpoint地址 ssh root@192.168.253.133 2.查看使用网卡(示例中为eth0) route Kernel IP routing table D ...
- Spring的单例模式底层实现
http://blog.csdn.net/cs408/article/details/48982085
- 20145203盖泽双《网络对抗技术》拓展:注入:shellcode及return-into-libc攻击
20145203盖泽双<网络对抗技术>拓展:注入:shellcode及return-into-libc攻击 一.注入:shellcode 1.编写一段用于获取Shellcode的C语言代码 ...
- 洛谷 P1101 单词方阵
题目链接 https://www.luogu.org/problemnew/show/P1101 题目描述 给一n×n的字母方阵,内可能蕴含多个"yizhong"单词.单词在方阵中 ...
- iOS开发基础-UITableView控件简单介绍
UITableView 继承自 UIScrollView ,用于实现表格数据展示,支持垂直滚动. UITableView 需要一个数据源来显示数据,并向数据源查询一共有多少行数据以及每一行显示什么 ...