2014 SummerTrain Beautiful Garden
There are n trees planted in lxhgww's garden. You can assume that these trees are planted along the X-axis, and the coordinate of ith tree is xi.
Input
- The first line contains an integers number n (1 ≤ n ≤ 40), representing the number of trees lxhgww planted;
- The second line contains n integers numbers, the ith number represents xi. (-1000000000 ≤ xi ≤ 1000000000)
Output
For each case, first output the case number as "Case #x: ", and x is the case number. Then output a single number, representing the minimum number of trees lxhgww needs to move.
Sample Input
1
4
1 3 6 7
Sample Output
Case #1: 1
Source
#include <iostream>
#include <cstdio>
#include <map>
#include <algorithm>
#include <cstring> using namespace std;
typedef long long LL;
const int N= ;
int n;
LL x[N];
map<LL,int>mp;
LL gcd(LL a,LL b){return b==?a:gcd(b,a%b);} void run()
{
scanf("%d",&n);
for(int i=;i<n;++i){
scanf("%lld",&x[i]);
if(mp.find( x[i] ) == mp.end() ) mp[x[i]]=;
else mp[x[i]]++;
}
if( n <= ){ puts(""); return ; }
int ans=n-;
for(int i=;i<n;++i){
for(int j=i+;j<n;++j){
LL d=abs(x[j]-x[i]);
if(!d){
ans=min(ans,n-mp[x[j]]);
continue;
}
for(int k=;k<=n-;++k){
LL g=gcd((LL)k,d);
LL c=min(x[i],x[j]);
LL dis=k/g;
LL d2=d/g;
int cnt=;
for(int z=; z < n; z += dis){ //dis~~
if(mp.find(c) != mp.end()) cnt++;
c += d2;
}
ans = min(ans,n-cnt);
}
}
}
printf("%d\n",ans);
} int main()
{
//freopen("in.txt","r",stdin);
int cas=,_;
scanf("%d",&_);
while(_--){
mp.clear();
printf("Case #%d: ",cas++);
run();
}
return ;
}
2014 SummerTrain 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 ...
- 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 ...
- 牛客网暑期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 ...
- 2014 ACM/ICPC 北京邀请赛 部分 题解
题目链接:http://acm.bnu.edu.cn/bnuoj/problem.php?search=2014+ACM-ICPC+Beijing+Invitational+Programming+C ...
- HDU5977 Garden of Eden(树的点分治)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5977 Description When God made the first man, he ...
随机推荐
- 【记录】java解析xml文件
最近新需求要解析xml格式的日志文件,解析完之后数据库落地. 经过度娘搜索,写了demo,现记录如下: 测试XML <?xml version="1.0" encoding= ...
- 学Python的第六天
今天发愤图强,死学Python!!!! 为此小编还买了自己喜欢的McPython! 从小老师就说兴趣是最好的老师,所以呢买这本书是想通过我的世界这款游戏来提高自己的学习兴趣!!! 当然也有私心啦... ...
- RocketMQ集群部署安装
RcoketMQ:[ 1.低延时:在高压下,1毫秒内超过99.6%的反应延迟. 2.面向金融:具有跟踪和审计功能的高可用性. 3.行业可持续发展:保证了万亿级的消息容量. 4.厂商中立:一个新的开放的 ...
- selenium鼠标悬停失效,用js语句模拟
写脚本时,有很多case需要要用的鼠标悬停出菜单 用到了ActionChains(self.driver).move_to_element(el).perform(),但是脚本写完以后,单个case执 ...
- Codeforces 1221F Game With String 思维题
题意:有两个人玩游戏,游戏规则如下:有一个长度为n的字符串,这个字符串由 . 和 X 构成,Alice可以选择a个连续的 . 把它们变成X, Bob可以选择连续的b个 . 把它们变成X.题目中保证a ...
- 如何查看Codeforces的GYM中比赛的数据
前置条件:黄名(rating >= 2100) 或者 紫名(rating >= 1900)并且打过30场计分的比赛. 开启:首先打开GYM的界面,如果符合要求会在右边展示出一个Coach ...
- java程序员必知的 8大排序
Java常用的八种排序算法与代码实现 排序问题一直是程序员工作与面试的重点,今天特意整理研究下与大家共勉!这里列出8种常见的经典排序,基本涵盖了所有的排序算法. 1.直接插入排序 我们经常会到这样一类 ...
- GPS通讯 数据包解析
全球时区的划分: 每个时区跨15°经度.以0°经线为界向东向西各划出7.5°经度,作为0时区.即0时区的经度范围是7.5°W——7.5°E.从7.5°E与7.5°W分别向东.向西每15°经度划分为一个 ...
- 3 Base64编码主要应用在那些场合?
,电子邮件数据也好,经常要用到Base64编码,那么为什么要作一下这样的编码呢? 我们知道在计算机中任何数据都是按ascii码存储的,而ascii码的128-255之间的值是不可见字符.而在网络上交换 ...
- 记录一下LEETheme库主题切换的使用
LEETheme库的位置:https://github.com/lixiang1994/LEETheme 从https://github.com/gsdios的SDAutolayoutDemo 中的白 ...