列表

详情


NC207127. Boundary

描述

Given points in 2D plane. Considering all circles that the origin point is on their boundries, find the one with the maximum given points on its boundry. Print the maximum number of points.

输入描述

The first line contains one integer , denoting the number of given points.
Following lines each contains two integers , denoting a given point .
It's guaranteed that the points are pairwise different and no given point is the origin point.

输出描述

Only one line containing one integer, denoting the answer.

示例1

输入:

4
1 1
0 2
2 0
2 2

输出:

3

说明:

Considering circle (x-1)^2+(y-1)^2=2, we can see that the origin point is on its boundry and that there are 3 given points {(0,2),(2,0),(2,2)} on its boundry.

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

pypy3 解法, 执行用时: 1530ms, 内存消耗: 43024K, 提交时间: 2023-05-09 17:18:46

from collections import defaultdict

n = int(input())
x = [0] * (n + 1)
y = [0] * (n + 1)
for i in range(1, n + 1):
    x[i], y[i] = map(float, input().split())

ans = 0
for i in range(1, n + 1):
    mp = defaultdict(int)
    for j in range(i + 1, n + 1):
        if x[i] * y[j] - x[j] * y[i] == 0:
            continue
        nx = ((y[j] - y[i]) * y[i] * y[j] - x[i] * x[i] * y[j] + x[j] * x[j] * y[i]) / (x[j] * y[i] - x[i] * y[j])
        ny = ((x[j] - x[i]) * x[i] * x[j] - y[i] * y[i] * x[j] + y[j] * y[j] * x[i]) / (y[j] * x[i] - y[i] * x[j])
        mp[(nx, ny)] += 1
        ans = max(ans, mp[(nx, ny)])

print(ans + 1)

C++11(clang++ 3.9) 解法, 执行用时: 503ms, 内存消耗: 544K, 提交时间: 2020-07-14 16:40:37

#include<bits/stdc++.h>
using namespace std;
const int MAXN=2005;
int n,ans;
double a[MAXN],b[MAXN],x,y;
typedef pair<double,double> p;
map<p,int> mx;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%lf%lf",a+i,b+i);
	for(int i=1;i<=n;i++)
	{
		mx.clear();
		for(int j=i+1;j<=n;j++)
			if(a[i]*b[j]!=a[j]*b[i])
			{
				x=((b[j]-b[i])*b[i]*b[j]-a[i]*a[i]*b[j]+a[j]*a[j]*b[i])/(a[j]*b[i]-a[i]*b[j]);
				y=((a[j]-a[i])*a[i]*a[j]-b[i]*b[i]*a[j]+b[j]*b[j]*a[i])/(b[j]*a[i]-b[i]*a[j]);
				mx[p(x,y)]++; ans=max(mx[p(x,y)],ans);
			}
	}
	printf("%d\n",ans+1);
}

C++14(g++5.4) 解法, 执行用时: 322ms, 内存消耗: 540K, 提交时间: 2020-07-14 19:41:31

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std;
const int maxn=2e3+9;
typedef pair<double,double> pdd;
int n;
double x[maxn],y[maxn];
map<pdd,int> res;
int main(){
	scanf("%d",&n);
	rep(i,0,n) scanf("%lf%lf",x+i,y+i);
	int ans=0;
	rep(i,0,n) {
		res.clear();
		rep(j,i+1,n){
			if(x[i]*y[j]==x[j]*y[i]) continue;
			double d=x[i]*y[j]-x[j]*y[i],d1=x[i]*x[i]+y[i]*y[i],d2=x[j]*x[j]+y[j]*y[j];
			double X=(y[i]*d2-y[j]*d1)/d,Y=(x[i]*d2-x[j]*d1)/d;
			ans=max(ans,++res[{X,Y}]);
		}
	}
	printf("%d\n",ans+1);
}

上一题