【前缀和】hdu 5480 Conturbatio
2015-09-29 21:11
417 查看
hdu 5480 Conturbatio
s
加粗
斜体
引用
插入链接
插入代码
插入图片
提升标题
有序列表
无序列表
横线
撤销
重做
http://acm.hdu.edu.cn/showproblem.php?pid=5480
问题描述:前缀和前缀和很好理解:
s[1] = a[0]
s[2] = a[0] + a[1]
s[3] = a[0] + a[1] + a[2]
s
= a[0] + a[1] + a[2] + a[3] +…… + a[n-1]
若求任一序列和a[i]+……+a[j] = s[j] - s[i-1]
思路
a[i]表示第i行是否被占用,row[i]是行a[]的前缀和;同样的。另一列前缀和为col[i],如果从第i到j行都被占用,那么行前缀和要等于[i,j]总的行个数,列也是这样参考代码
#include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<vector> #include<algorithm> #include<set> #include<sstream> using namespace std; typedef long long ll; const int _max = 1e5 + 10; int n,m,k,Q,row[_max],col[_max]; int x,y; int main(){ #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); #endif // ONLINE_JUDGE int T;cin>>T; while(T--){ fill(row,row+_max,0); fill(col,col+_max,0); scanf("%d%d%d%d",&n,&m,&k,&Q); while(k--){ scanf("%d%d",&x,&y); row[x] = 1; col[y] = 1; } for(int i = 2; i <= n; ++ i) row[i] += row[i-1]; for(int j = 2; j<= m; ++ j) col[j] += col[j-1]; int x1,x2,y1,y2; for(int i = 0; i < Q; ++ i){ scanf("%d%d%d%d",&x1,&y1,&x2,&y2); if(row[x2]-row[x1-1] == x2 - x1 + 1||col[y2]-col[y1-1]==y2-y1+1) puts("Yes"); else puts("No"); } } return 0; }
加粗
Ctrl + B
斜体
Ctrl + I
引用
Ctrl + Q
插入链接
Ctrl + L
插入代码
Ctrl + K
插入图片
Ctrl + G
提升标题
Ctrl + H
有序列表
Ctrl + O
无序列表
Ctrl + U
横线
Ctrl + R
撤销
Ctrl + Z
重做
Ctrl + Y
相关文章推荐
- 2015 Multi-University Training Contest 6 Solutions
- hdu 5124 BestCoder #20 1002 lines 解题报告
- hdu 5105 Math Problem bestcoder#18 1002 求最大值
- Codeforces538F A Heap of Heaps【分块+差分求前缀和】
- 【BestCoder Round #16】
- BestCoder55 hdu5432 二分
- hduacm 5464 Clarke and problem 题解
- hduacm 5433 Xiao Ming climbing题解
- ACM hdu5432 Pyramid Split
- Hdu 5307 He is Fly 2015ACM多校对抗赛第二场
- Hdu 4609 FFT
- 2015ACM多校对抗赛第四场 hdu 5327
- cf#320 Div.2 Problem E Weakness and Poorness
- HDU 4907 Task schedule(BestCoder Round #3 )
- bc_#6
- 多线程技术模拟并行计算之二:数组前缀和(Prefix Sum)
- BZOJ 1218 HNOI 2003 激光炸弹 模拟
- HDU 4932 贪心
- BestCoder Round #20 解题报告 A.B.C.
- [Codeforces] 347B - Fixed Points