博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Snake Rana Gym - 101350G
阅读量:4114 次
发布时间:2019-05-25

本文共 1419 字,大约阅读时间需要 4 分钟。

题目:

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.

有一个大的矩形区域,其中一些地方中有炸弹,现在问你有多少中矩阵的取法,使得任何一个矩阵里面都不包含炸弹。

思路:这个题是一个计数问题,我们可以使用容斥的方法去做,首先求出能构成矩阵的所有方案,相当于是在(n+1)条边中取两条边,在(m+1)条边中取两条边,得到总的方案数(n+1)*n/2*(m+1)*m/2,然后在减去包含奇数个炸弹的方案数,这时会多减掉一些部分,所以我们要在加上包含偶数个炸弹的方案数,想求包含几个炸弹,由于总炸弹的数量比较少,所以我们使用二进制的方式来判断包含的炸弹数。

#include 
using namespace std;const int maxn=1e4;const long long inf=1e9;struct Node{ long long x,y;} node[maxn];int main(){ int T; cin>>T; while(T--) { long long n,m,k; cin>>n>>m>>k; for(int i=0; i
>node[i].x>>node[i].y; } long long ans=(long long)(n+1)*n/2*(m+1)*m/2;// cout<
<

转载地址:http://ubgsi.baihongyu.com/

你可能感兴趣的文章
9个月的婴儿的喂养
查看>>
宝宝出牙顺序图
查看>>
XML简单读写
查看>>
10款宝宝最爱的家常辅食
查看>>
Visual Studio 2005 开发WPF应用程序系列文章——什么是WPF
查看>>
利用 Office 的 OWC 做报表
查看>>
怎样成为优秀的软件模型设计者
查看>>
面向对象软件设计的“开—闭”原则
查看>>
Visual C#2005中的匿名委托的实现
查看>>
C#几种常用的排序算法
查看>>
C#中调用Windows API的要点
查看>>
C#开发终端式短信的原理和方法
查看>>
使用P/Invoke来开发用于与串行设备通讯的.NET基类
查看>>
NET 2.0 中的自定义配置处理
查看>>
区别C#中的两个属性(Property和Attribute)
查看>>
利用反射来动态创建实例和调用方法
查看>>
Winform中多国语言窗体的设计以及.NET中资源文件的使用
查看>>
61条面向对象设计的经验原则---Arthur J.Riel
查看>>
.NET反编译工具Reflector及插件
查看>>
2007中国理财年度人物评选榜单揭晓
查看>>