1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
#include <iostream> #include <stdio.h> #include <map> #include <math.h> #include <algorithm> using namespace std; //M = sqrt(sumof(Mv)^2+sumof(Mh)^2) int per[8]={0,1,2,3,4,5,6,7}; int arr[322561]; int inp[8]; int main() { double Mv,Mh; double _max; int cnt=1; for(int i=0;i<8;i++) { arr[cnt]=per[i]; cnt++; } while(next_permutation(per,per+8)) { for(int i=0;i<8;i++) { arr[cnt]=per[i]; //cout<<arr[cnt]<<" "; cnt++; } } //cout<<cnt<<"\n"; while(cin>>inp[0]) { int sum=0; sum+=inp[0]; cin>>inp[1]; sum+=inp[1]; cin>>inp[2]; sum+=inp[2]; cin>>inp[3]; sum+=inp[3]; cin>>inp[4]; sum+=inp[4]; cin>>inp[5]; sum+=inp[5]; cin>>inp[6]; sum+=inp[6]; cin>>inp[7]; sum+=inp[7]; if(sum==0) break; _max = 1<<20; //cout<<_max<<"\n"; int inc=1; int pos; for(int k=1;k<=40320;k++) { Mv=0; Mh=0; Mv=(inp[arr[inc]]+inp[arr[inc+1]]+inp[arr[inc+2]]); Mv-=(inp[arr[inc+4]]+inp[arr[inc+5]]+inp[arr[inc+6]]); Mv = Mv*Mv; Mh=(inp[arr[inc]]+inp[arr[inc+6]]+inp[arr[inc+7]]); Mh-=(inp[arr[inc+2]]+inp[arr[inc+3]]+inp[arr[inc+4]]); Mh = Mh*Mh; double M = sqrt((Mv+Mh)); //cout<<"M = "<<M<<" "<<k<<"\n"; if(M<_max) { _max=M; pos = k; } inc+=8; } cout<<pos<<"\n"; printf("%.3lf\n",_max); } return 0; } |