zoukankan      html  css  js  c++  java
  • hdu4001

    参考博客http://www.cppblog.com/aswmtjdsj/archive/2011/09/04/155049.aspx

    维护4根双扫描线,左右和上下。暴力枚举,复杂度O(n^2).

    #define _CRT_SECURE_NO_DEPRECATE
    #include<iostream>
    #include<algorithm>
    using namespace std;
    const int MAXN = 1001;
    struct Point{
    	int x, y;
    };
    int n, R;
    Point vx[MAXN], vy[MAXN];
    bool cmpx(Point a, Point b){
    	return a.x < b.x;
    }
    bool cmpy(Point a, Point b){
    	return a.y < b.y;
    }
    int getMAX(){
    	int l, r, u,i,j,t=0;;
    	int ans = 0;
    	for (i = 0; i < n; i++){
    		l = vx[i].x;     //左边线
    		while (t < n&&vx[t].x - l <= R)t++;
    		t--;
    		r = vx[t].x;
    		int s = 0,temp=0;
    		for (j = 0; j < n; j++){
    			u = vy[j].y;
    			while (s < n&&vy[s].y - u <= R){
    				if (vy[s].x <= r&&vy[s].x>=l)
    				    temp++;
    				s++;
    			}
    			ans = max(ans, temp);
    			//为下一次做准备
    			if (vy[j].x <= r&&vy[j].x >= l)
    				temp--;
    		}
    	}
    	return ans;
    }
    int main(){
    	while (~scanf("%d%d", &n, &R)){
    		for (int i = 0; i < n; i++){
    			scanf("%d%d", &vx[i].x, &vx[i].y);
    			vy[i] = vx[i];
    		}
    		sort(vx, vx + n, cmpx);
    		sort(vy, vy + n, cmpy);
    		int ans = getMAX();
    		printf("%d
    ", ans);
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    input框和文字对齐问题
    滚动条位置判断
    【HDOJ】2007平方和与立方和
    POJ3177 Redundant Paths
    POJ3694 Network(tarjan求桥)
    UVA315 Network
    POJ1236 Network of schools
    ZOJ1008 Gnome Tetravex
    ZOJ007 Numerical Summation of a Series(纯数学)
    ZOJ1006 Do the Untwist
  • 原文地址:https://www.cnblogs.com/td15980891505/p/5767220.html
Copyright © 2011-2022 走看看