Zombie Apocalypse
A patient with first stage zombie virus has escaped from the facility in a city of population N. The zombie virus is very dangerous as it passer on to other people as they come in contact with the patient making them a patient as well.
Zombie virus has K life stages to develop, each of which takes 1 unit of time. Only the last stage is contagious. A person with zombie virus attacks only healthy people and can only affect one person in 1 unit of time.
if the patient escaped on Day 1. Find out the number of days it will take to wipe out the entire city's healthy population and turn them into a last stage zombie.
Note: 1 unit of time is equal to 1 day.
Input Specification.
Input1:Total healthy population of the city.
input2:Number of stages of zombie virus.
Output Specification
your function must return the numbers of days.
Example 1:
input1:10
input2:1
output:5
please give java code for this question.
public class Solution {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int input1 = s.nextInt();
int input2 = s.nextInt();
int ans = 0;
while (input1 > input2) {
input2 *= 2;
ans++;
}
System.out.println(ans + 1);
}
}
Comments
Leave a comment