Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

Please help in this easy hackerrank problem

Revision en1, by acash, 2019-06-24 18:04:54

input:

10 1 2

1

100

debug val 1 and debug val 2 are printing are same but req which is equal to (debug val 1 — debug val 2) is not getting zero ?

#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int l,s1,s2;
    cin>>l>>s1>>s2;
    int q;
    cin>>q;
    long long int relspe = abs(s2-s1);
    while(q--){
        long long int a;
        cin>>a;
        cout<<"debug val 1  "<<sqrt(2)*l<<endl;
        cout<<"debug val 2 "<<sqrt(2)*sqrt(a)<<endl;
        double req = abs(sqrt(2)*l-sqrt(2)*sqrt(a));
        cout<<"req "<<req<<endl;
        double ans = req/relspe;

        cout<<ans<<endl;
    }
}

https://www.hackerrank.com/challenges/sherlock-and-moving-tiles/problem

Tags #algorithms

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English acash 2019-06-24 18:04:54 873 Initial revision (published)