1.1 Violent cracked chicken and rabbit cage
50 head, 120 feet, how many chickens and rabbits are there alone?
/* Chicken rabbit with cage * chicken rabbit with Cage, head 50, Foot 120 * Chicken rabbit geometry? */package Chickrabbit; public class Chickrabbit {public static void Main (string[] args) { int chick; int rabbit; int head=50; int feet=120; for (chick=0;chick<=head;chick++) { rabbit=head-chick; if (rabbit*4+chick*2==feet) { System.out.println ("Chicken:" +chick); System.out.println ("Rabbit:" +rabbit);}}}
Han Xin Soldiers of
Han Xin knows the number of troops about 1000 people, the detailed figures are unknown.
5 people a group, more than 1 people;
7 people a group, more than 2 people;
A group of 8 people. More than 3 people.
Q, how many people are there?
/* Han is aware that the number of troops is about 1000, the detailed figures are unknown. 5 people a group, more than 1 people. A group of 7 people. More than 2 people, 8 people a group, more than 3 people. Q, how many people are there? */Package chickrabbit; public class Hanxindianbing {public static void Main (string[] args) { int n; for (n = +, n < n++) { if (n% 5 = = 1 && n% 7 = 2 && n% 8 = 3) { System.out.println ("The number of troops may be:" +n);}}}
The number of troops may be: 891 the number of units may be: the number of 1171 teams may be: the number of 1451 teams may be: 1731
Horse and Tile
Total 100 horses in common
A total of 100 tiles (ancient tiles, very large, very heavy)
Every big horse can carry 3 tiles at a time.
Every pony can carry 2 tiles at a time.
The foal carries 1 pieces of shingles every time 2 ponies
Ask for the number of horses
Hint: may be multi-solution. To list all the solutions.
/* Total co-owned 100 horses have a total of 100 tiles (ancient tiles). Very big, very heavy) each horse can carry 3 watts each pony can carry 2 shingles each time the 2 Foal Pack 1 tiles to ask for the number of horses: may be multi-solution, to list all the solutions.*/Package chickrabbit; public class Horseandbrick {public static void Main (string[] args) { int HORSE = +; int BRICK = +; int big; int mid; int little; for (big=0;big<=100;big++) {for (mid=0;mid<=100;mid++) { little=horse-big-mid; if (Big*3+mid*2+little*0.5==brick) { System.out.println ("The number of various horses may be: Malaysia:" +big+ "Pony:" +mid+ "Pony:" +little); } } } }}
The number of horses may be: Malaysia: 2 pony: 30 Pony: 68 The number of horses may be: Malaysia: 5 Pony: 25 Pony: 70 The number of horses may be: Malaysia: 8 Pony: 20 Pony: 72 The number of horses may be: Malaysia: 11 Pony: 15 Pony: 74 The number of horses may be: Malaysia: 14 Pony: 10 foal: 76 The number of horses may be: Malaysia: 17 Pony: 5 Pony: 78 The number of horses may be: Malaysia: 20 Pony: 0 Ponies: 80
Fundamentals of programming algorithms-brute force method