You are not logged in. Please login at www.codechef.com to post your questions!

×

EXPCODE2 - Editorial

0
1

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.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));

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

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

}

}

Edit-Correction :)

asked 15 Mar '17, 13:49

vivek96's gravatar image

2★vivek96
533221
accept rate: 8%

edited 20 Mar '17, 12:33

admin's gravatar image

0★admin ♦♦
19.8k350498541


If I am not wrong,

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

Wont this lead to precision errors? Meaning, if distance is 1.9 km, we are truncating it to 1km and calculating cost. Depending on the rate then, that (0.9 km * rate) might be a problem.

link

answered 15 Mar '17, 14:10

vijju123's gravatar image

5★vijju123 ♦♦
15.5k12066
accept rate: 18%

yes ,but its okay,u can take ciel value if no issue of precision,but in general we don't need explicit typecasting..

(15 Mar '17, 14:19) vivek962★

It wouldn't had been okay had I been the problem setter :p.

(15 Mar '17, 14:22) vijju123 ♦♦5★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×15,852
×3,820
×1,220
×167
×19

question asked: 15 Mar '17, 13:49

question was seen: 430 times

last updated: 20 Mar '17, 12:33