显示代码纯文本
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<utility>
#include<vector>
using namespace std;
const int INF=0x3f3f;
int ans[5000];
typedef pair<int,int> PT;
struct Point
{
int x,y;
pair <int,int> pi[110];
}pos[110];
struct PP
{
int i;
pair<int,int> al;
}Q[5000];
bool operator < (const PP &a,const PP &b)
{
if(a.al.first<b.al.first) return true;
else return false;
}
int main()
{
freopen("asm_fuel.in","r",stdin);
freopen("asm_fuel.out","w",stdout);
int n;
double tmp;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d%d",&pos[i].x,&pos[i].y);
}
for(int i=1;i<=n-1;i++)
{
int tm=1;
for(int j=i+1;j<=n;j++)
{
if(pos[i].x==pos[j].x)
{
pos[i].pi[tm].first=INF;
pos[i].pi[tm].second=pos[i].x;
tm++;
}
else if(pos[i].y==pos[j].y)
{
pos[i].pi[tm].first=0;
pos[i].pi[tm].second=pos[i].y;
tm++;
}
else
{
tmp=(pos[j].y-pos[i].y)/(pos[j].x-pos[i].x);
pos[i].pi[tm].first=tmp;
tmp=pos[i].y-pos[i].x*tmp;
pos[i].pi[tm].second=tmp;
tm++;
tmp=0;
}
}
}
int ti=(n*(n-1))/2;
int sz=1;
for(int i=1;i<=n-1;i++)
{
for(int j=1;j<=n-i;j++)
{
Q[sz].al.first=pos[i].pi[j].first;
Q[sz].al.second=pos[i].pi[j].second;
Q[sz].i=i;
sz++;
}
}
sz--;
sort(Q+1,Q+sz);
int MAXN=1,sum=1;
for(int i=2;i<=ti;i++)
{
if(Q[i].al.first==Q[i-1].al.first && Q[i].al.second==Q[i-1].al.second && Q[i].i!=Q[i-1].i)
{
ans[sum]=Q[i].i;
sum++;
//if(sum>=MAXN) MAXN=sum;
}
}
sum--;
int answer=2;
sort(ans+1,ans+sum+1);
for(int i=1;i<=sum;i++)
{
if(ans[i]!=ans[i-1] && ans[i]!=0) answer++;
}
printf("%d",answer);
return 0;
}