题目 | K-colinear Line
UNIQUE VISION Programming Contest 2022(AtCoder Beginner Contest 248)
E - K-colinear Line
https://atcoder.jp/contests/abc248/tasks/abc248_e
Time Limit: 2 sec / Memory Limit: 1024 MB
Score :
Problem Statement
You are given
Find the number of lines in the plane that pass
If there are infinitely many such lines, print Infinity
.
Constraints
or , if .- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the number of lines in the plane that pass Infinity
if there are infinitely many such lines.
Sample Input 1
5 2
0 0
1 0
0 1
-1 0
0 -1
Sample Output 1
6
The six lines
For example,
Thus,
Sample Input 2
1 1
0 0
Sample Output 2
Infinity
Infinitely many lines pass the origin.
Thus, Infinity
should be printed.
我的笔记
由于
首先在
因为
源码
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
const int MAXN = 310;
int N, K;
cin >> N >> K;
int X[MAXN], Y[MAXN];
for (int i = 0; i < N; i++)
cin >> X[i] >> Y[i];
if (K == 1)
{
cout << "Infinity" << endl;
}
else
{
bool vis[MAXN][MAXN]{};
int ans = 0;
for (int i = 0; i < N - 1; i++)
{
for (int j = i + 1; j < N; j++)
{
if (!vis[i][j])
{
vector<int> parallel;
parallel.push_back(i);
parallel.push_back(j);
for (int k = j + 1; k < N; k++)
{
if (((X[j] - X[i]) * (Y[k] - Y[i])) == ((Y[j] - Y[i]) * (X[k] - X[i])))
{
parallel.push_back(k);
}
}
for (int k = 0; k < parallel.size() - 1; k++)
{
for (int l = k + 1; l < parallel.size(); l++)
{
vis[parallel[k]][parallel[l]] = true;
}
}
if (parallel.size() >= K)
ans++;
}
}
}
cout << ans << endl;
}
return 0;
}
本文采用 CC BY-SA 4.0 许可,本文 Markdown 源码:Haotian-BiJi