标签:
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.
1 4 1 3 6 7
Case #1: 1
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 50; 4 int d[maxn],n; 5 map<int,int>mp; 6 int main() { 7 int kase,m; 8 scanf("%d",&kase); 9 for(int cs = 1; cs <= kase; ++cs) { 10 scanf("%d",&n); 11 mp.clear(); 12 for(int i = 0; i < n; ++i) { 13 scanf("%d",d+i); 14 mp[d[i]]++; 15 } 16 if(n <= 2) { 17 printf("Case #%d: %d\n",cs,0); 18 continue; 19 } 20 sort(d,d+n); 21 int ret = 50; 22 for(int i = 0; i < n; ++i) { 23 for(int j = i + 1; j < n; ++j) { 24 int ds = d[j] - d[i],cnt = n-1; 25 if(!ds) { 26 ret = min(ret,n - mp[d[j]]); 27 continue; 28 } 29 int now = d[i]; 30 for(int k = 1; k < n; ++k) { 31 now += ds; 32 if(mp[now]) cnt--; 33 } 34 int pre = d[i]; 35 ret = min(ret,cnt); 36 for(int k = 1; k < n; ++k) { 37 pre -= ds; 38 cnt += (mp[now]?1:0) - (mp[pre]?1:0); 39 now -= ds; 40 ret = min(ret,cnt); 41 } 42 } 43 } 44 printf("Case #%d: %d\n",cs,ret); 45 } 46 return 0; 47 }
标签:
原文地址:http://www.cnblogs.com/crackpotisback/p/4673728.html