// Bridge.cpp : Defines the entry point for the console application. // #include "stdafx.h" using namespace std; int _tmain(int argc, _TCHAR* argv[]) { void PersonPassWay(int *Time,int *Round,int fast,int low,int display,int ∑); int TestRound=0; cin>>TestRound; cout<<"/n"; while(TestRound--) { int person=0; int total=0; cin>>person; //cout<<person<<"/n"; int *TimePerson=new int[person]; int *Steps=new int[person*10]; for(int TIndex=0;TIndex<person;++TIndex)cin>>TimePerson[TIndex]; for(int SIndex=0;SIndex<10*person;++SIndex)Steps[SIndex]=0; for(int x=person-1;x>0;--x) { for(int y=0;y<x;++y) { if(TimePerson[y]>TimePerson[y+1]) { int temp=TimePerson[y]; TimePerson[y]=TimePerson[y+1]; TimePerson[y+1]=temp; } } } //for(int x=0;x<person;++x)cout<<TimePerson[x]<<" "; PersonPassWay(TimePerson,Steps,0,person-1,0,total); int con=0; cout<<"/n"<<total<<"/n"; while(Steps[con]!=0) { if(Steps[con]==200) { cout<<"/n"; ++con; } else { cout<<Steps[con]<<" "; ++con; } } cout<<"/n"; delete []TimePerson; delete []Steps; } system("pause"); return 0; } void PersonPassWay(int *Time,int *Round,int fast,int low,int display,int ∑) { //for(int x=0;x<=fast;++x)cout<<Time[x]<<" "; if((low==fast)) { sum=sum+Time[low]; Round[display++]=Time[low]; Round[display++]=200; } else if((low-fast)==1) { sum=sum+Time[low]; Round[display++]=Time[fast]; Round[display++]=Time[low]; Round[display++]=200; } else if((low-fast)==2) { sum=sum+Time[low]+Time[fast]+Time[low-1]; Round[display++]=Time[fast]; Round[display++]=Time[low]; Round[display++]=200; Round[display++]=Time[fast]; Round[display++]=200; Round[display++]=Time[fast]; Round[display++]=Time[low-1]; Round[display++]=200; } else if((low-fast)>2) { int fast1, fast2,low1,low2; fast1=Time[fast]; fast2=Time[fast+1]; low1=Time[low]; low2=Time[low-1]; if((2*fast2)>=(fast1+low2)) { sum=sum+low1+fast1+low2; Round[display++]=fast1; Round[display++]=low1; Round[display++]=200; Round[display++]=fast1; Round[display++]=200; Round[display++]=fast1; Round[display++]=low2; Round[display++]=200; PersonPassWay(Time,Round,0,low-2,display,sum); } else { sum=sum+fast2+fast1+low1+fast2; Round[display++]=fast1; Round[display++]=fast2; Round[display++]=200; Round[display++]=fast1; Round[display++]=200; Round[display++]=low2; Round[display++]=low1; Round[display++]=200; Round[display++]=fast2; Round[display++]=200; PersonPassWay(Time,Round,0,low-2,display,sum); } } }