1. A reconnaissance team received an urgent task requiring a number of persons to be selected as many as possible in a, B, C, D, E and F six players, subject to the following restrictions:
Scout A and B at least one person, a+b>=1(because each player has two states: to go and not to go, assuming not to go for 0, go to 1; each condition is represented by an equation, and each condition is satisfied with a for loop)
A and D cannot go together; a+d<=1
A, E and F three shall send two men; a+e+f = = 2
B and C neither go nor go; B+c!=1
C and D Two of people go to one; c+d==1
If D does not go, then E will not go. d+e==0 | | D=1
How many people should I ask for?
for(intA =0; A <=1; a++) { for(intb =0; b <=1; b++) { for(intc =0; C <=1; C++) { for(intD =0; D <=1; d++) { for(intE =0; E <=1; e++) { for(intf =0; F <=1; f++) { if(A + B >=1&& A + D <=1&& A + e + f = =2&& B + c! =1&& C + D = =1&& (d + e = =0|| D = =1) {Console.WriteLine ("A:"+ A +"\NB:"+ B +"\NC:"+ C +"\nd:"+ D +"\ne:", B +"\NF:"+f); } } } } } } }
2. There is a monkey and a bunch of peaches in the park, and the monkeys eat half of the peaches every day and throw away a bad one in half. By the seventh day, the monkey opened his eyes and found that there was only a peach left. Q. How many peaches are there in the park at first? (Converse thinking)
1
(*2==4)
(4+1) *2==10
int 1 ; for (int61; i--) { 12; } Console.WriteLine (" the first day of the park there are:"" a peach ");
3. Five children lined up in a team. Ask the first how old, the first to say two years older than the second, ask the second, the second one is two years older than the third, and so on. Ask the fifth child how old, the fifth child said 3 years old. Q How old is the first child?
int 3 ; for (int40; i--) { 2 * i; } Console.WriteLine ( "The first child ", "The old one");
4.1 () 2 () 3 () 4 = 4; Ask in parentheses I want to fill in (-or +)
Think of "+" or "-" as 1,-1, solving with for loop
for(intA =-1; A <=1; A = a +2) { for(intb =-1; b <=1; B = B +2) { for(intc =-1; C <=1; c = C +2) { if((1+ (A *2) + (b *3) + (c *4)) ==4) {Console.WriteLine (a+" "+ B +" "+c); } } } }
The scout team for the For statement chooses the person, the monkey eats the peach, the 5 child is the age, 1 () 2 () 3 () 4 = 4; Ask in parentheses I want to fill in (-or +) questions