fork download
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<map>
  5. using namespace std;
  6.  
  7. struct st{
  8. int a;
  9. int i;
  10. int beaten[90];
  11. }ele[90];
  12.  
  13. struct st tournament(int st,int end,struct st s[])
  14. {
  15. if(st==end)
  16. return s[st];
  17.  
  18. else if(st<end)
  19. {
  20. int mid=(st+end)/2;
  21. struct st left=tournament(st,mid,s);
  22. struct st right=tournament(mid+1,end,s);
  23. if(left.a>right.a)
  24. {left.beaten[left.i++]=right.a;return left;}
  25. else
  26. {right.beaten[right.i++]=left.a;return right;}
  27. }
  28. }
  29.  
  30. int tour(struct st ele[])
  31. {
  32. struct st winner=tournament(0,7,ele);
  33. int max=winner.beaten[0];
  34. for(int j=1;j<winner.i;j++)
  35. {if(winner.beaten[j]>max) max=winner.beaten[j];}
  36. return max;
  37. }
  38.  
  39. int main()
  40. {
  41. int i,s[]={3,7,1,4,2,8,5,6};
  42. int n=(sizeof s)/(sizeof s[0]);
  43. for(i=0;i<n;i++)
  44. ele[i].a=s[i];
  45. cout<<tour(ele);
  46. return 0;
  47. }
Success #stdin #stdout 0.01s 2756KB
stdin
Standard input is empty
stdout
7