北京邀请赛 B. Beautiful Garden

题意:给你坐标和n个点,求最少移动的点使得n个点成等差数列

思路:既然要成等差数列,那么最起码有两个点是不动的,然后枚举这两个点中间的点的个数,近期水的要死,看了队友的代码做的

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;
const double eps = 1e-9;
const int INF = 0x3f3f3f3f;

int n;
double x[45];

int main() {
	int cas = 1,t;
	scanf("%d", &t);
	while (t--) {
		scanf("%d", &n);
		for (int i = 0; i < n; i++) 
			scanf("%lf", &x[i]);
		sort(x, x+n);
		printf("Case #%d: ", cas++);
		if (n == 1){
			printf("0\n");
			continue;
		}
		int ans = INF;
		for (int i = 0; i < n; i++)
			for (int j = i+1; j < n; j++) 
				for (int k = 1; k < n; k++) {
					int count = 0;
					double d = (x[j]-x[i])/k;
					double cur = x[i]-d;
					int cnt = 0;
					for (int l = 0; l < n; l++) {
						cur += d;
						while (x[cnt] < cur && cnt < n)
							cnt++;
						if (cnt == n)
							break;
						if (fabs(cur-x[cnt]) < eps) {
							count++;
							cnt++;	
						}
					}
					ans = min(ans, n-count);
				}
		printf("%d\n", ans);
	}
	return 0;
}



转载于:https://www.cnblogs.com/ldxsuanfa/p/10894130.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值