zoukankan      html  css  js  c++  java
  • poj 1981 Circle and Points

    题目链接:http://poj.org/problem?id=1981

    解题思路:枚举两个点,求过这两点的单位圆,判断有多少个点在圆中。

      1 ///////////////////////////////////////////////////////////////////////////
      2 //problem_id: poj 1981
      3 //user_id: SCNU20102200088
      4 ///////////////////////////////////////////////////////////////////////////
      5 
      6 #include <algorithm>
      7 #include <iostream>
      8 #include <iterator>
      9 #include <iomanip>
     10 #include <cstring>
     11 #include <cstdlib>
     12 #include <string>
     13 #include <vector>
     14 #include <cstdio>
     15 #include <cctype>
     16 #include <cmath>
     17 #include <queue>
     18 #include <stack>
     19 #include <list>
     20 #include <set>
     21 #include <map>
     22 using namespace std;
     23 
     24 ///////////////////////////////////////////////////////////////////////////
     25 typedef long long LL;
     26 const double EPS=1e-8;
     27 const double PI=acos(-1.0);
     28 
     29 const int x4[]={-1,0,1,0};
     30 const int y4[]={0,1,0,-1};
     31 const int x8[]={-1,-1,0,1,1,1,0,-1};
     32 const int y8[]={0,1,1,1,0,-1,-1,-1};
     33 
     34 typedef int T;
     35 T max(T a,T b){ return a>b? a:b; }
     36 T min(T a,T b){ return a<b? a:b; }
     37 ///////////////////////////////////////////////////////////////////////////
     38 
     39 ///////////////////////////////////////////////////////////////////////////
     40 //Add Code:
     41 struct Point{
     42     double x,y;
     43     Point(double dx=0,double dy=0):x(dx),y(dy){}
     44 }p[305];
     45 
     46 double dist(Point a,Point b){
     47     return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
     48 }
     49 
     50 Point circle(Point a,Point b){
     51     Point mid((a.x+b.x)/2,(a.y+b.y)/2);
     52     double angle=atan2(a.x-b.x,b.y-a.y);
     53     double d=sqrt(1-dist(a,mid)*dist(a,mid));
     54     Point ret(mid.x+d*cos(angle),mid.y+d*sin(angle));
     55     return ret;
     56 }
     57 ///////////////////////////////////////////////////////////////////////////
     58 
     59 int main(){
     60     ///////////////////////////////////////////////////////////////////////
     61     //Add Code:
     62     int n,i,j,k;
     63     while(scanf("%d",&n)!=EOF){
     64         if(n==0) break;
     65         for(i=0;i<n;i++) scanf("%lf%lf",&p[i].x,&p[i].y);
     66         int Max=1;
     67         for(i=0;i<n;i++){
     68             for(j=i+1;j<n;j++){
     69                 if(dist(p[i],p[j])>2.0) continue;
     70                 Point center=circle(p[i],p[j]);
     71                 int num=0;
     72                 for(k=0;k<n;k++){
     73                     if(dist(center,p[k])<1.0+EPS) num++;
     74                 }
     75                 Max=max(Max,num);
     76             }
     77         }
     78         printf("%d
    ",Max);
     79     }
     80     ///////////////////////////////////////////////////////////////////////
     81     return 0;
     82 }
     83 
     84 ///////////////////////////////////////////////////////////////////////////
     85 /*
     86 Testcase:
     87 Input:
     88 3
     89 6.47634 7.69628
     90 5.16828 4.79915
     91 6.69533 6.20378
     92 6
     93 7.15296 4.08328
     94 6.50827 2.69466
     95 5.91219 3.86661
     96 5.29853 4.16097
     97 6.10838 3.46039
     98 6.34060 2.41599
     99 8
    100 7.90650 4.01746
    101 4.10998 4.18354
    102 4.67289 4.01887
    103 6.33885 4.28388
    104 4.98106 3.82728
    105 5.12379 5.16473
    106 7.84664 4.67693
    107 4.02776 3.87990
    108 20
    109 6.65128 5.47490
    110 6.42743 6.26189
    111 6.35864 4.61611
    112 6.59020 4.54228
    113 4.43967 5.70059
    114 4.38226 5.70536
    115 5.50755 6.18163
    116 7.41971 6.13668
    117 6.71936 3.04496
    118 5.61832 4.23857
    119 5.99424 4.29328
    120 5.60961 4.32998
    121 6.82242 5.79683
    122 5.44693 3.82724
    123 6.70906 3.65736
    124 7.89087 5.68000
    125 6.23300 4.59530
    126 5.92401 4.92329
    127 6.24168 3.81389
    128 6.22671 3.62210
    129 0
    130 Output:
    131 2
    132 5
    133 5
    134 11
    135 */
    136 ///////////////////////////////////////////////////////////////////////////
  • 相关阅读:
    定制自己的PHP语法-在PHP中实现unless
    欢迎使用CSDN-markdown编辑器
    在 Laravel 中通过 Artisan View 扩展包创建及删除应用视图文件
    直接可用的loading.js
    vue后退判断是否有历史记录,有就返回上一级,否则返回指定路由
    js防抖和节流
    IE增加Meta标签(IE=Edge,chrome=1)兼容IE问题
    如何覆盖 node_modules 里的文件
    js运行代码计时器
    vue打包font字体文件路径错误的问题处理
  • 原文地址:https://www.cnblogs.com/linqiuwei/p/3288190.html
Copyright © 2011-2022 走看看