码迷,mamicode.com
首页 > Web开发 > 详细

[JSOI2008]完美的对称

时间:2017-05-25 01:24:29      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:判断   www   cond   jsoi2008   his   bsp   ret   color   实现   

https://www.luogu.org/problem/show?pid=1227

 

对着图片观察了一会,会发现中间点必是最远点的一半。 自己可以画个图片 思考思考。

那么就排序,算出一对最远点x,y加和的一半 之后对每对点判断?

但是如果是奇数个点呢? 那么判断一下 最后一个单独点如果不是中间点 就可以了。

 

技术分享
 1 #include <cstdio>
 2 #include <algorithm>
 3 using namespace std;
 4 struct point{
 5     int x,y;
 6 }a[20005];
 7 int n;
 8 bool CMP(point a,point b){
 9     if(a.x!=b.x) return a.x<b.x;
10     if(a.y!=b.y) return a.y<b.y;
11     return 0;
12 }
13 int main(){
14     scanf("%d",&n);
15     for(int i=1;i<=n;i++) scanf("%d%d",&a[i].x,&a[i].y);
16     sort(a+1,a+1+n,CMP);
17     double first = (a[1].x+a[n].x)/2.0;
18     double second = (a[1].y+a[n].y)/2.0;
19     for(int i=2;i<=(n/2)+1;i++){
20         if( (a[i].x+a[n-i+1].x)/2.0 != first || (a[i].y+a[n-i+1].y)/2.0 != second){
21             printf("This is a dangerous situation!\n");
22             return 0;
23         }
24     }
25     printf("V.I.P. should stay at (%.1f,%.1f).",first,second);
26     return 0;
27 }
代码实现

 

[JSOI2008]完美的对称

标签:判断   www   cond   jsoi2008   his   bsp   ret   color   实现   

原文地址:http://www.cnblogs.com/OIerLYF/p/6901558.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!