UVA -203
Train swapping
problem link:
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=235
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=235
Solution:
#include <bits / stdc ++. h>
using namespace std;
long long int ara [20000000];
int main ()
long long int a, b, n, i, j, e;
cin >> b;
while (b--)
{
cin >> n;
for (i = 0; i <n; i ++)
{
cin >> ara [i];
}
for (i = 0, e = 0; i <n; i ++)
{
for (j = i + 1; j <n; j ++)
{
if (ara [i]> = ara [j])
{
swap (ara [i], ara [j]);
e ++;
}
}
}
printf ( "Optimal train swapping takes% lld swaps. \ n", e);
}
return 0;
}
No comments:
Post a Comment