Bnuoj 34982 Beautiful Garden

Source: Internet
Author: User

Beautiful gardentime limit:15000mscase time limit:8000msmemory limit:65536kb64-bit integer IO format:%lld Java class name: Main There is n trees planted in LXHGWW' s garden. You can assume that these trees be planted along the x-axis, and the coordinate of ith tree is XI. Recent days, LXHGWWWants to move some of the trees to make them look more beautiful. LXHGWWWould recognize the trees as beautiful if and only if the distance between any adjacent trees are the same. Now, LXHGWWWants to know the minimum number of trees he need to move. Just to is clear, after moving, there should still is n trees in the x-axis.InputThe first line of the input contains a single integer T, which is the number of the test cases. For each case,
    • 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 of 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
141 3 6 7
Sample Output
Case #1:1
SourceACM-ICPC Beijing Invitational Programming Contest problem Solving: enumeration tolerance, with any two points of the difference as a tolerance, the smaller as the first item, calculate the following n-1 elements, see how many of these n-1 elements in the original sequence Then the rest is to be moved and then the first item in front of a new alternative to the current first, the last side of the deletion of a look at how many in the original sequence ...
1#include <bits/stdc++.h>2 using namespacestd;3 Const intMAXN = -;4 intD[maxn],n;5map<int,int>MP;6 intMain () {7     intkase,m;8scanf"%d",&Kase);9      for(intCS =1; CS <= Kase; ++CS) {Tenscanf"%d",&n); One mp.clear (); A          for(inti =0; I < n; ++i) { -scanf"%d", d+i); -mp[d[i]]++; the         } -         if(N <=2) { -printf"Case #%d:%d\n"Cs0); -             Continue; +         } -Sort (d,d+n); +         intRET = -; A          for(inti =0; I < n; ++i) { at              for(intj = i +1; J < N; ++j) { -                 intds = D[j]-d[i],cnt = n1; -                 if(!DS) { -ret = min (Ret,n-Mp[d[j]]); -                     Continue; -                 } in                 intnow =D[i]; -                  for(intK =1; K < n; ++k) { toNow + =ds; +                     if(Mp[now]) cnt--; -                 } the                 intPre =D[i]; *RET =min (ret,cnt); $                  for(intK =1; K < n; ++k) {Panax NotoginsengPre-=ds; -CNT + = (Mp[now]?1:0)-(Mp[pre]?1:0); theNow-=ds; +RET =min (ret,cnt); A                 } the             } +         } -printf"Case #%d:%d\n", Cs,ret); $     } $     return 0; -}
View Code

Bnuoj 34982 Beautiful Garden

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.