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 ...
随机推荐
- ORACLE 查询被锁定表及解锁释放session的方法
后台数据库操作某个表时处于假死状态,可能该表被某个用户锁定,导致其他用户无法继续操作, 如下是解决方案和实例. 查被锁的表,以及用户 SELECT object_name, machine, s.si ...
- js异步流程控制-回调
f1为耗时操作,f2依赖f1的数据,因此f2必须在f1之后执行: 个人理解是:将f2(回调函数)的代码放在异步函数内部的最后执行,相当于把同步操作的代码融合到异步函数内部的最后: let tag = ...
- 【Android】4.0 神一样的仪式感:Android第一个项目HelloWorld——eclipse
进入Eclipse,在左侧栏右击: 新建 “Android Application Project”项目,如果new之后没有,选择“Project”中“Android”目录下的 “Android Ap ...
- ECMAscript 变量作用域
使用var操作符声明的变量与未使用var操作符声明的变量区别 未使用var操作符声明 function test() { message='hi'; console.log(message); } c ...
- check_mk的性能案例
http://wiki.lustre.org/Check_MK/Graphite/Graphios_Setup_Guide Dell PowerEdge R515 2x 8-Core AMD Opte ...
- IIS10搭建FTP服务
1.首先是基本搭建 http://jingyan.baidu.com/article/0bc808fc408fa91bd585b94f.html 2.计算机—管理----本地用户和组----本地用户- ...
- Spring MVC工程 无法拦截到url请求
一直没有办法拦截到url的请求,tomcat启动也没有看到Springmvc容器启动的任何说明.所以就建立了一个普通的servlet工程,可以访问url.再重新发布springmvc项目,访问url, ...
- c#MD5加密解密
MD5的全称是Message-Digest Algorithm 5(信息-摘要算法),在90年代初由MIT Laboratory for Computer Science和RSA Data Secur ...
- HTML <meta> Attribute
HTML <meta> Attribute http-equiv 定义和用法 The http-equiv attribute provides an HTTP header for th ...
- Orchard core 中文文档翻译系列
本系列翻译顺序完全参照 官方顺序 原文地址:https://orchardcore.readthedocs.io/en/latest/ Orchard Core 中文文档翻译(一)关于Orchard ...