题意:给你坐标和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. 常用颜色的RGB分布

    RGB色彩模式是工业界的一种颜色标准,它通过对红(RED).绿(GREEN).蓝(BLUE)三种基本颜色的相互组合从而叠加出各种颜色.RGB色彩模式为每一个红.绿.蓝分类了0-255范围内的亮度值. ...

  2. zabbix入门之定义触发器

    zabbix入门之定义触发器 触发器的概念 触发器的定义:界定某特定的item 采集到数据的非合理区间或非合理状态.通常为逻辑表达式. 逻辑表达式(阈值):通常用于定义数据的不合理区间,其结果如下: ...

  3. [USACO06FEB]摊位预订Stall Reservations(贪心)

    [USACO06FEB]摊位预订Stall Reservations 题目描述 Oh those picky N (1 <= N <= 50,000) cows! They are so ...

  4. 【LeetCode】智商题 brainteaser(共3题)

    [292]Nim Game [319]Bulb Switcher [777]Swap Adjacent in LR String (2019年2月13日,谷歌tag) 给了两个字符串start 和en ...

  5. Sass函数:数字函数-ceil()函数

    ceil() 函数将一个数转换成最接近于自己的整数,会将一个大于自身的任何小数转换成大于本身 1 的整数.也就是只做入,不做舍的计算: >> ceil(2.0) 2 >> ce ...

  6. Windows 搭建MongoDB分片集群(二)

    在本篇博客中我们主要讲描述分片集群的搭建过程.配置分片集群主要有两个步骤,第一启动所有需要的mongod和mongos进程.第二步就是启动一个mongos与集群通信.下面我们一步步来描述集群的搭建过程 ...

  7. maven 配置自动本地/线上不同配置自动打包

    工程结构:在resource下新建开发,线上不同文件夹存放不同配置文件 pom.xml配置文件 <!-- maven配置不同环境打包 --> <build> <plugi ...

  8. office2016pro专业版命令行激活

    1.首先查看Office2016安装目录在哪里,如果是默认安装,没有修改路径,是在C:\Program Files\Microsoft Office\Office16目录下,具体路径还得自行查看,我的 ...

  9. Python3.5-20190529-os模块

    os.getcwd() 获取当前路径os.listdir("路径") 返回该路径下面所有的文件os.path.abspath(path):返回path的绝对路径.os.path.s ...

  10. H2database创建表

    语法和sql server大同小异 create table users(id int primary key not null int identity, name varchar(20))