# Sherlock and Moving Tiles

# Sherlock and Moving Tiles

atique + 2 comments Query has double type input instead of integer. This is not matching problem description. That's bad. That is why statistics of the problem shows less acceptance. Please fix.

GustavBertram + 3 comments Actually, it just doesn't fit inside an int. It's all there in the problem statement. q <= L^2 and L<=10^9, so q<=10^18. LONG_MAX in this environment is 9223372036854775807, so that is juuuust sufficient.

masotrix + 0 comments You are the one right man.

atique + 0 comments I am sorry. I made wrong guess. You are right.

sgrebenkin + 0 comments Yeah. Use long.

StoneCold_Xi + 0 comments [deleted]

protojas + 3 comments For python users having trouble with JUST number 4 - try doing

`format(answer, '.20f')`

to get the right precision required.

dbhrockzz + 2 comments import math l,s1,s2 = map(int,raw_input().split()) n = input() q = [] for i in range(n): q.append(input()) rel = abs(s1*math.sin(math.radians(45))-s2*math.sin(math.radians(45))) for qi in q: if qi==(l**2): print 0.0000000 else: print format((l-math.sqrt(qi))/rel,'.20f')

Test Case 4 is still coming wrong

jane_beguin + 1 comment with this code you have O(1) complexity and it works

import math t, v1, v2 = map(int, input().split()) for _ in range(int(input())): a = int(input()) rep = math.sqrt(2)*(t-math.sqrt(a))/abs(v2-v1) print (rep)

maheshvangala191 + 1 comment explain the logic plzzz

vikasjat123 + 0 comments Use the Relativity motion concept of physics

sgrebenkin + 0 comments Oh c'mon, sin(Pi/4) = sqrt(2)/2;

bigbang1498 + 1 comment Can you please explain the logic behind using format here, I wasn't getting 4th testcase right but after doing what you suggested I got it right

protojas + 1 comment I noticed that for people using C++ they were having precision errors.

`format(answer, .20f)`

just makes the answer go to 20 decimal points, which is somehow required for question 4.. not sure why thoughbigbang1498 + 0 comments thanks

RahulHP + 0 comments Thanks a lot, I wasted a submission due to this before reading your comment!

tvanloon + 4 comments For those using C++ stuck on test cases 3 and 4, use cout << std::fixed <<

withasingle_t + 0 comments Thanks!

q1a2z3 + 0 comments What does that do?

adarsh97 + 0 comments you are awesome bro....very very thank you.

metamemelord + 1 comment cout<<setprecision(50)<<ans<<endl;

works as well!

xdavidliu + 0 comments that's kind of overkill; it forces 50 significant figures regardless of where the decimal point is. So 1.0 would display as 1.0000000000000000000000000000000000000000000000000.

with std::fixed, it makes std::setprecision(5) always require exactly 5 digits

*after*the decimal point, which matches the statement of the problem, which requires a tolerance of 0.0001.

manish_chauhan + 1 comment i m not getting it can someone explain me logic of this progam

JasolAsked to answer + 1 comment Hm, doesn't look like I can paste a picture in here, but I'll try to give you some information that helped me. You're trying to solve for time, so you want an equation with time where you can isolate time, and solve it. Distance = speed x time. There are two distances available to you, the distances of the bottom left corner of both squares. Using this information, and the picture provided with the problem, you can solve for time.

bismitapadhy + 0 comments I am not able to understand the question exactly.can you please explain

estevedelacebo + 0 comments You can simplify the problem by:

Considering the absolute value of the difference in velocities. That is the relative velocity.

Asking for a square of area A is the same thing than asking for a square of diagonal sqrt(2 * a) (check it). The diagonal of the inner square as a function of time is d = L * sqrt(2) - rel_vel * time. We have then a linear equation instead of a quadratic one

pl_lepko + 0 comments I solved this problem by solving: Quadratic equation...

q= ( L+(time*p)) * (L+(time*p)); (L+t*p) * (L+t*p) = q q = L^2 + 2*L*t*p + t^2*p^2; q - L^2 = 2*L*t*p + t^2*p^2; q - L^2 = 2*L*t*p + t^2*pS; (a)*t^2 + (b)*t - (c) = 0; //quadratic equation....

masterpradeep + 9 comments Getting runtime error for testcases 4,5,6. suceesfully executed 1,2,3.How to find out the reason for run time error. Help

public class Solution {

`public static void main(String[] args) { Scanner g=new Scanner(System.in); int side=g.nextInt(); int v1=g.nextInt(); int v2=g.nextInt(); double a = Math.sqrt(2); double diagonal=a * side; int v3=Math.abs(v1-v2); int t=g.nextInt(); for(int i=0;i<t;i++) { int distance=g.nextInt(); double diagonal2=a * Math.sqrt(distance); if(v3 != 0) { double result = (Math.abs(diagonal-diagonal2))/v3; System.out.println(result); } else { System.out.println(0.00000000000000); } } }`

}

masterpradeep + 0 comments Solved it by using - nextDouble()

romario_yakunin + 0 comments This problem is sopposed to be solved with a formula.

cgira + 0 comments try changing your else statement to return infinity instead of 0.0. The logic is that if the two squares move at a same pace, they will never leave q area as shown on the picture

pGxplorer + 0 comments no need to write else part. It is already said that S1 and S2 will

**never**be equal.vvbhandare + 0 comments Will you please explain how you calculate this to get q? I tried to understand your code but could not get it.

ThanujaM + 0 comments Use long for v1,v2 and v3

ebrucecfa + 0 comments U should use

double distance=in.nextDouble();

int will result in Test Case failures in Java8.

bhuvanms + 1 comment why are we doing s1-s2 relative velocity concept??

rajatsaini + 0 comments Relative velocity will give us the speed of (original_diagonal - diagonal_of_qi).

poonia0312 + 0 comments hello your code give runtime error in testcase 3,4,5 plz correct it

shivamsaluja20 + 0 comments My code is giving bad_alloc even for the test case. I tried deleting memory for the 'queries' at the end still doesn't remove the error. Why is it so? How do I tackle it? Below is my code

vector<double> movingTiles(int l, int s1, int s2, vector<int> queries) { if(s1>s2) swap(s1,s2); vector<double> t; t.resize(queries.size()); for(int i=0;i<t.size();i++) { __try { if((s2-s1)>0) t.push_back(((sqrt(2*l*l)-sqrt(2*queries[0]))/((double)s2-s1))); else t.push_back(0.00000); } catch(const bad_alloc&) { return vector<double>(); } } vector<int>().swap(queries); return t; }

Sort 167 Discussions, By:

Please Login in order to post a comment