HDU 1077 Catching Fish(用单位圆尽可能围住多的点)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1077
Catching Fish
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2636 Accepted Submission(s): 969
Note: If a fish is just on the border of the fishnet, it is also caught by Ignatius.
Each test case starts with a positive integer N(1<=N<=300) which indicate the number of fish in the lake. Then N lines follow. Each line contains two floating-point number X and Y (0.0<=X,Y<=10.0). You may assume no two fish will at the same point, and no two fish are closer than 0.0001, no two fish in a test case are approximately at a distance of 2.0. In other words, if the distance between the fish and the centre of the fishnet is smaller 1.0001, we say the fish is also caught.
3
6.47634 7.69628
5.16828 4.79915
6.69533 6.20378
6
7.15296 4.08328
6.50827 2.69466
5.91219 3.86661
5.29853 4.16097
6.10838 3.46039
6.34060 2.41599
8
7.90650 4.01746
4.10998 4.18354
4.67289 4.01887
6.33885 4.28388
4.98106 3.82728
5.12379 5.16473
7.84664 4.67693
4.02776 3.87990
20
6.65128 5.47490
6.42743 6.26189
6.35864 4.61611
6.59020 4.54228
4.43967 5.70059
4.38226 5.70536
5.50755 6.18163
7.41971 6.13668
6.71936 3.04496
5.61832 4.23857
5.99424 4.29328
5.60961 4.32998
6.82242 5.79683
5.44693 3.82724
6.70906 3.65736
7.89087 5.68000
6.23300 4.59530
5.92401 4.92329
6.24168 3.81389
6.22671 3.62210
5
5
11
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define max_v 305
double p[max_v][];
int n;
double dis(double x1,double y1,double x2,double y2)//两点距离
{
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
double f(int i,int j)
{
double x1,y1,x2,y2,x3,y3,x4,y4,x5,y5;
x1=p[i][];
y1=p[i][]; x2=p[j][];
y2=p[j][]; double s=dis(x1,y1,x2,y2);
double xx=(y2-y1)/s;//(xx,yy)相当于与弦长垂直的单位法向量
double yy=(x1-x2)/s; s=s/2.0;
s=sqrt(1.0-s*s);//圆心与两点弦长的距离 x3=(x1+x2)/2.0;
y3=(y1+y2)/2.0;//(x3,y3)是(x1,y1),(x2,y2)的中点 int c1=,c2=; x4=x3+s*xx;
y4=y3+s*yy;//(x4,y4)现在是圆心
for(int i=;i<n;i++)
{
if(dis(x4,y4,p[i][],p[i][])<1.0001)
c1++;
} x5=x3-s*xx;
y5=y3-s*yy;//(x5,y5)现在是圆心
for(int i=;i<n;i++)
{
if(dis(x5,y5,p[i][],p[i][])<1.0001)
c2++;
} if(c1>c2)
return c1;
else
return c2; }
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%lf %lf",&p[i][],&p[i][]);
}
int temp,sum=; //暴力,每次让两点恰好位于单位圆上,算出圆心。然后找覆盖点的数目,输出最大的
for(int i=;i<n;i++)
{
for(int j=i+;j<n;j++)
{
if(dis(p[i][],p[i][],p[j][],p[j][])<2.0001)//距离大于2.0001的点可以不枚举,因为这两点肯定不在一个单位圆上
{
temp=f(i,j);
if(sum<temp)
{
sum=temp;
} }
}
}
printf("%d\n",sum);
}
return ;
}
HDU 1077 Catching Fish(用单位圆尽可能围住多的点)的更多相关文章
- hduoj 1077 Catching Fish 求单位圆最多覆盖点个数
Catching Fish Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- (水题)HDU - 1077 - Catching Fish - 计算几何
http://acm.hdu.edu.cn/showproblem.php?pid=1077 很明显这样的圆,必定有两个点在边界上.n平方枚举圆,再n立方暴力判断.由于没有给T,所以不知道行不行.
- hdu 1077(单位圆覆盖问题)
Catching Fish Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- Catching Fish[HDU1077]
Catching Fish Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDU 3395 Special Fish(拆点+最大费用最大流)
Special Fish Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- hdu 1077 (圆交)
Problem - 1077 我们可以知道,当这个单位圆可以覆盖到最多的点的时候,必定最少有两个点位于这个圆的圆周上,于是就有网上众多的O(N^3)的枚举两个在圆上的点的暴搜做法. 然而这题是可以用圆 ...
- [ACM] HDU 3395 Special Fish (最大重量二分图匹配,KM算法)
Special Fish Problem Description There is a kind of special fish in the East Lake where is closed to ...
- HDU 1077
题意 : 给你 N 个点, 问一个单位圆最大能包括几个点 直接暴力枚举圆心, 计算个数 O(n^ 3): 精度,细节都要注意, //#include<bit/stdc++.h> ...
- HDU 3469 Catching the Thief (博弈 + DP递推)
Catching the Thief Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
随机推荐
- SQL动态配置,动态解析SQL
在项目中使用SQL动态配置的方式可以让后期的维护和发布后的修改变得更加方便,无论使用那种配置方式都离不开解析成最终真正能执行的SQL.下面代码就是一种比较简单的处理方法,SQL的参数以##括起来. 1 ...
- c#.net常见字符串处理方法
1.字符串比较 字符串.ComparTo(目标字符串) "a".ComparTo("b"); 2.查找子串 字符串.IndexOf(子串,查找其实位置) ; 字 ...
- python的用户输入和while循环
1.函数input()工作原理 函数input()让程序暂停运行,等待用户输入一些文本.获取用户输入后,Python将其存储在一个变量中,以方便你使用. (1)获取数值可以用 int()函数 (2)求 ...
- 在asp.net中如何使用Session
2.那么在asp.net中到底该怎么使用Session呢? Session对象用于存储从一个用户开始访问某个特定的aspx的页面起,到用户离开为止,特定的用户会话所需要的信息.用户在应用程序的页面切换 ...
- 有关ie9 以下不支持placeholder属性以及获得焦点placeholder的移除
(一)placeholder 属性起到提示客户输入信息作用 (二)ie9以下出问题了 placeholder不支持 (三)解决办法 先贴html 加上jquery代码就可以了 关于表单获取焦点,chr ...
- ubuntu GITLAB完全导入SVN(提交历史,用户)项目
从SVN导入到GITLAB目前没有直接的方案,通常需要通过GIT转换:SVN –>GIT –>GITLAB.通过这种方式,将SVN的提交历史,用户信息一并导入到gitlab 注:本文只适用 ...
- 一个简单的 HTML 文档,带有最基本的必需的元素
<html> <head> <title>文档的标题</title> </head> <body> 文档的内容... ... & ...
- CentOS 7 使用 yum 安装 jdk 1.8
安装之前先检查一下系统有没有自带open-jdk 命令: rpm -qa |grep java rpm -qa |grep jdk rpm -qa |grep gcj 如果没有输入信息表示没有安装. ...
- SpringBoot 启动参数设置环境变量、JVM参数、tomcat远程调试
java命令的模版:java [-options] -jar jarfile [args...] 先贴一下我的简单的启动命令: java -Xms128m -Xmx256m -Xdebug -Xrun ...
- Linux下创建vue项目
前提:已经安装了node.js.cnpm 1.全局安装vue脚手架vue-cli:#cnpm install -g vue-cli 注意:全局安装没有建立软链接前是无法使用刚刚安装的vue命令的,所以 ...