北京邀请赛 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的更多相关文章
- 2014 ACM/ICPC 北京邀请赛 部分 题解
题目链接:http://acm.bnu.edu.cn/bnuoj/problem.php?search=2014+ACM-ICPC+Beijing+Invitational+Programming+C ...
- hihocoder 1084 扩展KMP && 2014 北京邀请赛 Justice String
hihocoder 1084 : http://hihocoder.com/problemset/problem/1084 北京邀请赛 Just String http://www.bnuoj.co ...
- 2014 北京邀请赛ABDHJ题解
A. A Matrix 点击打开链接 构造,结论是从第一行開始往下产生一条曲线,使得这条区间最长且从上到下递减, #include <cstdio> #include <cstrin ...
- bnu 34982 Beautiful Garden(暴力)
题目链接:bnu 34982 Beautiful Garden 题目大意:给定一个长度为n的序列,问说最少移动多少点,使得序列成等差序列,点的位置能够为小数. 解题思路:算是纯暴力吧.枚举等差的起始和 ...
- 牛客多校第四场 F Beautiful Garden
链接:https://www.nowcoder.com/acm/contest/142/F来源:牛客网 题目描述 There's a beautiful garden whose size is n ...
- BNUOJ 34982 Beautiful Garden
BNUOJ 34982 Beautiful Garden 题目地址:BNUOJ 34982 题意: 看错题意纠结了好久... 在坐标轴上有一些树,如今要又一次排列这些树,使得相邻的树之间间距相等. ...
- (第四场)F Beautiful Garden
题目: F Beautiful Garden 题目描述 There's a beautiful garden whose size is n x m in Chiaki's house. The ga ...
- ACM程序设计选修课——1057: Beautiful Garden(模拟+耐心调试)
1057: Beautiful Garden Time Limit: 5 Sec Memory Limit: 128 MB Submit: 25 Solved: 12 [Submit][Statu ...
- 2014 SummerTrain Beautiful Garden
There are n trees planted in lxhgww's garden. You can assume that these trees are planted along the ...
随机推荐
- vue 项目,获取手机验证码和图形验证码(iviewUI框架)
1.编辑获取验证码模块 <Form ref="phoneFormItem" :model="phoneFormItem" :label-width=&qu ...
- ubuntu下安装c man文档
http://www.mirrorservice.org/sites/sourceware.org/pub/gcc/libstdc%2b%2b/doxygen/ 下载 http://www.mirro ...
- Spark 读取HBase数据
Spark1.6.2 读取 HBase 1.2.3 //hbase-common-1.2.3.jar //hbase-protocol-1.2.3.jar //hbase-server-1.2.3.j ...
- 【LeetCode】双指针 two_pointers(共47题)
[3]Longest Substring Without Repeating Characters [11]Container With Most Water [15]3Sum (2019年2月26日 ...
- iPython清屏命令
!clear for Unix-like systems !CLS for Windows
- js百度地图API创建弧线并修改弧线的弧度
去百度API官网下载CurveLine.min.js,注意复制下来的Js前面的行号要删除. // 百度地图API功能 var map = new BMap.Map("container&qu ...
- Web核心之最简单最简单最简单的登录页面
需求分析: 在登录页面提交用户名和密码 在Servlet中接收提交的参数,封装为User对象,然后调用DAO中的方法进行登录验证 在DAO中进行数据库查询操作,根据参数判断是否有对象的用户存在 在Se ...
- 【leetcode】1008. Construct Binary Search Tree from Preorder Traversal
题目如下: Return the root node of a binary search tree that matches the given preorder traversal. (Recal ...
- MongoDB笔记【2】——基本概念和基本指令
- 基本概念 数据库(database) 集合(collection) 文档(document) - 在MongoDB中,数据库和集合都不需要手动创建,当我们创建文档时,如果文档所在的集合或数据库不存 ...
- 以IP地址的形式访问网站
一致以来我都习惯于用域名的方式来访问网站,看到同事用IP地址来访问网站,也仅仅只是好奇,试了一下也没成功,于是就放弃了. 最近发布了站点,客户并没有提供域名,于是通过IP地址访问的方法又在我的脑子里蹦 ...