topic:
The new crown epidemic is caused by the new crown virus. It has recently spread in country A. In order to control the epidemic as soon as possible, country A is preparing to conduct virus nucleic acid testing for a large number of people.
However, kits for testing are in short supply. In order to solve this difficulty, scientists thought of a way: combined detection. That is, samples collected from multiple people (k) are put into the same kit for detection. If the result is negative, it means that all k people are negative, and the detection of k people has been completed with one kit. If the result is positive, it means that at least one person is positive, and all samples of these k individuals need to be re-tested independently (theoretically, if all k−1 individuals are negative before the test, it can be inferred that the kth individual is positive, but In actual operation, this inference will not be used, but k individuals will be tested independently), plus the initial combined detection, a total of k + 1 kits will be used to complete the detection of k individuals.
Country A estimates that the infection rate of the people tested is about 1%, which is evenly distributed. May I ask how much k can save the most kits?
analyze:
The collected samples of k individuals are placed in one kit, and the infection rate of the people tested is about 1%, one in 100 people is infected
1) If the box is Yin, k people are Yin.
2) If the box is Yang, at least one of the k people is Yang. Retest k people independently
Assume that
k is 100 people
1) The number of people tested is just greater than the number of people tested by the kit:
if(k%i==0) k/i + infected people *i
2) The number of people tested is greater than the number of people tested by the kit
k/i + 1 + infected people *i
import java.util.Scanner;
public class _1_13 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int k = s.nextInt(); //检测人数
int gan, people=0, usehe; //感染数 使用人数 使用盒子数
int maxhe = k; //使用最多盒为一人一检
if(k%100==0)
gan = (int)(0.01*k); //每100人中感染数
else
gan= (int)(0.01*k)+1; //检测人数不能被100整除
for(int i=2; i<100; i++){
if(k%i==0)
usehe = k/i + gan*i;
else
usehe = k/i + 1 + gan*i;
if(maxhe>usehe)
{
maxhe = usehe;
people= i;
}
}
System.out.println("每"+people+"人使用最节省");
}
}