Points on the line

A. Points on the line

We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round.

The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1, 3, 2, 1} is 2.

Diameter of multiset consisting of one point is 0.

You are given n points on the line. What is the minimum number of points you have to remove, so that the diameter of the multiset of the remaining points will not exceed d?

Input

The first line contains two integers n and d (1 ≤ n ≤ 100, 0 ≤ d ≤ 100) — the amount of points and the maximum allowed diameter respectively.

The second line contains n space separated integers (1 ≤ xi ≤ 100) — the coordinates of the points.

Output

Output a single integer — the minimum number of points you have to remove.

Examples

input

Copy

3 1
2 1 4

output

1

input

Copy

3 0
7 7 7

output

0

input

Copy

6 3
1 3 4 6 9 10

output

3

Note

In the first test case the optimal strategy is to remove the point with coordinate 4. The remaining points will have coordinates 1 and 2, so the diameter will be equal to 2 - 1 = 1.

In the second test case the diameter is equal to 0, so its is unnecessary to remove any points.

In the third test case the optimal strategy is to remove points with coordinates 1, 9 and 10. The remaining points will have coordinates 3, 4 and 6, so the diameter will be equal to 6 - 3 = 3.

百度翻译:

我们没有测试用例。一场大型奥林匹克竞赛即将来临。但problemsetters的首要任务应该是增加了另一个问题的轮。
线路上多点的直径是最大的两点之间的距离从这组。例如,在 multiset { 1,3,2 直径, 1 } 2。
多组由一个点的直径是0。
你在直线上得到n分。你必须删除点的最小数目是多少,所以,其余点的直径不超过multiset D?
输入
第一行包含两个整数n和d(1 ≤ N ≤ 100, 0 ≤ D ≤ 100)-点数量和允许的最大直径分别。
第二行包含N个整数(1 ≤ xi ≤ 100)-点的坐标。

 

这很明显是枚举呀!

1到100试一遍就好了

#include<bits/stdc++.h>
using namespace std;
int s[105];
int main()
{
	int n,i,d,a,j,ans=0;
	scanf("%d%d",&n,&d);
	for(i=1;i<=n;i++){
		scanf("%d",&a);
		s[a]++;
	}
	for(i=1;i<=100;i++)		//枚举坐标 
	{
		if(s[i]!=0){		//如果有这个点 
			int t=0;		
			for(j=max(1,i-d);j<=i;j++)
				t+=s[j];//求出直径内点的个数 
			ans=max(t,ans);	//求一个在右边已d为直径能包括点的最多点 
		}
	}
	printf("%d",n-ans);		//除了能包括的,就是要删除的 
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
public void FitLine3(ConcurrentBag<Point2f> Allpoints, out Point2f p1, out Point2f p2) { // Convert ConcurrentBag<Point2f> to Mat var pointsMat = new Mat(Allpoints.Count, 1, MatType.CV_32FC2); var i = 0; foreach (var p in Allpoints) { pointsMat.At<Vec2f>(i, 0)[0] = p.X; pointsMat.At<Vec2f>(i, 0)[1] = p.Y; i++; } // Fit a line to the points using PCA var mean = new Mat(); var eigenvectors = new Mat(); var eigenvalues = new Mat(); Cv2.PCACompute(pointsMat, mean, eigenvectors, eigenvalues, 1); // Get the direction vector of the line var direction = eigenvectors.At<Vec2f>(0, 0); // Get two points on the line var point1 = new Point2f(direction[0] * eigenvalues.At<float>(0, 0) + mean.At<float>(0, 0), direction[1] * eigenvalues.At<float>(0, 0) + mean.At<float>(0, 1)); var point2 = new Point2f(mean.At<float>(0, 0) - direction[0] * eigenvalues.At<float>(0, 0), mean.At<float>(0, 1) - direction[1] * eigenvalues.At<float>(0, 0)); // Sub-pixel optimization using cornerSubPix var winSize = new Size(5, 5); var zeroZone = new Size(-1, -1); var criteria = new TermCriteria(CriteriaTypes.MaxIter | CriteriaTypes.Eps , 100, 0.001); Cv2.CornerSubPix(pointsMat, mean, winSize, zeroZone, criteria); // Get the direction vector of the line after optimization direction = eigenvectors.At<Vec2f>(0, 0); // Get two points on the line after optimization point1 = new Point2f(direction[0] * eigenvalues.At<float>(0, 0) + mean.At<float>(0, 0), direction[1] * eigenvalues.At<float>(0, 0) + mean.At<float>(0, 1)); point2 = new Point2f(mean.At<float>(0, 0) - direction[0] * eigenvalues.At<float>(0, 0), mean.At<float>(0, 1) - direction[1] * eigenvalues.At<float>(0, 0)); // Set the output points p1 = point1; p2 = point2; }有错进行优化
最新发布
06-09
在这段代码中可能存在一些潜在的问题和可以优化的地方: 1. 目前的代码只适用于二维平面上的点集,如果需要处理三维数据或更高维数据,需要进一步修改代码。 2. 在使用PCA计算主成分时,目前的代码只使用了其中的一维信息,因此可能存在信息丢失的情况。如果需要更准确地拟合线段,可以考虑使用更多的主成分信息。 3. 在进行亚像素级别的优化时,目前的代码只使用了一个固定的迭代次数和收敛精度。如果需要更精确地拟合线段,可以考虑根据实际情况动态调整这些参数。 4. 在进行亚像素级别的优化时,目前的代码使用了所有的点来进行优化,这可能会导致一些离群点对优化结果产生较大的影响。如果需要更鲁棒的拟合结果,可以考虑使用一些基于统计学方法的去噪和异常值剔除技术。 5. 在进行亚像素级别的优化时,目前的代码使用了一个固定的窗口大小和零区域大小。如果需要更适应不同的数据集和噪声情况,可以考虑使用一些自适应的窗口大小和零区域大小。 6. 在进行亚像素级别的优化时,目前的代码没有进行异常值检测和处理。如果输入的点集中包含一些异常值,可能会导致优化结果不准确。因此,可以考虑使用一些异常值检测和处理技术来提高算法的鲁棒性。 针对这些问题,可以根据具体的应用场景和需求进行相应的优化和改进。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值