• POJ2526+简单几何


    题意:给定的这些点是否有一个对称中心。

    PS:我写得有点啰嗦。。

    就是把小的x和大的x进行匹配。

      1 #include<stdio.h>
      2 #include<algorithm>
      3 #include<math.h>
      4 using namespace std;
      5 
      6 const double eps = 1e-8;
      7 const int maxn = 10005;
      8 
      9 struct Point{
     10     double x,y;
     11 };
     12 Point pnt1[ maxn ],pnt2[ maxn ];
     13 Point cc;
     14 
     15 int cmp1( Point a,Point b ){
     16     return a.x<b.x;
     17 }
     18 
     19 int cmp2( Point a,Point b ){
     20     return a.y<b.y;
     21 }
     22 
     23 int cmp3( Point a,Point b ){
     24     return a.x>b.x;
     25 }
     26 
     27 bool NotOnePoint( Point a,Point b ){
     28     if( fabs(a.x-b.x)<=eps&&fabs(a.y-b.y)<=eps ) return false;
     29     else return true;
     30 }
     31 
     32 bool OK( Point a,Point b ){
     33     if( fabs((a.x+b.x)-(2.0*cc.x))<=eps && fabs((a.y+b.y)-(2.0*cc.y))<=eps ) return true;
     34     else return false;
     35 }
     36 
     37 bool Notcc( Point a ){
     38     if( fabs(a.x-cc.x)<=eps&&fabs(a.y-cc.y)<=eps ) return true;
     39     else return false;
     40 }
     41 
     42 int main(){
     43     int n;
     44     int T;
     45     //freopen("in.txt","r",stdin);
     46     scanf("%d",&T);
     47     while( T-- ){
     48         scanf("%d",&n);
     49         for( int i=1;i<=n;i++ ){
     50             scanf("%lf%lf",&pnt1[i].x,&pnt1[i].y);
     51             pnt2[ i ] = pnt1[ i ];
     52         }
     53         if( n==2 ){
     54             puts("yes");
     55             continue;
     56         }
     57         sort( pnt1+1,pnt1+1+n,cmp1 );
     58         cc.x = (pnt1[1].x+pnt1[n].x)/2.0;
     59         sort( pnt2+1,pnt2+1+n,cmp2 );
     60         cc.y = (pnt2[1].y+pnt2[n].y)/2.0;
     61         sort( pnt2+1,pnt2+1+n,cmp3 );
     62 
     63         int cnt = 0;
     64         if( n%2==1 ){
     65             for( int i=1;i<=n;i++ ){
     66                 if( pnt1[i].x==cc.x&&pnt1[i].y==cc.y ){
     67                     cnt++;
     68                 }
     69             }
     70         }
     71         if( (n-cnt)%2==1 ){
     72             puts("no");
     73             continue;
     74         }
     75         if( n==cnt ){
     76             puts("yes");
     77             continue;
     78         }
     79         //printf("cc:x = %lf,y = %lf
    ",cc.x,cc.y);
     80         /*
     81         for( int i=1;i<=n;i++ ){
     82             printf("x = %lf 
    ",pnt1[i].x);
     83         }
     84         for( int i=1;i<=n;i++ ){
     85             printf("x = %lf 
    ",pnt2[i].x);
     86         }
     87         */
     88         int tt = 0;
     89         int N = n - cnt;//N%2=0
     90         for( int i=1;i<=(n/2)&&tt<(N/2);i++ ){
     91             tt++;
     92             //printf(" i =%d ",i);
     93             //printf("pnt1:x = %lf y = %lf
    ",pnt1[i].x,pnt1[i].y);
     94             bool find = false;
     95             for( int j=1;j<=(n/2);j++ ){
     96                 //printf(" j = %d 
    ",j);
     97                 //printf("pnt2:x = %lf y = %lf
    ",pnt2[j].x,pnt2[j].y);
     98                 if( (pnt1[i].x+pnt2[j].x)<2.0*cc.x ) break;
     99                 if( /*Notcc(pnt1[i])==true&&*/NotOnePoint(pnt1[i],pnt2[j])==true&&OK(pnt1[i],pnt2[j])==true ){
    100                     find = true;
    101                     cnt += 2;
    102                     break;
    103                 }
    104             }
    105             //if( find==true ) printf("true
    ");
    106             //else printf("false
    ");
    107             if( find==false ) break;
    108         }
    109         if( cnt==n ){
    110             puts("yes");
    111             continue;
    112         }
    113         puts("no");
    114     }
    115     return 0;
    116 }
    View Code
    keep moving...
  • 相关阅读:
    BZOJ 2006: [NOI2010]超级钢琴 [ST表+堆 | 主席树]
    CF 741D. Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths [dsu on tree 类似点分治]
    CF 716E. Digit Tree [点分治]
    CF 291E. Tree-String Problem [dfs kmp trie图优化]
    CF 208E. Blood Cousins [dsu on tree 倍增]
    CF 246E. Blood Cousins Return [dsu on tree STL]
    CF 570D. Tree Requests [dsu on tree]
    [dsu on tree]【学习笔记】
    测试markdown
    BZOJ 1969: [Ahoi2005]LANE 航线规划 [树链剖分 时间倒流]
  • 原文地址:https://www.cnblogs.com/xxx0624/p/3278759.html
Copyright © 2020-2023  润新知