码迷,mamicode.com
首页 > 其他好文 > 详细

NYIST 1083 美丽的校园

时间:2014-10-02 21:53:33      阅读:279      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   ar   for   strong   

美丽的校园
时间限制:1000 ms | 内存限制:65535 KB
难度:3

 

描述
美丽的校园需要大家维护,作为南工学子,当然有责任!

在计科系门前有n棵树,按一行排列在计科系楼前面,它们在一条直线上,系里的老师觉得要让它们看起来漂亮,它们认为漂亮就是所有的树之间的间隔都相等,现在给出所有树的位置,让你求最少移动树的个数使得树所有看起来漂亮。

输入
输入多组数据,首先一个数n(1<=n<=40),表示n棵树,接着n个数,表示每个数的位置xi(-1000000000 ≤ xi ≤ 1000000000)。


输出
输出结果


样例输入
4
1 3 6 7


样例输出
1


来源
Yougth


上传者
TC_杨闯亮

 

解题:枚举相邻的距离即可。。

bubuko.com,布布扣
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <algorithm>
 6 #include <climits>
 7 #include <vector>
 8 #include <queue>
 9 #include <cstdlib>
10 #include <string>
11 #include <set>
12 #include <stack>
13 #define LL long long
14 #define pii pair<int,int>
15 #define INF 0x3f3f3f3f
16 using namespace std;
17 const int maxn = 42;
18 int n,d[maxn];
19 int main() {
20     while(~scanf("%d",&n)){
21         for(int i = 1; i <= n; i++)
22             scanf("%d",d+i);
23         int ans = INF;
24         sort(d+1,d+n+1);
25         for(int i = 1; i < n; i++){
26             int tmp = 0,ds = d[i+1] - d[i];
27             for(int j = i - 1; j > 0; j--)
28                 if(d[i] - d[j] == ds*(j - i)) continue;
29                 else tmp++;
30             for(int j = i + 1; j <= n; j++)
31                 if(d[j] - d[i+1] == ds*(j - i - 1)) continue;
32                 else tmp++;
33             ans = min(ans,tmp);
34         }
35         printf("%d\n",ans);
36     }
37     return 0;
38 }
View Code

 

貌似这样子不对,是水过去的,数据太弱了

NYIST 1083 美丽的校园

标签:style   blog   http   color   io   os   ar   for   strong   

原文地址:http://www.cnblogs.com/crackpotisback/p/4004386.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!