麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

hdu1077【計算幾何,枚舉圓心】

2019-11-14 11:03:45
字體:
來源:轉載
供稿:網友

Catching Fish

Time Limit: 10000/5000 MS (java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1930 Accepted Submission(s): 784

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

題解: 依次把圓心枚舉出來,然后取最大值 這里寫圖片描述 【盜圖】原文鏈接

代碼:

#include <iostream>#include <string>#include <cstring>#include <cstdio>#include <cmath>#include <cstdlib>#include <algorithm>#include <queue>#include <map>#include <sstream>#define Maxn 100005using namespace std;double pos[305][2];double centre1[2], centre2[2];int n;void GetCentre(double A[], double B[]){ double x0 = (A[0] + B[0]) / 2; double y0 = (A[1] + B[1]) / 2; double a = sqrt( 1 - ( (A[0] - B[0]) * (A[0] - B[0]) + (A[1] - B[1]) * (A[1] - B[1]) ) / 4); if (fabs(A[1] - B[1]) < 1e-6) { centre1[0] = centre2[0] = x0; centre1[1] = y0 + a; centre2[1] = y0 - a; } else { double angel = atan((B[0] - A[0]) / (A[1] - B[1])); centre1[0] = x0 + a * cos(angel); centre1[1] = y0 + a * sin(angel); centre2[0] = x0 - a * cos(angel); centre2[1] = y0 - a * sin(angel); }}int CatchFish(){ int ans1 = 0; int ans2 = 0; for (int i = 0; i < n; i++) { if (sqrt( (pos[i][0] - centre1[0]) * (pos[i][0] - centre1[0]) + (pos[i][1] - centre1[1]) * (pos[i][1] - centre1[1]) ) < 1.0001) ans1++; if (sqrt( (pos[i][0] - centre2[0]) * (pos[i][0] - centre2[0]) + (pos[i][1] - centre2[1]) * (pos[i][1] - centre2[1]) ) < 1.0001) ans2++; } return max(ans1, ans2);}int main(){ int T, i, j; cin >> T; while (T--) { int ans = 1; // 注意n為1時 scanf("%d", &n); for ( i = 0; i < n; i++) { scanf("%lf %lf", &pos[i][0], &pos[i][1]); } for ( i = 0; i < n; i++) for ( j = i + 1; j < n; j++) { // 如果兩點距離超過2,直接略過,不然會超時 if ((pos[i][0] - pos[j][0]) * (pos[i][0] - pos[j][0]) + (pos[i][1] - pos[j][1]) * (pos[i][1] - pos[j][1]) > 4.0) continue; GetCentre(pos[i], pos[j]); ans = max(ans, CatchFish()); } printf("%d/n", ans ); }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 免费放黄网站在线播放 | 日韩字幕在线观看 | 一级国产精品一级国产精品片 | 伊人久久国产精品 | 欧美精品一级 | 成人视屏在线观看 | 操操操操操 | 欧美大胆xxxx肉体摄影 | 欧美成年人视频在线观看 | 国产一区二区精品在线观看 | 99视频观看 | 国产精品视频六区 | 黄色免费在线网址 | 欧美成人午夜一区二区三区 | 免费午夜网站 | 亚洲最大av网站 | 护士hd欧美free性xxxx | 一区视频 | free korean xxxxhd| 成人毛片在线 | 91久久国产综合久久91精品网站 | 成年人在线视频免费 | 成人免费乱码大片a毛片视频网站 | 性生活视频一级 | 黄污在线观看 | 亚洲爱爱网站 | 久久久无码精品亚洲日韩按摩 | 污视频在线看 | 特黄一区二区三区 | 国产一区二区三区在线观看视频 | 一级做a爱片性色毛片 | 涩涩操| 色婷婷久久久 | 黄色大片在线观看 | 亚洲经典视频 | 色播亚洲 | 369看片你懂的小视频在线观看 | 久久久久99一区二区三区 | 成人超碰97 | 毛片观看网址 | 男女羞羞的视频 |