BNUOJ 34982 Beautiful Garden
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的更多相关文章
- 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 ...
- (第四场)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 ...
- 牛客网暑期ACM多校训练营(第四场) F Beautiful Garden
链接: https://www.nowcoder.com/acm/contest/142/F 题意: n x m的矩形,选个p x q的矩形去掉,两个矩形中⼼重合,去掉后的矩形上下左右对称 求(p, ...
- 北京邀请赛 B. Beautiful Garden
题意:给你坐标和n个点,求最少移动的点使得n个点成等差数列 思路:既然要成等差数列,那么最起码有两个点是不动的,然后枚举这两个点中间的点的个数,近期水的要死,看了队友的代码做的 #include &l ...
- HDU5977 Garden of Eden(树的点分治)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5977 Description When God made the first man, he ...
- hdu-5977 Garden of Eden(树分治)
题目链接: Garden of Eden Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/ ...
随机推荐
- XML文件生成C++代码(基于rapidxml)
简述 与XML文件生成C++代码(基于pugixml)中的功能一致,只是这里改用的rapidxml来实现.就不多说了,直接放代码. 代码 #include "rapidxml-1.13/ra ...
- 转:3d max 2013 安装教程,凭着一种互联网精神提供给广大朋友
看到有人在ps区咨询如何安装3d max教程,当你进行第一步之前,请先断开网络连接第一步:运行安装程序 第二步:接受安装协议,点击下一步会提示输入序列号 第三步:你会看到已经安装完成了的界面 第四部: ...
- 基于SpringSecurity和JWT的用户访问认证和授权
发布时间:2018-12-03 技术:springsecurity+jwt+java+jpa+mysql+mysql workBench 概述 基于SpringSecurity和JWT的用户访 ...
- Eclipse中10个最有用的快捷键组合(转)
Eclipse中10个最有用的快捷键组合 一个Eclipse骨灰级开发者总结了他认为最有用但又不太为人所知的快捷键组合.通过这些组合可以更加容易的浏览源代码,使得整体的开发效率和质量得到提升. ...
- python中对两个 list 求交集,并集和差集
python中对两个 list 求交集,并集和差集: 1.首先是较为浅白的做法: >>> a=[1,2,3,4,5,6,7,8,9,10] >>> b=[1,2,3 ...
- Ubuntu菜鸟入门(十二)—— 主题美化
一.unity-tweak-tool 1.软件介绍 调整 Unity 桌面环境,还是推荐使用Unity Tweak Tool,这是一个非常好用的 Unity 图形化管理工具,可以修改工作区数量.热区等 ...
- A. Candy Bags
A. Candy Bags http://codeforces.com/problemset/problem/334/A time limit per test 1 second memory l ...
- 必须掌握的30种SQL语句优化
1.’对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中使用!=或<>操作符,否则将引擎放弃使用 ...
- Windows Server 2008中安装IIS7.0
最近由于需求重新部署了一台服务器Windows Server 2008,由于以前都是在Windows Server 2003上操作,因此记录下,供其他同学参考. 下面主要介绍在Windows Se ...
- ASP.NET车辆管理系统
原文地址:https://blog.csdn.net/lisenyang/article/details/46606181 系统开发环境为VS2010,采用ASP.NET框架,数据库采用SQL Ser ...