hdu 1077 Catching Fish

來源:互聯網
上載者:User
#include<stdio.h>#include<string.h>#include<algorithm>#include<iostream>#include<math.h>using namespace std;const int MAXN=330;const double eps=1e-4;double p[MAXN][2];double xx1,yy1,xx2,yy2;double dis(int i,int j){    return sqrt((p[i][0]-p[j][0])*(p[i][0]-p[j][0])+(p[i][1]-p[j][1])*(p[i][1]-p[j][1]));}void get_center_point(int a,int b){    double x0=(p[a][0]+p[b][0])/2;    double y0=(p[a][1]+p[b][1])/2;    double d=sqrt(1-((p[a][0]-p[b][0])*(p[a][0]-p[b][0])+(p[a][1]-p[b][1])*(p[a][1]-p[b][1]))/4);    if(fabs(p[a][1]-p[b][1])<1e-6)    {        xx1=x0;        yy1=y0+d;        xx2=x0;        yy2=y0-d;    }    else    {        double tmp=atan(-(p[a][0]-p[b][0])/(p[a][1]-p[b][1]));        double dx=d*cos(tmp);        double dy=d*sin(tmp);        xx1=x0+dx;        yy1=y0+dy;        xx2=x0-dx;        yy2=y0-dy;    }}int main(){    int T;    int n;    scanf("%d",&T);    while(T--)    {        scanf("%d",&n);        for(int i=0;i<n;i++)           scanf("%lf%lf",&p[i][0],&p[i][1]);        int ans=1;        for(int i=0;i<n;i++)          for(int j=i+1;j<n;j++)          {              if(dis(i,j)>2.0)continue;              get_center_point(i,j);              int cnt=0;              for(int i=0;i<n;i++)                if(sqrt((p[i][0]-xx1)*(p[i][0]-xx1)+(p[i][1]-yy1)*(p[i][1]-yy1))<1+eps)                  cnt++;              if(cnt>ans)ans=cnt;              cnt=0;              for(int i=0;i<n;i++)                if(sqrt((p[i][0]-xx2)*(p[i][0]-xx2)+(p[i][1]-yy2)*(p[i][1]-yy2))<1+eps)                  cnt++;              if(cnt>ans)ans=cnt;          }        printf("%d\n",ans);    }    return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.