Horse Racing Duals puzzle discussion


#315

I did it in Python. For some reason I pass "Horses in any order" and "Many horses", but not "Simple case". It seems like first input is entering 3 instead of 4, so it prints when I inserted

print('n = ' + str(n), file=sys.stderr)

after

n = int(input())


#316

The problem statement doesn't say that all the speeds you'll be given are unique, which implies that there is a chance that horses with the same speed will be in the data set. What will be the result if those horses race each other, and what will the difference in speeds be?

From another perspective, the output D is shown to be an integer value greater than or equal to zero. Can your algorithm produce that?


#317

Hello, I made this code :
include iostream>
include string>
include vector>
include algorithm>
include set>

using namespace std;

int main(){
set<unsigned long> myset;

unsigned int N;
cin >> N; cin.ignore();
for (unsigned int i = 0; i < N; i++) {
    unsigned long Pi;
    cin >> Pi; cin.ignore();

    myset.insert(Pi);
}

set<unsigned long>::iterator it=myset.end();
it--;

unsigned long ecartTmp=*it-*--it;

if (ecartTmp==1 || myset.size()==2){
    cout << ecartTmp <<endl;
    return 0;
}

unsigned long ecart=ecartTmp;

do{
    ecartTmp=*it-*--it;

    if (ecartTmp==1){
        cout << "1" <<endl;
        return 0;
    }

    if (ecartTmp<ecart){
        ecart=ecartTmp;
    }
}while(it!=myset.begin());

cout << ecart << endl;

// Write an action using cout. DON'T FORGET THE "<< endl"
// To debug: cerr << "Debug messages..." << endl;
}

It pass "horses in desorder" in IDE but not when I submitted it, why?

Thanks for help :blush:


#318

My code gets 90% on validation test. It does not print the values for the shorter distance among the initial two horses according to the results. I don know why.

**
 * Auto-generated code below aims at helping you parse
 * the standard input according to the problem statement.
 **/
let arr = []
let arr2 = []

var N = parseInt(readline());
for (var i = 0; i < N; i++) {
    var pi = parseInt(readline());
    arr.push(pi)
}
arr = arr.sort()
for(let i = 1;i<arr.length;i++){
    arr2.push((arr[i]-(arr[i-1]))*1)
    }

for(let i =0;i<arr2.length;i++){
    if(arr2[i]<0){
        arr2[i] = arr2[i]*-1}}
arr3 = arr2.reduce(function(p,n){if(p>n){return n}
else{return p}})
print(arr3)

Here is my code. It would be great if you could help me.