A cell's life cycle is 3 hours, 1 hour to split time, how many cells in containers for n hour,
CodePudding user response:
Using a recursive
{int A (int value, int n)
If (n==0 | | value=https://bbs.csdn.net/topics/=3)
return 0;
Value++;
N -;
Value, return A (n) + A (0, n);
}
CodePudding user response:
Thank you, but can use a for loop about them
CodePudding user response:
public static void main (String [] args) { //TODO Auto - generated method stub Int n=5; Queue The queue=new LinkedList (); The queue. The add (0); for(int i=0; I & lt; n; I++) { Int k=queue. The size (); for(int j=0; J & lt; k; J++) { Int num=queue. The poll (); The queue. The add (0); The queue. The add (0); if(num ! =2)The queue. The add (num + 1); } } System. The out. Println (queue. The size ()); } CodePudding user response:
refer to the original poster m0_57306111 response: a cell's life cycle is 3 hours, 1 hour to split time, how many cells in containers for n hour, It is difficult to solve for loop, We have Division number for x, deaths to y, survival number for z, we can conclude that Z=z (n) (n - 1) + x (n) - y (n) X=z (n) (n - 1) Y=x (n) (n - 3)=z (n - (4) We organize can come Z z (n)=2 * (n - 1) + z (n - (4) Public static void main (String [] args) { //TODO Auto - generated method stub Int n=5; System. The out. Println (survival (n)); } Static int survival (int n) { The switch (n) { Case 0: return 1; Case 1: return 2; Case 2: return 3; Case 3: The return of 7; Default: Return 2 * survival (n - 1) - survival (n - (4); } } CodePudding user response:
reference 4 floor qq_39936465 response: Quote: refer to the original poster m0_57306111 response: a cell's life cycle is 3 hours, 1 hour to split time, how many cells in containers for n hour, It is difficult to solve for loop, We have Division number for x, deaths to y, survival number for z, we can conclude that Z=z (n) (n - 1) + x (n) - y (n) X=z (n) (n - 1) Y=x (n) (n - 3)=z (n - (4) We organize can come Z z (n)=2 * (n - 1) + z (n - (4) Public static void main (String [] args) { //TODO Auto - generated method stub Int n=5; System. The out. Println (survival (n)); } Static int survival (int n) { The switch (n) { Case 0: return 1; Case 1: return 2; Case 2: return 3; Case 3: The return of 7; Default: Return 2 * survival (n - 1) - survival (n - (4); } } thank you bosses solution CodePudding user response:
The reference 3 floor nayi_224 response: public static void main (String [] args) { //TODO Auto - generated method stub Int n=5; Queue The queue=new LinkedList (); The queue. The add (0); for(int i=0; I & lt; n; I++) { Int k=queue. The size (); for(int j=0; J & lt; k; J++) { Int num=queue. The poll (); The queue. The add (0); The queue. The add (0); if(num ! =2)The queue. The add (num + 1); } } System. The out. Println (queue. The size ()); } ? Thank you for the answer of it CodePudding user response:
This topic has a problem, the third hour is divided and then death, or death? CodePudding user response:
According to the third division is not to be Public static void main (String [] args) { Int n=7; int sum=1; //save the first three times the number of new, used to reduce, initialization time new 1 0 Int [] incr=new int [] {1, 0, 0}; For (int I=1; I & lt;=n; I++) { System. Out.println (String format (" % s first began again, this time death data for the first new % s time, number of % s, copy the cardinality of - % s (% s) * 2=% s ", I, I - 3, incr [3] I %, sum, incr [3] I %, (sum - incr [3] I %) * 2)); Int temp=(sum - incr [3] I %) * 2; Incr [3] I %=temp - sum; System. Out. Println (the String. Format (" the first time new % s % s ", I, incr [3] I %)); Sum=temp; } System.out.println(sum); } CodePudding user response:
This problem is the key to save nearly three hours of new number, (the current count to three hours before the new number) * 2 (replication) is not the 3 hours, the current number * 2 - three hours of new copy (3 hours and then die) Simplify the model, very simple CodePudding user response:
refer to 7th floor maradona1984 response: this is a problem, the third hour is first split again, death or death? Well is first divided death again CodePudding user response:
refer to 7th floor maradona1984 response: this is a problem, the third hour is first split again, death or death? Is divided again after death,