北京邀请赛 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;
}

北京邀请赛 B. Beautiful Garden,布布扣,bubuko.com

时间: 2024-12-16 16:42:02

北京邀请赛 B. Beautiful Garden的相关文章

2014 北京邀请赛ABDHJ题解

A. A Matrix 点击打开链接 构造,结论是从第一行开始往下产生一条曲线,使得这条区间最长且从上到下递减, #include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include <stdio.h> #include <vector> #include <set> using namespace std; #defi

2014北京邀请赛(部分题解)

马上要去比赛了. 今天做了一下2014北京邀请赛,出了两道题目,感觉很水啊... 首先H题: H. Happy Reversal Time Limit: 1000ms Case Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java class name: Main Submit Status PID: 34988 Font Size:  +   - Elfness is studying

ACM-ICPC 2014北京邀请赛 H Happy Reverse [模拟]

题意:给出n个二进制串,可以把其中的一些0和1反转(即0变1,1变0),找出转化后n个串中的最大值和最小值的差值. 分析:思路就是把所有的串和反转的存在一个数组中,然后排序,找最大值和最小值的差,(如果是同一个串反转的就找第二大的和最小的或第二小和最大的中的最大值).注意假如只有一个串的话结果为0 DEBUG: 这题写了好久 1.第一次用vim,很爽,但是还没熟练 2.忽视了这题的范围,显然要用longlong 3.用了longlong后还WA,用脚本跑出来数据发现在longlong下,min的

2014北京邀请赛 Happy Reversal

H. Happy Reversal 64-bit integer IO format: %lld      Java class name: Main Elfness is studying in an operation "NOT". For a binary number A, if we do operation "NOT A", after that, all digits of A will be reversed. (e.g. A=1001101, af

bnu 34982 Beautiful Garden(暴力)

题目链接:bnu 34982 Beautiful Garden 题目大意:给定一个长度为n的序列,问说最少移动多少点,使得序列成等差序列,点的位置能够为小数. 解题思路:算是纯暴力吧.枚举等差的起始和中间一点,由于要求定中间一点的位置.所以这一步是o(n3);然后用o(n)的算法确定说须要移动几个来保证序列等差. #include <cstdio> #include <cstring> #include <vector> #include <algorithm&g

BNUOJ 34985 Elegant String 2014北京邀请赛E题 动态规划 矩阵快速幂

Elegant String Time Limit: 1000msMemory Limit: 65536KB 64-bit integer IO format: %lld      Java class name: Main We define a kind of strings as elegant string: among all the substrings of an elegant string, none of them is a permutation of "0, 1,-, k

2014 SummerTrain Beautiful Garden

There are n trees planted in lxhgww's garden. You can assume that these trees are planted along the X-axis, and the coordinate of ith tree is xi. But in recent days, lxhgww wants to move some of the trees to make them look more beautiful. lxhgww will

bnu 34982 Beautiful Garden

Beautiful Garden There are n trees planted in lxhgww's garden. You can assume that these trees are planted along the X-axis, and the coordinate of ith tree is xi. But in recent days, lxhgww wants to move some of the trees to make them look more beaut

北京邀请赛 H. Happy Reversal

3.Setting Up and Configuring Backup and Recovery 这个单元讲述如何启动.与rman client如何互动,准备rman环境,实现备份和恢复策略 注意:尽管闪回数据库和安全还原点不是真的数据库备份,但是它们是数据保护策略一个重要部分.这些特性需要一些初始化设置,这些设置依赖于在备份策略中你怎么混合它们.Chapter 5-Data Protection with Restore Points andFlashback Database 提供了关于怎么