1. 程式人生 > >[JSOI2008]完美的對稱

[JSOI2008]完美的對稱

title 技術 alt event eve dangerous 觀察 pla tps

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]完美的對稱