北京邀请赛 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 ...
随机推荐
- 二进制部署k8s
一.二进制部署 k8s集群 1)参考文章 博客: https://blog.qikqiak.com 文章: https://www.qikqiak.com/post/manual-install-hi ...
- SharePoint创建web应用程序,提示密码不正确
使用版本SharePoint2010: $username="domain\username"$newpassword="xxxxxxxx"stsadm -o ...
- 简单说下cookie,LocalStorage与SessionStorage.md
最近在网上看到有人讨论这三个的一些概念与区别,发现自己也一直没有较好的总结,所以查阅了一些资料来阐述一下. 基本概念 cookie cookie英文意思是小甜饼,是原来的网景公司创造,目前是在客户端存 ...
- EXCUTE JAVAScript点击事件
# Execute Javascript document.getElementsByClassName('chooseFile')[${index}].arguments[0].click(); # ...
- webRTC脱坑笔记(二)— webRTC API之MediaStream(getUserMedia)
webRTC API WebRTC API包括媒体捕获.音频视频的编码和解码.传输层和会话管理. getUserMedia():捕获音频和视频. MediaRecorder:录制音频和视频. RTCP ...
- 01.java8入门
函数式编程的不变模式 import java.util.Arrays; /** * 函数式编程的不变模式 */ public class ArrStream { public static void ...
- java 时间戳转为时间
Date date = new Date(Long.parseLong(String.valueOf("1560235259477")));SimpleDateFormat for ...
- 【leetcode】543. Diameter of Binary Tree
题目如下: 解题思路:最长的周长一定是树中某一个节点(不一定是根节点)的左右子树中的两个叶子节点之间的距离,所以最简单的办法就是把树中所有节点的左右子树中最大的两个叶子节点之间的距离求出来,最终得到最 ...
- boost timer
Boost.Timer provides clocks to measure code performance. At first, it may seem like this library com ...
- 阿里云基于OSS的云上统一数据保护方案2.0技术解析
近年来,随着越来越多的企业从传统经济向数字经济转型,云已经渐渐成为数据经济IT新常态.核心业务系统上云,云上的业务创新,这些都产生了大量的业务数据,这些数据也成为了企业最重要的资产.资源. 阿里云基于 ...