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 ;}