Sunday, June 11, 2017

Solution of : Viral Advertising(problem link)

solution link

At first we initialize three variables m, liked and total with values 5,2(floor(5/2)) ,2 respectively. Here m is the total number of people.  As you can see this simulates the first day.
So the loop must simulate from the 2nd day to nth day. Hence it is initialized with i=2.
Each iteration simulates a day. At first we calculate the total number of people exposed to advertisement i.e. m = liked*3;
next we divide the value of m by 2 to get the number of people that liked the
ad. This is equivalent to floor(x/2). The result is then added to the total number of likes.

After getting out of the loop we just print the total as desired. :)
#HappyCoding




No comments:

Post a Comment

CodeForces: Xenia and Ringroad(339B) Solution in Java for Beginners

  Xenia and Ringroad(339B) Problem Link: Since this is a beginner's problem, I suggest you try it out yourself first. Java programm...