日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Game of Lines(POJ-3668)

發布時間:2025/3/17 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Game of Lines(POJ-3668) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Problem Description

Farmer John has challenged Bessie to the following game: FJ has a board with dots marked at N (2 ≤ N ≤ 200) distinct lattice points. Dot i has the integer coordinates Xi and Yi (-1,000 ≤ Xi ≤ 1,000; -1,000 ≤ Yi ≤ 1,000).
Bessie can score a point in the game by picking two of the dots and drawing a straight line between them; however, she is not allowed to draw a line if she has already drawn another line that is parallel to that line. Bessie would like to know her chances of winning, so she has asked you to help find the maximum score she can obtain.

Input

Line 1: A single integer: N

Lines 2..N+1: Line i+1 describes lattice point i with two space-separated integers: Xi and Yi.

Output

Line 1: A single integer representing the maximal number of lines Bessie can draw, no two of which are parallel.

Sample Input

4

-1 1
-2 0
0 0
1 1

Sample Output

4

題意:給出n個點的坐標,求最多能確定多少個互不平行的直線。

思路:用atan()函數求出所有點的斜率,排序后進行判斷即可。

Source Program

#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<string> #include<cstdlib> #include<queue> #include<vector> #define INF 0x3f3f3f3f #define PI acos(-1.0) #define N 1050 #define MOD 123 #define E 1e-6 using namespace std; struct Point{double x;double y; }point[N]; double a[N*N]; double Calculate(Point p1, Point p2) {Point p;p.x=p2.x-p1.x;p.y=p2.y-p1.y;if(fabs(p.x)<E)//斜率不存在return 1;double temp=atan(p.y/p.x);if(temp<0)//注意斜率的范圍return 1+temp;elsereturn temp; }int main() {int n;scanf("%d",&n);for(int i=0;i<n;i++)scanf("%lf%lf",&point[i].x,&point[i].y);int k=0;for(int i=0;i<n;i++)for(int j=i+1;j<n;j++){a[k]=Calculate(point[i],point[j]);k++;}sort(a,a+k);int ans=1;for(int i=1;i<k;i++)if(a[i]!=a[i-1])ans++;printf("%d\n",ans);return 0; }

?

總結

以上是生活随笔為你收集整理的Game of Lines(POJ-3668)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。