BNUOJ 34982 Beautiful Garden 2014北京邀请赛B (有意思的枚举题)
来源:互联网 发布:网络球机控制线接线图 编辑:程序博客网 时间:2024/05/18 16:58
题意: 在坐标轴上有一些树,现在要重新排列这些树,使得相邻的树之间间距相等。 求最少移动的树的数量。
分析: 至少有两棵没有移动 枚举两棵树 然后看中间有多少不用移动的 注意判断重合的情况
代码:
//// Created by TaoSama on 2015-09-25// Copyright (c) 2015 TaoSama. All rights reserved.////#pragma comment(linker, "/STACK:1024000000,1024000000")#include <algorithm>#include <cctype>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iomanip>#include <iostream>#include <map>#include <queue>#include <string>#include <set>#include <vector>using namespace std;#define pr(x) cout << #x << " = " << x << " "#define prln(x) cout << #x << " = " << x << endlconst int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;int n, a[N];int cal(int l, int r) { int d = a[r] - a[l]; if(d == 0) return n - (r - l + 1); //左右重合 int ret = INF; for(int k = 2; k < n; ++k) { //枚举k个间距 int cnt = 2; for(int i = l + 1; i < r; ++i) { //不重合 if(a[i] != a[i - 1] && a[i] != a[r] && (a[i] - a[l]) * k % d == 0) ++cnt; } ret = min(ret, n - cnt); } return ret;}int main() {#ifdef LOCAL// freopen("in.txt", "r", stdin);// freopen("out.txt","w",stdout);#endif ios_base::sync_with_stdio(0); int t; scanf("%d", &t); int kase = 0; while(t--) { scanf("%d", &n); for(int i = 1; i <= n; ++i) scanf("%d", a + i); printf("Case #%d: ", ++kase); if(n <= 2) { puts("0"); continue; } int ans = INF; sort(a + 1, a + 1 + n); for(int i = 1; i <= n; ++i) for(int j = i + 1; j <= n; ++j) ans = min(ans, cal(i, j)); printf("%d\n", ans); } return 0;}
0 0
- BNUOJ 34982 Beautiful Garden 2014北京邀请赛B (有意思的枚举题)
- 2014北京邀请赛 B Beautiful Garden
- 2014北京邀请赛B Beautiful Garden
- 北京邀请赛 B. Beautiful Garden
- BNUOJ 34982 Beautiful Garden
- 2014 BNU 邀请赛B题(枚举)
- BNUOJ 34990 北京邀请赛最后一题
- 2014 北京邀请赛 B
- 2014ACM 北京邀请赛 B题
- BNUOJ 34985 Elegant String 2014北京邀请赛E题 矩阵快速幂
- BNUOJ 34985 北京邀请赛 E题 Elegant String dp & 矩阵
- bnu 34982 Beautiful Garden
- BNU 34982 Beautiful Garden
- bnu 34982 Beautiful Garden(暴力)
- BNUOJ 34986 北京邀请赛 F题 Football on Table 几何题
- 2014北京邀请赛 J 题 基于哈希值的LCP算法
- 2014acm北京邀请赛A题
- hash(2014北京邀请赛)bnu34990
- OC基础-继承
- UI高度可定制化KxMenu弹出菜单
- 完全搞懂KMP算法
- [笔试题]找数组中最长和为0连续子序列
- PHP学习(三)--变量的类型
- BNUOJ 34982 Beautiful Garden 2014北京邀请赛B (有意思的枚举题)
- uvalive 3026(kmp)
- 重复出现超过m次的最长的子串的最大下标 后缀数组或Hash+LCP UVA 12206 - Stammering Aliens
- ListFragment的使用
- java 基础总结
- 转:网页爬取页面去重策略
- USACO 1.5 Prime Palindromes (打表查询)
- oracle utl_http
- jQuery学习之获取和设置内容以及属性