×

# EXPCODE2 - Editorial

 0 1 PROBLEM LINK:https://www.codechef.com/problems/EXPCODE2 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: 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 2★vivek96 533●2●21 accept rate: 8% 0★admin ♦♦ 19.8k●350●498●541

 0 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. answered 15 Mar '17, 14:10 15.5k●1●20●66 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)
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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