HDU 1077 - Catching Fish

Catching Fish

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1827    Accepted Submission(s): 725

Problem Description

  Ignatius
likes catching fish very much. He has a fishnet whose shape is a circle
of radius one. Now he is about to use his fishnet to catch fish. All
the fish are in the lake, and we assume all the fish will not move when
Ignatius catching them. Now Ignatius wants to know how many fish he can
catch by using his fishnet once. We assume that the fish can be regard
as a point. So now the problem is how many points can be enclosed by a
circle of radius one.

Note: If a fish is just on the border of the fishnet, it is also caught by Ignatius.

Input

  The
input contains several test cases. The first line of the input is a
single integer T which is the number of test cases. T test cases follow.
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.

Output

  For each test case, you should output the maximum number of fish Ignatius can catch by using his fishnet once.

Sample Input

4

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

Sample Output

2

5

5

11

题意:

  给你N个点,计算出单位圆内最多包含多少个点

思路:

  每两个点每举出一个圆

AC代码:

 1 # include <bits/stdc++.h>
 2 using namespace std;
 3 const double eps = 1e-6;
 4
 5 struct Point
 6 {
 7     double x;
 8     double y;
 9 }p[305];
10
11 double dis2(Point a, Point b)
12 {
13     return (b.y - a.y) * (b.y - a.y) + (b.x - a.x) * (b.x - a.x);
14 }
15
16 Point center(Point a, Point b)
17 {
18     Point aa, bb, mid;
19     aa.x = b.x - a.x;
20     aa.y = b.y - a.y;
21     mid.x = (a.x + b.x) / 2;
22     mid.y = (a.y + b.y) / 2;
23     double c = sqrt(1.0 - dis2(a, mid));
24     if(fabs(aa.y) < eps)
25     {
26         bb.x = mid.x;
27         bb.y = mid.y + c;
28     }
29     else
30     {
31         double ang = atan(-aa.x / aa.y);
32         bb.x = mid.x + c * cos(ang);
33         bb.y = mid.y + c * sin(ang);
34     }
35     return bb;
36 }
37
38 int main()
39 {
40     int T;
41     scanf("%d", &T);
42     while(T--)
43     {
44         int n;
45         scanf("%d", &n);
46         for(int i = 0; i < n; i++)
47         {
48             scanf("%lf%lf", &p[i].x, &p[i].y);
49         }
50         Point cen;
51         int ans = 1, tep;
52         for(int i = 0; i < n; i++)
53         {
54             for(int j = i + 1; j < n; j++)
55             {
56                 if(dis2(p[i], p[j]) > 4)
57                     continue;
58                 cen = center(p[i], p[j]);
59                 tep = 0;
60                 for(int k = 0; k < n; k++)
61                 {
62                     if(dis2(p[k], cen) <= 1 + eps)
63                         tep++;
64                 }
65                 if(ans < tep)
66                     ans = tep;
67             }
68         }
69         printf("%d\n", ans);
70     }
71
72
73     return 0;
74 }

时间: 2024-08-25 01:32:06

HDU 1077 - Catching Fish的相关文章

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 Problem Description Ignatius likes catching

hduoj 1077 Catching Fish 求单位圆最多覆盖点个数

Catching Fish Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1217    Accepted Submission(s): 466 Problem Description Ignatius likes catching fish very much. He has a fishnet whose shape is a c

hdu 1077(单位圆覆盖问题)

Catching Fish Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1741    Accepted Submission(s): 686 Problem Description Ignatius likes catching fish very much. He has a fishnet whose shape is a c

HDU 3395 Special Fish 最“大”费用最大流

求最大费用可以将边权取负以转化成求最小费用.然而此时依然不对,因为会优先寻找最大流,但是答案并不一定出现在满流的时候.所以要加一些边(下图中的红边)使其在答案出现时满流.设所有边的流量为1,花费如下图所示.显然最大花费是1001,而没有红边的情况下会得到3. #include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include <cstdio>

HDU 3395 Special Fish(拆点+最大费用最大流)

Special Fish Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2367    Accepted Submission(s): 878 Problem Description There is a kind of special fish in the East Lake where is closed to campus o

HDU 3395 Special Fish(费用流)

题目地址:HDU 3395 刷了几道白书和CF上的非算法的智商题,感觉智商越来越接近负数了...还是先刷几道简单题缓缓.. 这题很简单,二分图模型,用费用流也可以,用KM也可以.不过需要注意的是这里是最大费用流,并不是最大费用最大流,区别在于是否是最大流,这题可以不是最大流,所以要当费用开始减少的时候停止继续流,来保证费用是最大的. 代码如下: #include <iostream> #include <cstdio> #include <string> #includ

[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 campus of Wuhan University. It's hard to say which gender of those fish are, because every fish believes itself as a male, and it may attack one of s

HDU 3395 Special Fish(最大费用流)

Special Fish Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1814    Accepted Submission(s): 678 Problem Description There is a kind of special fish in the East Lake where is closed to campus o

HDU 3469 Catching the Thief (博弈 + DP递推)

Catching the Thief Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 653    Accepted Submission(s): 359 Problem Description In the Qingshui Village, there's a clever thief and a cleverer police.