首页 > Web开发 > 详细

洛谷 P1227 [JSOI2008]完美的对称

时间:2017-11-05 18:56:01      阅读:274      评论:0      收藏:0      [点我收藏+]

传送门

题目大意:求一些点集的公共对称中心

技术分享

题解:对称中心是可以确定的,再判断。

代码:

技术分享
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define N 20009
using namespace std;

int n;

struct W{
    double x,y;
}w[N];

bool cmp(W a,W b){
    if(a.x==b.x)return a.y<b.y;
    return a.x<b.x;
}

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lf%lf",&w[i].x,&w[i].y);
    }
    sort(w+1,w+n+1,cmp);
    double xx=(w[1].x+w[n].x)/2.0;
    double yy=(w[1].y+w[n].y)/2.0;
    for(int i=2;i<=n;i++){
        if(n-i+1<=i)break;
        double tx=(w[i].x+w[n-i+1].x)/2.0;
        double ty=(w[i].y+w[n-i+1].y)/2.0;
        if(tx!=xx||ty!=yy){
            printf("This is a dangerous situation!\n");
            return 0;
        }
    }
    printf("V.I.P. should stay at (%.1lf,%.1lf).",xx,yy);
    return 0;
}
View Code

 

洛谷 P1227 [JSOI2008]完美的对称

原文:http://www.cnblogs.com/zzyh/p/7788199.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!