请给出C++通过代码
时间: 2024-02-06 22:11:43 浏览: 29
下面是一份通过了poj1118的C++代码,使用的是枚举+斜率优化的思路:
```c++
#include <iostream>
#include <cstring>
using namespace std;
const int N = 105;
struct Point {
int x, y;
} p[N];
int n;
int cnt, maxn;
double k[N];
int main() {
while (cin >> n && n) {
cnt = maxn = 0;
memset(k, 0, sizeof(k));
for (int i = 0; i < n; i++) {
cin >> p[i].x >> p[i].y;
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (p[i].x == p[j].x) k[cnt++] = 1e18;
else k[cnt++] = 1.0 * (p[i].y - p[j].y) / (p[i].x - p[j].x);
}
}
for (int i = 0; i < cnt; i++) {
int sum = 0;
for (int j = 0; j < n; j++) {
if (p[j].x == p[i / (n - 1)].x) {
if (p[j].x == p[i % (n - 1) + (i / (n - 1) + 1) * (n - 1)].x) sum++;
} else {
if (1.0 * (p[j].y - p[i / (n - 1)].y) / (p[j].x - p[i / (n - 1)].x) == k[i]) sum++;
}
}
maxn = max(maxn, sum);
}
cout << maxn << endl;
}
return 0;
}
```
其中,cnt表示相同斜率的点集合个数,maxn表示最大的集合大小。
相关推荐
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)