zephyr_23's blog

By zephyr_23, history, 6 years ago, In English

I am trying to solve this problem ( https://www.hackerrank.com/contests/hourrank-12/challenges/fair-cut ). The editorial describes D.P approach which I am not able to understand. In the discussion, I saw a greedy approach but I am not able to prove why it works.

Can someone please help me in understanding the D.P approach to this question?

Thanks.

Full text and comments »

  • Vote: I like it
  • +17
  • Vote: I do not like it

By zephyr_23, history, 6 years ago, In English

I am reading the article on this website https://www.cs.colorado.edu/~srirams/courses/csci2824-spr14/pollardsRho.html to understand Pollard rho factorization.

I will explain my doubt with an example.

Suppose for

Unable to parse markup [type=CF_TEX]

, we have

Unable to parse markup [type=CF_TEX]

where

Unable to parse markup [type=CF_TEX]

,

Unable to parse markup [type=CF_TEX]

,

Unable to parse markup [type=CF_TEX]

.

Probability of finding factor 5 from

Unable to parse markup [type=CF_TEX]

is

Unable to parse markup [type=CF_TEX]

.

To increase the probability of getting the factor 5, we search for number x such that

Unable to parse markup [type=CF_TEX]

. Numbers

Unable to parse markup [type=CF_TEX]

satisfy the equation

Unable to parse markup [type=CF_TEX]

. So probability of finding factor 5 increases to

Unable to parse markup [type=CF_TEX]

.

Now they have mentioned that to increase the probability further, we find pairs of numbers such that

Unable to parse markup [type=CF_TEX]

where Yi is

Unable to parse markup [type=CF_TEX]

.

Number of pairs satisfying the criteria

Unable to parse markup [type=CF_TEX]

is

Unable to parse markup [type=CF_TEX]

, similarly number of pairs satisfying

Unable to parse markup [type=CF_TEX]

is

Unable to parse markup [type=CF_TEX]

and so on..

So to get factor 5, we need to search

Unable to parse markup [type=CF_TEX]

pairs out of

Unable to parse markup [type=CF_TEX]

pairs. So the probability of getting required pair is

Unable to parse markup [type=CF_TEX]

which is same as the one where we found factor 5 using

Unable to parse markup [type=CF_TEX]

without searching for pairs.

So my doubt is, to find required factor, why do we search for

Unable to parse markup [type=CF_TEX]

such that

Unable to parse markup [type=CF_TEX]

instead of

Unable to parse markup [type=CF_TEX]

as their probabilities are same ?

Full text and comments »

  • Vote: I like it
  • +37
  • Vote: I do not like it

By zephyr_23, history, 6 years ago, In English

Given a connected, undirected graph, find maximum number of non overlapping cycles ?

Example:-

Here in the above example we can have 2 (maximum number) non overlapping cycles, 0-1-2 and 4-5-6.

Any idea of how to solve this problem efficiently ?

Full text and comments »

  • Vote: I like it
  • +21
  • Vote: I do not like it

By zephyr_23, history, 6 years ago, In English

I am trying to solve this binary search problem (https://www.codechef.com/problems/FAKEBS) on codechef.

I am getting W.A on 3 tasks out of 12 and those are small tasks. I think I am missing some edge cases. Can someone please help ?

Code :- https://ideone.com/VnwXtb

Thanks.

Full text and comments »

  • Vote: I like it
  • -5
  • Vote: I do not like it