BNUOJ 34982 Beautiful Garden

Source: Internet
Author: User

BNUOJ 34982 Beautiful Garden

Address: BNUOJ 34982

Question:
I have been confused about the wrong question for a long time...
There are some trees on the coordinate axis. Now we need to rearrange these trees so that the distance between adjacent trees is equal.
At first, I took a glance and thought it was the shortest distance of moving... Later I found it was the number of trees that were at least moved.

Analysis:
I was wrong at the beginning. I thought I could just take the two sides as the adjacent two sides. after eating a lot of wa, I found this problem, considering that the three sequences are three in the final sequence, we may not be able to judge them.
So I thought of a new method. After enumerating the two trees, I enumerated several trees in the middle, and found several trees in the middle of the two trees without moving them.
For details, see the code.

Code:

/** Author: illuz
 
  
* File: B. cpp * Create Date: 2014-05-29 14:43:59 * Descripton: */# include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include
      
        Using namespace std; typedef long ll; const int N = 44; const double EPS = 1e-8; ll t, n, x [N], mmin; set
       
         S; void deal (int lhs, int rhs) {int cnt; ll dis = x [rhs]-x [lhs]; // if the distance is 0 at the same point, processing if (dis = 0) {mmin = min (mmin, n-(rhs-lhs + 1 )); return;} // enumerative lhs and rhs have k spacing. You can also enumerate the tree for (int k = 2; k <n; k ++) {cnt = 2; // search for the tree (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 ;}
       
      
     
    
   
  
 


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.