UVA270题解
题目传送门
这道题可以用平面向量的初等知识解决。
Solution
我们知道,如果点
我们又知道当向量
所以这个题思路就很简单了,直接
这道题的输入十分毒瘤,每次要 getchar() 以吞掉每组数据前的空行,需要注意一下,这里我使用了 sscanf 来将读入的字符串转转化为整数。
Code
#include <bits/stdc++.h>
#define maxn 1010
using namespace std;
int T, n, ans;
int x[maxn], y[maxn]; // x[]和y[]用来存储坐标,ans存储答案
char str[110];
void clear()
{
memset(x, 0, sizeof x);
memset(y, 0, sizeof y);
ans = 0, n = 0;
}
int main()
{
cin >> T;
getchar();
while (T --)
{
clear();
getchar();
while (gets(str) && str[0] >= '1' && str[0] <= '9')
{
sscanf(str, "%d %d", &x[n], &y[n]);
n ++;
}
getchar();
//for (int i = 0 ; i < n ; i ++) cout << x[i] << " " << y[i] << endl;
for (int i = 0 ; i < n; i ++) // n^3 循环
for (int j = i + 1 ; j < n ; j ++)
{
int cnt = 1;
for (int k = j + 1 ; k < n ; k ++)
if ((x[i] - x[j]) * (y[j] - y[k]) == (x[i] - x[k]) * (y[i] - y[j])) // 刚刚的公式
cnt ++;
ans = max(ans, cnt);
}
cout << ans << endl;
if (T) puts("");
}
return 0;
}