原题:转自
解决代码
// y = kx +b
//已知两点的k和b就能确定这两点的直线
//k = (y1-y2)/(x1-x2)
//b = (y1 * x2 - y2 * x1) / x2 - x1
//斜率为零或没有斜率的直线单独考虑
#include<iostream>
#include<set>
#include<vector>
using namespace std;
typedef pair<double,double> PII;
set<PII> l;
vector<PII> a;
int main()
{
for(int i = 0;i<=19;i++){
for(int j =0;j<=20;j++){
a.push_back({i,j});//添加pair元素也可以用 make_pair(i,j)
}
}
for(int i = 0;i<a.size();i++){
for(int j =0;j<a.size();j++){
if(a[i].first == a[j].first || a[i].second == a[j].second)
continue;
double x1 = a[i].first,x2 = a[j].first;
double y1 =a[i].second,y2 = a[j].second;
double k = (y2-y1) * 1.0 / (x2-x1);
double b = ((y1 * x2) - (y2 * x1))*1.0/ (x2-x1);
l.insert({k,b});//添加pair元素也可以用 make_pair(i,j)
}
}
int ans = l.size() + 20 + 21;
cout<<ans;
return 0;
}