E - K-colinear Line
题目描述:
n
个点,问存在多少条不同的直线,使的直线上的点的数量大于等于x
思路:
两点确定一条直线,所以我们直接枚举每两个点,得到一个直线,再枚举剩下的所有的点,看有多少个点在线上,如果数量大于等于
k
,就更新答案,个人感觉这个题主要考的是直线的判重,这里因为数据量很小,我们直接用vector
存下来每次符合条件的点的所有下标,然后排个序,扔到set
里面去重,最后只需要输出set
的大小即可
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define inf 0x3f3f3f3f
#define mod7 1000000007
#define mod9 998244353
#define m_p(a,b) make_pair(a, b)
#define mem(a,b) memset((a),(b),sizeof(a))
#define io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(a) cout << "Debuging...|" << #a << ": " << a << "\n";
typedef long long ll;
#define int long long
typedef pair <int,int> pii;
#define MAX 300000 + 50
int n, m, k, x, y;
vector<pii>v;
set<vector<int>>se;
bool judge(int i, int j, int k){
int a = v[k].second - v[i].second;
int b = v[k].first - v[i].first;
int c = v[j].second - v[i].second;
int d = v[j].first - v[i].first;
if(a * d == b * c)return true;
return false;
}
void work(){
cin >> n >> k;
for(int i = 1; i <= n; ++i){
cin >> x >> y;
v.push_back(m_p(x, y));
}
if(k == 1){
cout << "Infinity\n";
return;
}
for(int i = 0; i < n; ++i){
for(int j = i + 1; j < n; ++j){
int mx = min(v[i].first, v[j].first);
int my = min(v[i].second, v[j].second);
int num = 2;
vector<int>vv;
vv.push_back(i);vv.push_back(j);
for(int k = 0; k < n; ++k){
if(k == i || k == j)continue;
if(judge(vv[(int)vv.size() - 2], vv[(int)vv.size() - 1], k)){
++num;
vv.push_back(k);
mx = min(mx, v[k].first);
my = min(my, v[k].second);
}
}
if(num >= k){ sort(vv.begin(), vv.end());
se.insert(vv);
}
}
}
cout << se.size() << endl;
}
signed main(){
io;
work();
return 0;
}