Advertisement
Saleh127

UVA 299

Jul 19th, 2021
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);
  9. cout.tie(0);
  10.  
  11. test
  12. {
  13. ll n,m,i,j,k,l;
  14.  
  15. cin>>n;
  16.  
  17. ll a[n+4];
  18.  
  19. for(i=0; i<n; i++)
  20. {
  21. cin>>a[i];
  22. }
  23.  
  24. l=0;
  25.  
  26. for(i=0; i<n-1; i++)
  27. {
  28. for(j=i+1; j<n; j++)
  29. {
  30. if(a[i]>a[j])
  31. {
  32. swap(a[i],a[j]);
  33. l++;
  34. }
  35. }
  36. }
  37.  
  38. cout<<"Optimal train swapping takes "<<l<<" swaps."<<endl;
  39. }
  40.  
  41.  
  42. return 0;
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement