Can anybody help me figure out what is wrong with logic I have implemented for the problem CAR-PAL TUNNEL? I am getting a WA.link text
Well, you wonât have that much time for a problem.
and if you had, RIP your rating if the problem is out of first 3.
Hard for you to remain masked, now that you are a moderator too, an active contributor.
I have posted an answer because it wouldnât fit in comment.
Matrix Exponentation
See the equation (T(n) means \cos nx for current problem.)
\begin{pmatrix} T(n) \\ T(n-1) \\ \end{pmatrix} = \begin{pmatrix} a & b\\ c & d \\ \end{pmatrix} * \begin{pmatrix} T(n-1)\\ T(n-2)\\ \end{pmatrix}
Now, for every linear recurrence, we have to fill this matrix with suitable values of a,b,c and d So as to make LHS = RHS.
For current problem, our recurrence is \cos(NâX)=2âcos(X)âcos((Nâ1)âX)âcos((Nâ2)âX)
The values in Transformation Matrix shall be filled so that this equation is always satisfied. Then we will find (T-1)th power of this transformation matrix T, then
\begin{pmatrix}\cos nx \\ \cos (n-1)x \\\end{pmatrix} = {\begin{pmatrix} a & b\\ c & d \\ \end{pmatrix}}^{T-1}* \begin{pmatrix} cos x\\ cos 0\\ \end{pmatrix}
This way, we get our solution to recurrence. Also, the size of transformation matrix is the number of previous values needed to calculate current value.
This was all about Matrix Exponentation in brief. You can find more about Matrix Exponentaion from following links.
And what if I skip first 3 and dive at 5? Still RIP :3 XD
static long modInv(long b){
long p = MOD-2, out = 1;
while(p>0){
if((p&1)==1)out = (outb)%MOD;
p>>=1;
b = (bb)%MOD;
}
return out;
}
@taran_1407 can you explain how you take modInverse?
Well, if u skip first 3, either u r too genius if u manage AC, and then solve others.
If u didnât get AC in 5th and didnât attempt, i will take it as intentional rating drop.
PS: I posted an answer below, but couldnât get the LaTex rightâŚ, please help!!
Read about fermatâs little theorem, which states that if p is prime, then modular inverse of x can be found as x^(p-2) modulo p.
If p is not prime, but gcd(x, p) ==1 we may use extended euclid euclid algorithm.
All methods explained here https://www.geeksforgeeks.org/multiplicative-inverse-under-modulo-m/
Sorry, didnt notice! Will do right away
Since I am a moderator, I cannot be masked lol. Else who will people go to resolve queries? XD People will be like âAnd the legend says that there is some strange force- called a moderator- which looks after the forums. Unseen to the eye, nobody has ever seen or heard any of himâ XDXD
Your conclusion that there are points for all the y-values isnât true.
Construct a polygon with vertices:
10000 11111111
20000 22222222
40009 44454444
50018 55575555
50027 55585555
30045 33383333
20045 22272222
10036 11151111
18 20000
9 10000
There are just 13 internal grid points, which are at
10009 11121111
10018 11131111
10027 11141111
20009 22232222
20018 22242222
20027 22252222
20036 22262222
30009 33343333
30018 33353333
30027 33363333
30036 33373333
40018 44464444
40027 44474444
why 10 , 11112 will not lie inside
this was
from geeks from geeks, i just check for for (10 ,11112) and its showing yes as output ?? why ?
Read comments there. The code and procedure given at geeksforgeeks for point inside a polygon is incorrect. I know because I had to write an editorial, and that thing failed on edge cases.
@vijju123 i have check for most points⌠yes this g4g code is totally wrong ⌠gives wrong output in most cases âŚ