数学题,double会有误差,所以转化为int。
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int n=1e6;
int a,b,c[n],d[n];
struct ss
{
int x,y,z,ll;
};
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>a;
map<pair<int,int>,int>q;
int s=0;
for(int i=1;i<=a;i++)
{
cin>>c[i]>>d[i];
q[{c[i],d[i]}]++;
if(q[{c[i],d[i]}]>=2)
{
s=1;
}
}
if(s==1)
{
cout<<"inf"<<endl;
return 0;
}
long double w;
long double m;
set<int>nn;
set<vector<int>>t;
for(int i=1;i<=a;i++)
{
for(int j=1+i;j<=a;j++)
{
if(c[j]!=c[i])
{
int xx=(d[j]-d[i]);
int yy=(c[j]-c[i]);
w=__gcd((d[j]-d[i]),(c[j]-c[i]));
m=d[j]-w*c[j];
int f=(c[j]-c[i])*d[j]-(d[j]-d[i])*c[j];
int v=c[j]-c[i];
int cc=__gcd(f,v);
vector<int>vv;
vv.push_back(xx/w);
vv.push_back(yy/w);
vv.push_back(f/cc);
vv.push_back(v/cc);
t.insert(vv);
}
else
nn.insert(c[i]);
}
}
cout<<t.size()+nn.size()<<endl;
}