使劲水啊。。。数据量太唬人了。。普通DFS就能过。。。看懂题意就好。。看不懂题是硬伤啊。。
1 /* 2 ID: cuizhe 3 LANG: C++ 4 TASK: cowcycle 5 */ 6 #include <cstdio> 7 #include <cstring> 8 #include <cmath> 9 #include <string> 10 #include <ctime> 11 #include <queue> 12 #include <vector> 13 #include <algorithm> 14 using namespace std; 15 int o1[101],o2[101],ax[15],ay[15]; 16 double arry[101],d[101]; 17 int x,y,x2,y2,n,m; 18 double minz = 100000000; 19 void dfs2(int str,int step) 20 { 21 int i,j,num = 0; 22 double ans = 0,sum = 0; 23 if(step > m) 24 { 25 if(o1[n]*o2[m] >= 3*o1[1]*o2[1]) 26 { 27 28 for(i = 1;i <= n;i ++) 29 { 30 for(j = 1;j <= m;j ++) 31 { 32 arry[num++] = (o1[i]*1.0/o2[j]); 33 } 34 } 35 sort(arry,arry+num); 36 for(i = 0;i < num-1;i ++) 37 { 38 d[i] = arry[i+1] - arry[i]; 39 sum += d[i]; 40 } 41 sum = sum/(num-1); 42 for(i = 0;i < num-1;i ++) 43 { 44 ans += (d[i]-sum)*(d[i]-sum); 45 } 46 ans = ans/(num-1); 47 if(minz > ans) 48 { 49 minz = ans; 50 for(i = 1;i <= n;i ++) 51 ax[i] = o1[i]; 52 for(i = 1;i <= m;i ++) 53 ay[i] = o2[i]; 54 } 55 } 56 return ; 57 } 58 for(i = str;i <= y2;i ++) 59 { 60 o2[step] = i; 61 dfs2(i+1,step+1); 62 } 63 } 64 void dfs1(int str,int step) 65 { 66 int i; 67 if(step > n) 68 { 69 dfs2(x2,1); 70 return; 71 } 72 for(i = str;i <= y;i ++) 73 { 74 o1[step] = i; 75 dfs1(i+1,step+1); 76 } 77 return ; 78 } 79 int main() 80 { 81 int i; 82 freopen("cowcycle.in","r",stdin); 83 freopen("cowcycle.out","w",stdout); 84 scanf("%d%d",&n,&m); 85 scanf("%d%d%d%d",&x,&y,&x2,&y2); 86 dfs1(x,1); 87 for(i = 1;i <= n;i ++) 88 { 89 if(i == 1) 90 printf("%d",ax[i]); 91 else 92 printf(" %d",ax[i]); 93 } 94 printf("\n"); 95 for(i = 1;i <= m;i ++) 96 { 97 if(i == 1) 98 printf("%d",ay[i]); 99 else 100 printf(" %d",ay[i]); 101 } 102 printf("\n"); 103 return 0; 104 }