标签:style blog http color os io for ar
There are n trees planted in lxhgww‘s garden. You can assume that these trees are planted along the X-axis, and the coordinate of ith tree is xi.
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
#include <iostream> #include <cstdio> #include <map> #include <algorithm> #include <cstring> using namespace std; typedef long long LL; const int N= 44; int n; LL x[N]; map<LL,int>mp; LL gcd(LL a,LL b){return b==0?a:gcd(b,a%b);} void run() { scanf("%d",&n); for(int i=0;i<n;++i){ scanf("%lld",&x[i]); if(mp.find( x[i] ) == mp.end() ) mp[x[i]]=1; else mp[x[i]]++; } if( n <= 2){ puts("0"); return ; } int ans=n-1; for(int i=0;i<n;++i){ for(int j=i+1;j<n;++j){ LL d=abs(x[j]-x[i]); if(!d){ ans=min(ans,n-mp[x[j]]); continue; } for(int k=1;k<=n-1;++k){ LL g=gcd((LL)k,d); LL c=min(x[i],x[j]); LL dis=k/g; LL d2=d/g; int cnt=0; for(int z=0; z < n; z += dis){ //dis~~ if(mp.find(c) != mp.end()) cnt++; c += d2; } ans = min(ans,n-cnt); } } } printf("%d\n",ans); } int main() { //freopen("in.txt","r",stdin); int cas=1,_; scanf("%d",&_); while(_--){ mp.clear(); printf("Case #%d: ",cas++); run(); } return 0; }
2014 SummerTrain Beautiful Garden,布布扣,bubuko.com
2014 SummerTrain Beautiful Garden
标签:style blog http color os io for ar
原文地址:http://www.cnblogs.com/YRETSIM/p/3923661.html