前缀和 hdu 5480 (Conturbatio)
来源:互联网 发布:未来的大数据 编辑:程序博客网 时间:2024/05/17 01:13
Conturbatio
Description
There are many rook on a chessboard, a rook can attack the row and column it belongs, including its own place.
There are also many queries, each query gives a rectangle on the chess board, and asks whether every grid in the rectangle will be attacked by any rook?
There are also many queries, each query gives a rectangle on the chess board, and asks whether every grid in the rectangle will be attacked by any rook?
Input
The first line of the input is a integer , meaning that there are test cases.
Every test cases begin with four integers .
is the number of Rook, is the number of queries.
Then lines follow, each contain two integers describing the coordinate of Rook.
Then lines follow, each contain four integers describing the left-down and right-up coordinates of query.
.
.
.
Every test cases begin with four integers
Then
Then
Output
For every query output "Yes" or "No" as mentioned above.
Sample Input
22 2 1 21 11 1 1 22 1 2 22 2 2 11 11 22 1 2 2
Sample Output
YesNoYes
题解 :前缀和。前缀算法能够从一个给定数据空间中找出其前缀特征,即前缀集合。前缀集合具有确定性,能够匹配该前缀集合的数据一定属于该数据空间,否则将一定不属于该数据空间。
#include<cstdio>#include<cstring>using namespace std;int ma[100100];int mark[100100];int main(){int t,n,m,k,q,i,j;int x,y,a,b,c,d;scanf ("%d",&t);while (t--){scanf ("%d %d %d %d",&n,&m,&k,&q);memset (mark,0,sizeof(mark));memset (ma,0,sizeof(ma));while (k--){scanf ("%d %d",&x,&y);mark[x]=1;//标记行ma[y]=1;//标记列}for (i=1;i<=n;i++)mark[i]+=mark[i-1];for (j=1;j<=m;j++)ma[j]+=ma[j-1];while (q--){scanf ("%d %d %d %d",&a,&b,&c,&d);if (c-a+1==(mark[c]-mark[a-1])||(d-b+1)==(ma[d]-ma[b-1]))printf ("Yes\n");elseprintf ("No\n");}}return 0;}
0 0
- HDU 5480:Conturbatio 前缀和
- 【前缀和】hdu 5480 Conturbatio
- HDU 5480 Conturbatio (前缀和)
- 前缀和 hdu 5480 (Conturbatio)
- HDU 5480 Conturbatio(前缀和)
- hduacm 5480 Conturbatio前缀和
- HDU 5480 Conturbatio(并查集或前缀和)
- hdu 5480 Conturbatio 区间和
- HDU5480:Conturbatio(前缀和)
- HDU 5480 Conturbatio
- Hdu 5480 Conturbatio
- hdu 5480Conturbatio
- HDU 5480 Conturbatio
- hdu 5480 Conturbatio(水)
- hdu 5480 Conturbatio【模拟】
- hdu 5480 Conturbatio
- 【HDU 5480 Conturbatio】
- HDU 5480 Conturbatio
- Shapefile格式数据去除投影坐标系
- <<App研发录:架构设计、Crash分析和竞品技术分析>>读书笔记
- LightOJ 1033
- HDU-3746 Cyclic Nacklace
- 美国历史与文化
- 前缀和 hdu 5480 (Conturbatio)
- Oracle与mysql的字段类型整理
- java设计模式_依赖倒转原则
- 手机端打开miracast
- 40. Combination Sum II [Not solved]
- Java学习提要——字符串连接
- Android环境搭建
- 垃圾陷阱(模拟\dp)
- DeepLearning:三、神经网络