Description
Farmer John has recently invented a game to test the pretentious Bessie. At the beginning of the game, FJ will draw N (2 <= n <= 200) non-overlapping points on the plank for Bessie, the X and Y coordinates of point I are x_ I and y_ I (-1,000 <= x_ I <= 1,000;-1,000 <= y_ I <= 1,000 ). Bessie can select two dots to draw a straight line over them. If and only when there is no straight line parallel to the drawn line on the plane. When the game ends, Bessie's score is the total number of straight lines she draws. To win the game, Bessie found you and hoped you could help her calculate the maximum possible score.
Input
* Row 1st: Enter 1 positive integer: N
* Row 2nd. n + 1: line I + 1 uses two integers x_ I and y_ I separated by spaces to describe the coordinates of vertex I.
Output
Row 3: output an integer, indicating the maximum score of Bessie, that is, the number of parallel lines she can draw.
Sample input4
-1 1
-2 0
0 0
1 1
Sample output * row 1st: output an integer, indicating the maximum score of Bessie, that is, the number of parallel lines she can draw.
Question, brute force find all K values, and find the number of different K values. (Oh, remember to handle the case where no K value exists, it seems that dividing by 0 will lead to strange things. 233 cannot be tried)
Code attached:
#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>using namespace std;const int INF=21474836;int n,tot=0,ans=0;struct node{int x,y;}a[201];double f[40001];int main(){freopen("line.in","r",stdin);freopen("line.out","w",stdout);scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d%d",&a[i].x,&a[i].y);}for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++){ if(i!=j){ if(a[j].x-a[i].x!=0){ double k=(a[j].y-a[i].y)/((a[j].x-a[i].x)+0.0); f[++tot]=k; }else f[++tot]=INF;} } sort(f+1,f+tot+1); ans=1; for(int i=2;i<=tot;i++){ if(f[i]!=f[i-1]) ans++; } cout<<ans;return 0;}
[Usaco2008 Feb] line connected games [brute force] [water question]