zoukankan      html  css  js  c++  java
  • BZOJ 3170 & 切比雪夫距离

    题意:

      给出N个点,在这N个点中选一个点使其它的点与这个点的切比雪夫距离和最小.

    SOL:

      TJOI真是...厚道还是防水...这种题目如果知道切比雪夫距离是什么那不就是傻逼题...如果不知道那不就懵逼了么...

      与随意选点不同,这种给定点中选与x,y轴还是有一定关系的.所以我们要像树上搞那什么最小距离一样搞这种东西.然后就....

    CODE:

      

    /*==========================================================================
    # Last modified: 2016-03-04 19:52
    # Filename:		3170.cpp
    # Description: 
    ==========================================================================*/
    #define me AcrossTheSky 
    #include <cstdio> 
    #include <cmath> 
    #include <ctime> 
    #include <string> 
    #include <cstring> 
    #include <cstdlib> 
    #include <iostream> 
    #include <algorithm> 
      
    #include <set> 
    #include <map> 
    #include <stack> 
    #include <queue> 
    #include <vector> 
     
    #define lowbit(x) (x)&(-x) 
    #define FOR(i,a,b) for((i)=(a);(i)<=(b);(i)++) 
    #define FORP(i,a,b) for(int i=(a);i<=(b);i++) 
    #define FORM(i,a,b) for(int i=(a);i>=(b);i--) 
    #define ls(a,b) (((a)+(b)) << 1) 
    #define rs(a,b) (((a)+(b)) >> 1) 
    #define getlc(a) ch[(a)][0] 
    #define getrc(a) ch[(a)][1] 
     
    #define maxn 130000 
    #define maxm 130000 
    #define pi 3.1415926535898 
    #define _e 2.718281828459 
    #define INF 1070000000 
    using namespace std; 
    typedef long long ll; 
    typedef unsigned long long ull; 
     
    template<class T> inline 
    void read(T& num) { 
        bool start=false,neg=false; 
        char c; 
        num=0; 
        while((c=getchar())!=EOF) { 
            if(c=='-') start=neg=true; 
            else if(c>='0' && c<='9') { 
                start=true; 
                num=num*10+c-'0'; 
            } else if(start) break; 
        } 
        if(neg) num=-num; 
    } 
    /*==================split line==================*/ 
    struct Infor{
    	double x,y;
    	int id;
    }p[maxn];
    double ans[maxn];
    int cmpx(Infor a,Infor b){return a.x<b.x;}
    int cmpy(Infor a,Infor b){return a.y<b.y;}
    int main(){ 
    	int n; read(n); 
    	double sumx=0,sumy=0;
    	FORP(i,1,n) {
    		double x,y;
    		scanf("%lf%lf",&x,&y);
    		p[i].x=(x+y)/2.0;	p[i].y=(x-y)/2.0;
    		p[i].id=i;
    		sumx+=p[i].x; sumy+=p[i].y;
    	}
    	sort(p+1,p+1+n,cmpx);
    	double temp=0;
    	FORP(i,1,n){
    		//int t=p[i].x-p[i-1].x;
    		ans[p[i].id]+=((i-1)*p[i].x)-temp;
    		ans[p[i].id]-=((n-i+1)*p[i].x-(sumx-temp));
    		temp+=p[i].x;
    	}
    	sort(p+1,p+1+n,cmpy);
    
    	temp=0;
    	FORP(i,1,n){
    		ans[p[i].id]+=(i-1)*p[i].y-temp;
    		ans[p[i].id]-=((n-i+1)*p[i].y-(sumy-temp));
    		temp+=p[i].y;
    	}
    	double out=ans[1];
    	FORP(i,1,n) out=min(out,ans[i]);
    	printf("%.0lf
    ",out);
    }
    
    Sometimes it s the very people who no one imagines anything of. who do the things that no one can imagine.
  • 相关阅读:
    Iscroll滑动无效
    原生js 无缝滚动组件
    原生 js dialog弹窗组件
    html5 历史管理
    html5拖拽属性
    highcharts 数据图设置X轴间隔显示效果
    highcharts柱状图含有正负柱设置不同颜色的方法
    移动端滑动插件 swiper
    千分位添加和去掉方法
    dubbo常用类和路径
  • 原文地址:https://www.cnblogs.com/YCuangWhen/p/5243353.html
Copyright © 2011-2022 走看看