标签:style blog http java color os
16 10 8 2 2 2 5 2 7 3 3 3 8 4 2 4 5 4 8 6 4 6 7 7 5 7 8 8 1 8 4 9 6 10 3 4 3 8 6 4 1 2 2 1 2 4 3 4 4 2 5 3 6 1 6 2 3 2 0
4 3
解题:题目比较长啊。。。开始没高清意思。。。鸟语太挫了。。。给出平面上n个点,最后要在这个平面内找出一个举行内部点数最多的指定长宽的矩形,输出最多包括的点数。
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #define LL long long 13 #define INF 0x3f3f3f 14 using namespace std; 15 const int maxn = 110; 16 int tree[maxn][maxn]; 17 int lowbit(int x) { 18 return x&(-x); 19 } 20 void update(int x,int y,int val) { 21 for(int i = x; i < maxn; i += lowbit(i)) { 22 for(int j = y; j < maxn; j += lowbit(j)) { 23 tree[i][j] += val; 24 } 25 } 26 } 27 int sum(int x,int y) { 28 int ans = 0; 29 for(int i = x; i; i -= lowbit(i)) { 30 for(int j = y; j; j -= lowbit(j)) { 31 ans += tree[i][j]; 32 } 33 } 34 return ans; 35 } 36 int main() { 37 int n,w,h,x,y; 38 while(scanf("%d",&n),n) { 39 scanf("%d%d",&w,&h); 40 memset(tree,0,sizeof(tree)); 41 for(int i = 0; i < n; i++) { 42 scanf("%d%d",&x,&y); 43 update(x,y,1); 44 } 45 scanf("%d%d",&x,&y); 46 int ans = 0,temp; 47 for(int i = x; i <= w; i++) { 48 for(int j = y; j <= h; j++) { 49 temp = sum(i,j) - sum(i-x,j) - sum(i,j-y) + sum(i-x,j-y); 50 if(temp > ans) ans = temp; 51 } 52 } 53 printf("%d\n",ans); 54 } 55 return 0; 56 }
xtu数据结构 B. Get Many Persimmon Trees,布布扣,bubuko.com
xtu数据结构 B. Get Many Persimmon Trees
标签:style blog http java color os
原文地址:http://www.cnblogs.com/crackpotisback/p/3858052.html