Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

Chef and Ola Cab-Editorial

$
0
0

PROBLEM LINK:https://www.codechef.com/problems/EXPCODE2

Author:https://www.codechef.com/users/vivek96

DIFFICULTY:EASY

PREREQUISITES:Basic Maths,Math Functions

PROBLEM: Chef want to book Ola Cab,he have to take ride from point one (xi,yi) to second point (xj,yj),Ola cost N rupees per unit, Chef have R rupees in his pocket, You have to help Chef to find Whether he have suffiecient amount of money in his pocket for paying to ola.

if yes print “yes”(without quotes) else print “no”(without quotes)

EXPLANATION: From the Question,its clear we have to find distance between two points.

Distance Formula: Given the two points (x1, y1) and (x2, y2), the distance d between these points is given by the:alt text

find the distance d between 2 points then we know ola cost N rupees per unit so,

total cost=d(distance) * N(Cost of Per Unit).

so if total cost<=R(Amount chef have in his pocket) then Print yes else print no

AUTHOR'S AND TESTER'S SOLUTIONS:

class chefandolacab {

public static void main(String[] args)

{

    Scanner sc=new Scanner(System.in);

    int x1=sc.nextInt();

    int y1=sc.nextInt();

    int x2=sc.nextInt();

    int y2=sc.nextInt();

    int r=sc.nextInt();

    int n=sc.nextInt();

    double dist=Math.ceil(Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));

    if(dist*r<=n)
    System.out.println("yes");

    else
        System.out.println("no");

}

}

Edit-Correction :)


Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>