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

Beginner's Guide: Some Useful Machine Learning Websites(Part 1)

I have been away for quite some time now. The reason is I was quite busy with my academic thesis and general academic pressure. Now I do fe...