hdu 1077 Catching Fish 计算几何+暴力枚举

简介:

   简单的暴力枚举,枚举两个点在圆上,用向量法求下圆心。复杂度o(n^3),但数据量只有300


/*
author:jxy
lang:C/C++
university:China,Xidian University
**If you need to reprint,please indicate the source**
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#define INF 1E9
using namespace std;
double X[301],Y[301];
int n,ans;
double x,y;
inline double c(int i)
{
    return (X[i]-x)*(X[i]-x)+(Y[i]-y)*(Y[i]-y);
}
int calc()//计数
{
    int i,ans=0;
    for(i=0;i<n;i++)
    {
        if(c(i)>1.0+1e-8)continue;
        ans++;
    }
    return ans;
}
void center(int i,int j)//确定圆心
{
    double x1=X[i]-X[j],y1=Y[i]-Y[j],len,k;
    double a,b;//单位向量
    if(x1==0)
        a=1,b=0;
    else if (y1==0)
        a=0,b=1;
    else
    {
        k=-1/y1*x1;
        len=sqrt(1+k*k);
        a=1.0/len;
        b=k/len;
    }
    len=1-(x1*x1+y1*y1)/4;
    if(len<0)return;
    len=sqrt(len);
    x1=(X[i]+X[j])/2.0;y1=(Y[i]+Y[j])/2.0;
    a*=len;b*=len;
    x=x1+a;y=y1+b;
    ans=max(ans,calc());
    x=x1-a;y=y1-b;
    ans=max(ans,calc());
}
int main()
{
    int T;
    int i,j;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        for(i=0;i<n;i++)
          scanf("%lf%lf",&X[i],&Y[i]);
        ans=0;
        for(i=0;i<n;i++)
          for(j=i;j<n;j++)
             center(i,j);
        printf("%d\n",ans);
    }
}


目录
相关文章
HDU7018.Banzhuan(计算几何+贪心)
HDU7018.Banzhuan(计算几何+贪心)
104 0
HDU7018.Banzhuan(计算几何+贪心)
|
人工智能 Java
[HDU 7136] Jumping Monkey | 并查集 | 逆向思维
Jumping Monkey Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 747 Accepted Submission(s): 360
223 0
[HDU 7136] Jumping Monkey | 并查集 | 逆向思维
|
人工智能 BI Go
[Atcoder ABC222] F - Expensive Expense | 妙用树的直径 | Dijkstra
Problem Statement The Kingdom of AtCoder is composed of N towns and N−1 roads. The towns are labeled as Town 1, Town 2, …, Town N. Similarly, the roads are labeled as Road 1, Road 2, …, Road N−1. Road i connects Towns Ai and Bi bidirectionally, and you have to pay the toll of Ci to go through it.
214 0
[Atcoder ABC222] F - Expensive Expense | 妙用树的直径 | Dijkstra
|
人工智能
Codeforces 220B-Little Elephant and Array-扫描线 & 树状数组
题意: 给出一个长度为n的数组,有m个询问,每次询问给出一个区间,问这个区间内有多少个数x恰好出现x次
124 0
Codeforces 220B-Little Elephant and Array-扫描线 & 树状数组
|
测试技术
HDOJ(HDU) 1859 最小长方形(水题、、)
HDOJ(HDU) 1859 最小长方形(水题、、)
78 0
|
Java BI 机器学习/深度学习