Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- long computeCase(Pair[] arr)
- {
- arr.sort();
- double k = 0.0;
- long count = 1;
- while(true)
- {
- auto switches = iota(arr.length-1)
- .map!(i => tuple!("a", "b", "c", "d", "id")(arr[i].a, arr[i].b, arr[i+1].a, arr[i+1].b, i))
- .filter!(e => e.b != e.d)
- .map!(e => tuple!("f", "id")(cast(double)(e.c - e.a) / (e.b - e.d), e.id))
- .filter!(e => e.f > k);
- if(switches.empty)
- break;
- auto bestSwitch = switches.minElement;
- swap(arr[bestSwitch.id], arr[bestSwitch.id+1]);
- k = bestSwitch.f;
- count++;
- }
- return count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement