HDU 1077Catching Fish(简单计算几何)
Catching Fish
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1113 Accepted Submission(s): 411
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
题目大意:给你n个点的横纵坐标,问你用一个单位圆,最多能使得多少点在圆内,包括圆上的点。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdio>
using namespace std;
int n;
struct node
{
double x;
double y;
};
node a[305]; double dis(node p1,node p2)
{
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
} int cal(int p1,int p2)
{
node t1,t2,t3,t4;
t1=a[p1],t2=a[p2];
double s,tmp,xx,yy;
tmp=dis(t1,t2);
s=tmp/2.0;
s=sqrt(1.0-s*s); //s为圆心到t1,t2弦长的距离
int ans1=0,ans2=0,i;
xx=(t1.y-t2.y)/tmp;
yy=(t2.x-t1.x)/tmp; //(xx,yy)相当于与弦长垂直的单位法向量
t3.x=(t1.x+t2.x)/2.0,t3.y=(t1.y+t2.y)/2.0;
t4.x=t3.x+s*xx,t4.y=t3.y+s*yy; //t4为圆心
for(i=0;i<n;i++)
{
if(dis(t4,a[i])<1.0001)
ans1++;
}
t4.x=t3.x-s*xx,t4.y=t3.y-s*yy; //t4为圆心
for(i=0;i<n;i++)
{
if(dis(t4,a[i])<1.0001)
ans2++;
}
return ans1>ans2?ans1:ans2;
} int main()
{
int i,j;
int tes;
scanf("%d",&tes); while(tes--)
{
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%lf%lf",&a[i].x,&a[i].y);
int num;
int res=1;
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
{
if(dis(a[i],a[j])<2.0001)
{
num=cal(i,j);
if(num>res) res=num;
}
} printf("%d\n",res);
}
return 0;
} //2406MS
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdio>
using namespace std;
int n;
double a[305][2]; double dis(double *b1,double *b2)
{
return sqrt((b1[0]-b2[0])*(b1[0]-b2[0])+(b1[1]-b2[1])*(b1[1]-b2[1]));
} int cal(int p1,int p2)
{
double t1[2],t2[2],t3[2],t4[2];
t1[0]=a[p1][0],t1[1]=a[p1][1],t2[0]=a[p2][0],t2[1]=a[p2][1];
double s,tmp,xx,yy;
tmp=dis(t1,t2);
s=tmp/2.0;
s=sqrt(1.0-s*s); //s为圆心到t1,t2弦长的距离
int ans1=0,ans2=0,i;
xx=(t1[1]-t2[1])/tmp;
yy=(t2[0]-t1[0])/tmp; //(xx,yy)相当于与弦长垂直的单位法向量
t3[0]=(t1[0]+t2[0])/2.0,t3[1]=(t1[1]+t2[1])/2.0;
t4[0]=t3[0]+s*xx,t4[1]=t3[1]+s*yy; //t4为圆心
for(i=0;i<n;i++)
{
if(dis(t4,a[i])<1.0001)
ans1++;
}
t4[0]=t3[0]-s*xx,t4[1]=t3[1]-s*yy; //t4为圆心
for(i=0;i<n;i++)
{
if(dis(t4,a[i])<1.0001)
ans2++;
}
return ans1>ans2?ans1:ans2;
} int main()
{
int i,j;
int tes;
scanf("%d",&tes); while(tes--)
{
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%lf%lf",&a[i][0],&a[i][1]);
int num;
int res=1;
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
{
if(dis(a[i],a[j])<2.0001)
{
num=cal(i,j);
if(num>res) res=num;
}
} printf("%d\n",res);
}
return 0;
} //984MS G++
HDU 1077Catching Fish(简单计算几何)的更多相关文章
- HDU 4643 GSM 简单计算几何
今天比赛的时候略坑, admin告诉我询问Q的个数不超过n^2, 赛后敲了个 O(Q*m^3)的复杂度,但这个复杂度常数比较低,可能在除以个小常数, 300ms过了,真心无语,数据应该水了吧,比赛的时 ...
- HDU 2085 核反应堆 --- 简单递推
HDU 2085 核反应堆 /* HDU 2085 核反应堆 --- 简单递推 */ #include <cstdio> ; long long a[N], b[N]; //a表示高能质点 ...
- HDU 5130 Signal Interference(计算几何 + 模板)
HDU 5130 Signal Interference(计算几何 + 模板) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5130 Descripti ...
- ●POJ 1556 The Doors(简单计算几何+最短路)
●赘述题目 10*10的房间内,有竖着的一些墙(不超过18个).问从点(0,5)到(10,5)的最短路. 按照输入样例,输入的连续5个数,x,y1,y2,y3,y4,表示(x,0--y1),(x,y2 ...
- 2018.07.04 POJ 2398 Toy Storage(二分+简单计算几何)
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Description Mom and dad have a problem: their ch ...
- Least Common Multiple (HDU - 1019) 【简单数论】【LCM】【欧几里得辗转相除法】
Least Common Multiple (HDU - 1019) [简单数论][LCM][欧几里得辗转相除法] 标签: 入门讲座题解 数论 题目描述 The least common multip ...
- 七夕节 (HDU - 1215) 【简单数论】【找因数】
七夕节 (HDU - 1215) [简单数论][找因数] 标签: 入门讲座题解 数论 题目描述 七夕节那天,月老来到数字王国,他在城门上贴了一张告示,并且和数字王国的人们说:"你们想知道你们 ...
- [HDU 4082] Hou Yi's secret (简单计算几何)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4082 题目大意: 给你n个点,问能最多构成多少个相似三角形. 用余弦定理,计算三个角度,然后暴力数有多 ...
- HDU 4617 Weapon (简单三维计算几何,异面直线距离)
Weapon Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Subm ...
随机推荐
- 两段简单的JS代码防止SQL注入
1.URL地址防注入: //过滤URL非法SQL字符var sUrl=location.search.toLowerCase();var sQuery=sUrl.substring(sUrl.inde ...
- 从python run 和python unittest两种eclipse运行方式深入理解if __name__ == "__main__"
在写一个简单的python测试程序的时候,发现eclipse中Run as "Python run 和 Python unittest”结果不一样?为什么会不一样? 先贴一下代码段: # - ...
- C++实现网格水印之调试笔记(六)——补充
调用matlab生成的网格水印特征向量矩阵 从文件中读取的原始网格的特征向量矩阵 好吧,之前得出的结果不正确是因为代码写错了.因为实现论文中的提取方案时代码写错了,自己想了另外一个方法,结果方向两者在 ...
- openfl关于windows平台编译报错解决办法
报错信息: 无法打开程序数据库“e:\newproj\mainclient\bin\windows\cpp\obj\obj\msvc-debug-ncxp\vc.pdb”:如果要将多个 CL.EXE ...
- 【开发流程】土耳其CDD工具
土耳其的CDD工具开发到现在已经三个星期了,进展非常不顺利,从最开始的遇到很多难题没法解决到现在工具可以运行但是有一个bug. 起初遇到的ExternalUtranCell这一页的信息很难填,没有解决 ...
- ado.net(class0503)
ado.net组成 数据提供程序 connection //连接对象 command executeNonQuery //执行增删改 executeScalar //执行查询返回首行首列 execut ...
- 搜狐云景paas平台实践之路
前言: 搜狐云景作为搜狐的paas平台,在2014年5月22日的云计算大会上正式发布了公测.初测,注册用户必须先申请邀请码参与公测会赠送用户100元电子券,经过实名认证之后会再赠送100电子券,目测可 ...
- java StreamTokenizer使用
注意:用JAVA解题一般用Scanner类来进行输入,但对时间要求严格的题,用它可能会超时,我.解POJ1823的时候就遇到这样的问题,后改用StreamTokenizer类进行输入,就过了.看来后者 ...
- oracle10~11g在centos5~6版本上安装整体总结如下
1,oracle10g在centos/RedHat5~6主要的安装步骤,我主要记录核心的,别的在此就不多说了,都是些linux基本维护指令,关闭iptables,selinux,或是放行相应的端口,本 ...
- 关于MySQL数据类型timestamp的讨论
在项目中用到了timestamp这个类型,该字段本意是用于存储改行记录的创建时间的,实际上这是一个很危险的设置: mysql官方文档上有这么一段话: The TIMESTAMP data type p ...