题意:给你坐标和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的更多相关文章

  1. 2014 ACM/ICPC 北京邀请赛 部分 题解

    题目链接:http://acm.bnu.edu.cn/bnuoj/problem.php?search=2014+ACM-ICPC+Beijing+Invitational+Programming+C ...

  2. hihocoder 1084 扩展KMP && 2014 北京邀请赛 Justice String

    hihocoder 1084 : http://hihocoder.com/problemset/problem/1084 北京邀请赛 Just  String http://www.bnuoj.co ...

  3. 2014 北京邀请赛ABDHJ题解

    A. A Matrix 点击打开链接 构造,结论是从第一行開始往下产生一条曲线,使得这条区间最长且从上到下递减, #include <cstdio> #include <cstrin ...

  4. bnu 34982 Beautiful Garden(暴力)

    题目链接:bnu 34982 Beautiful Garden 题目大意:给定一个长度为n的序列,问说最少移动多少点,使得序列成等差序列,点的位置能够为小数. 解题思路:算是纯暴力吧.枚举等差的起始和 ...

  5. 牛客多校第四场 F Beautiful Garden

    链接:https://www.nowcoder.com/acm/contest/142/F来源:牛客网 题目描述 There's a beautiful garden whose size is n ...

  6. BNUOJ 34982 Beautiful Garden

    BNUOJ 34982 Beautiful Garden 题目地址:BNUOJ 34982 题意:  看错题意纠结了好久... 在坐标轴上有一些树,如今要又一次排列这些树,使得相邻的树之间间距相等.  ...

  7. (第四场)F Beautiful Garden

    题目: F Beautiful Garden 题目描述 There's a beautiful garden whose size is n x m in Chiaki's house. The ga ...

  8. ACM程序设计选修课——1057: Beautiful Garden(模拟+耐心调试)

    1057: Beautiful Garden Time Limit: 5 Sec  Memory Limit: 128 MB Submit: 25  Solved: 12 [Submit][Statu ...

  9. 2014 SummerTrain Beautiful Garden

    There are n trees planted in lxhgww's garden. You can assume that these trees are planted along the ...

随机推荐

  1. differential evolution代码实例(DE算法)

    DE算法是遗传算法中一种比较流行的算法,这种算法比较简单,速度也比较快,下面给出一份示例代码 clear all; close all; clc 2 %Function to be minimized ...

  2. 安卓构架组件——概述 Android Architecture Components

    谷歌官文文档地址:https://developer.android.google.cn/topic/libraries/architecture 安卓构架组建是库的集合:帮助你设计健壮的.易测试的. ...

  3. 转载他人的efk搭建文章后边有链接和地址

    EFK教程 - EFK快速入门指南   通过部署elasticsearch(三节点)+filebeat+kibana快速入门EFK,并搭建起可用的demo环境测试效果 目录 ▪ 用途▪ 实验架构▪ E ...

  4. shell脚本实现ftp上传下载文件

    前段时间工作中需要将经过我司平台某些信息核验数据提取后上传到客户的FTP服务器上,以便于他们进行相关的信息比对核验.由于包含这些信息的主机只有4台,采取的策略是将生成的4个文件汇集到一个主机上,然后在 ...

  5. Linux使用rarcrack暴力破解RAR,ZIP,7Z压缩包

    1.下载http://rarcrack.sourceforge.net/ 2.安装依赖 gcc libxml2-devel  libxslt-devel 3.使用rarcrack your_encry ...

  6. python读取pcap包

    import struct class FileConvert(object): ''' test python file''' def __init__(self): self.aa = 0 sel ...

  7. elasticsearch添加访问密码

    1.将x-pack复制到elasticsearch的plugins目录下面 2.启动elasticsearch .bin/elasticsearch & 3.修改指定用户密码 PUT http ...

  8. Servlet接口和web.xml配置文件初识

    一.Java Web核心Servlet 1.什么是Servlet? Servlet是运行在服务器端的Java小程序,是sun公司提供的一套规范,用来处理客户端请求.响应给浏览器的动态资源.但Servl ...

  9. Java字节数组流学习

    字节数组流 基于内存操作,内部维护着一个字节数组,我们可以利用流的读取机制来处理字符串.无需关闭,不会报IOException. ByteArrayInputStream 包含一个内部缓冲区,该缓冲区 ...

  10. appium---学习

    一直想学但是没有时间,今天看到个不错的链接保存一下. 学习链接:http://www.testclass.net/appium_base/appium-base-summary