[JSOI2008]完美的對稱

來源:互聯網
上載者:User

標籤:判斷   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]完美的對稱

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.