BNUOJ 34982 Beautiful Garden

题目地址:BNUOJ 34982

题意: 

看错题意纠结了好久。。。

在坐标轴上有一些树,如今要又一次排列这些树,使得相邻的树之间间距相等。 

刚開始瞄了一眼以为是求最短的移动距离...后来发现是求最少去移动的树的数量。

分析: 

刚開始想错了,以为随意取两棵树,作为相邻的两棵树即可了,吃了好多个wa后,发现这个有问题,由于考虑里面三棵树为终于序列中的三个。那么就有可能推断不出来。 

于是想了新的方法,枚举两棵树后,再枚举中间有几棵树,在两棵树中间找有几棵树不用移动。

详细见代码。

代码:

/*
* Author: illuz <iilluzen[at]gmail.com>
* File: b.cpp
* Create Date: 2014-05-29 14:43:59
* Descripton:
*/ #include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <set>
using namespace std; typedef long long ll; const int N = 44;
const double EPS = 1e-8; ll t, n, x[N], mmin;
set<int> s; void deal(int lhs, int rhs) {
int cnt;
ll dis = x[rhs] - x[lhs];
// 假设在同一点就作为间距为0的情况处理
if (dis == 0) {
mmin = min(mmin, n - (rhs - lhs + 1));
return;
}
// 枚举lhs和rhs中有k个间距,也能够枚举树
for (int k = 2; k < n; k++) {
cnt = 2;
// 在中间的树中找要不用移动的树
for (int i = lhs + 1; i < rhs; i++) {
if (x[i] != x[i - 1] && x[i] > x[lhs] && x[i] < x[rhs] && (x[i] - x[lhs]) * k % dis == 0)
cnt++;
}
mmin = min(mmin, n - cnt);
}
} int main()
{
cin >> t;
for (int cas = 1; cas <= t; cas++) {
cin >> n;
s.clear();
for (int i = 0; i < n; i++) {
cin >> x[i];
}
if (n <= 2) {
printf("Case #%d: 0\n", cas);
continue;
}
mmin = N;
sort (x, x + n);
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
deal(i, j);
}
}
printf("Case #%d: ", cas);
cout << mmin << endl;
}
return 0;
}

BNUOJ 34982 Beautiful Garden的更多相关文章

  1. bnu 34982 Beautiful Garden(暴力)

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

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

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

  3. (第四场)F Beautiful Garden

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

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

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

  5. 2014 SummerTrain Beautiful Garden

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

  6. 牛客网暑期ACM多校训练营(第四场) F Beautiful Garden

    链接: https://www.nowcoder.com/acm/contest/142/F 题意: n x m的矩形,选个p x q的矩形去掉,两个矩形中⼼重合,去掉后的矩形上下左右对称 求(p, ...

  7. 北京邀请赛 B. Beautiful Garden

    题意:给你坐标和n个点,求最少移动的点使得n个点成等差数列 思路:既然要成等差数列,那么最起码有两个点是不动的,然后枚举这两个点中间的点的个数,近期水的要死,看了队友的代码做的 #include &l ...

  8. HDU5977 Garden of Eden(树的点分治)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5977 Description When God made the first man, he ...

  9. hdu-5977 Garden of Eden(树分治)

    题目链接: Garden of Eden Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/ ...

随机推荐

  1. 使用jquery的ajax提交文件上传

    以前的项目大多的使用jquery的插件来进行文件上传,对于就只引用jquery而不使用插件来上传文件之前未有写过,最近项目里有写到和用到,就记录一下,以后方便查找. 提示:存在浏览器皆容问题,谨慎使用 ...

  2. HotSpot学习(一)——如何下载openjdk源码

    下载页地址: https://download.java.net/openjdk/jdk7 或者 https://download.java.net/openjdk/jdk8 这里以jdk8的页面为例 ...

  3. SSM框架-使用MyBatis Generator自动创建代码

    参考:http://blog.csdn.net/zhshulin/article/details/23912615 SSM搭建的时候用到MyBatis的代码自动生成的功能,由于MyBatis属于一种半 ...

  4. RHEL7 MariaDB测试

    MariaDB安装及启动: yum groupinstall mariadb 启动mariadb systemctl restart mariadb systemctl enable mariadb ...

  5. Android中如何让DialogFragment全屏(DialogFragment fullscreen)

    这个问题很让人纠结,因为我要在popopwindows里面使用fragment,但是在popopwindows里面找不到它的父控件,于是转战使用DialogFragment,但是让它全屏是一件很头疼的 ...

  6. QQ登录整合/oauth2.0认证-01-申请appkey和appid

    本节需要你申请appkey和appid还有绑定域名的空间 首先 再讲课之前 你需要准备以下东西 到腾讯开发平台中申请 开发者 获得appid 和appkey 这两个东东 这两个东东 就算没审核 也可以 ...

  7. arping 帮助——翻译

    [root@localhost ~]# arping --helparping: invalid option -- '-'Usage: arping [-fqbDUAV] [-c count] [- ...

  8. JAVA操作mysql

    所需jar包:mysql-connector-java.jar 代码: import java.sql.*; import java.util.ArrayList; import java.util. ...

  9. POJ 3678 Katu Puzzle (经典2-Sat)

    Katu Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6553   Accepted: 2401 Descr ...

  10. 【java】java开发中的23种设计模式详解

    设计模式(Design Patterns) ——可复用面向对象软件的基础 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结.使用设计模式是为了 ...