BNUOJ 34982 Beautiful Garden
来源:互联网 发布:魔方一键网络共享工具 编辑:程序博客网 时间:2024/05/16 06:20
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;}
2 0
- BNUOJ 34982 Beautiful Garden
- BNUOJ 34982 Beautiful Garden 2014北京邀请赛B (有意思的枚举题)
- bnu 34982 Beautiful Garden
- BNU 34982 Beautiful Garden
- bnu 34982 Beautiful Garden(暴力)
- 北京邀请赛 B. Beautiful Garden
- 2014北京邀请赛 B Beautiful Garden
- 2014北京邀请赛B Beautiful Garden
- BNUOJ-33687-Beautiful Spacing(二分+DP)
- Garden
- ACM程序设计选修课——1057: Beautiful Garden(模拟+耐心调试)
- Beautiful
- JavaScript-Garden/
- JavaScript-Garden
- Lingering Garden
- CSU1615: Garden
- 花园(garden)
- Javascript Garden
- MySQL数据库常用SQL语句总结一
- ios使用shell脚本打包ipa软件包
- 如何制作一个横版格斗过关游戏 Cocos2d-x 2.0.4
- Linux下用于查看系统当前登录用户信息的4种方法
- IOS自动打包脚本
- BNUOJ 34982 Beautiful Garden
- java新浪微博api
- 杂项: Socket 编程中的一些实际问题
- 小牛问题
- 精简zxing 3.1.1,仅保留扫描和解码部分,增加n种特性...
- QT——QMap
- 面向程序员的数据库访问性能优化法则
- To Begin
- 利用11g自身工具deinstall卸载grid(rac集群环境下)