[Putting] Do you really belong to the only 2% smart person?

xiaoxiao2021-03-06  58

Do you belong to a smart class 2%? The topic is this: --------------------------------- ---------------------------------------------- 1, On a street, there are 5 houses that spray 5 colors. 2, each room lives with different nationalities 3, everyone drinks different drinks, draws different brands of cigarettes, and raising different pet problems: Who is fishing? Tip: 1, British live red house 2, Swedish raised dog 3, Danish drink tea 4, green house on the left side of white house 5, green house owner drink coffee 6, pumping parmall cigarette people bird 7, yellow house The master smokes Dunhill cigarette 8, people living in the middle house drink milk 9, Norwegian people live in the first room 10, people smoking Blends cigarettes live in the next door of the cat 11, the people who raise the horse, the people who smoke Dunhill cigarettes next door 12, people who smoke Blue Master drink beer 13, German smoke Prince cigarettes 14, Norwegians live in the blue house next door 15, people who smoke Blends cigarettes have a drink of water neighborhoods: Who is fishing? -------------------------------------------------- ------------------------------ Take the top the topic to use the form: --------- -------------------------------------------------- ---------------------

House color

Nationality

drink

smokes

pet

position

red

British

Swede

Dog

yellow

Summose dunhill

green

Drink coffee

White house left

Danish

Tea

House order

House color

Nationality

Drink

pet

smokes

1

Norwegian

2 blue

3

milk

4

5

smokes

Nationality

pet

Drink

position

Dunhill

Hippage

Blue Master

beer

Prince

German

Blends

Nursing cat partition, drinking water neighbors

Pall Mall

Boy

Use the above form to fill the following table:

House order

House color

Nationality

Drink

pet

smokes

1

Norwegian

2

blue

3

milk

4

5

Think about the topic. The following is the answer:

use

C # program writes the post-post source code:

Using system;

Namespace Netsafe.math

{

Public class alyst

{

///

/// All elements in the problem

///

String [,] DATA = {{"Huang House", "Blue House", "White House", "Red House", "Green House"}

{"Norwegian", "British", "German", "Danish", "Sweden"}

{"Dunhill", "Prince", "Mixed Smoke", "Pall Mall", "Blue Master"},

{"Coffee", "Mine Water", "Tea", "Milk", "Beer"}

{"Fish", "Dinosaur", "Ma", "Bird", "Dog"}}

///

/// Answer is used to store answers

///

Int [,] answer = new int rt [6, 6];

int [,] all = new int rt [6,122];

INT count = 1; int NLVEL = 0;

int [] list = new int [6];

Public static void main (string [] args)

{

Aynst c = new ays ();

C.P (); /// Generate full alignment to all

C.Run ();

Console.read (); /// According to any key operation

}

Void Run ()

{

INT I1, I2, I3, I4, I5; // Optimize the program through logical condition sequence

For (i1 = 1; i1 <= 120; i1 ) // 房

{

/// 9, Norwegian people live in the first house

/// 14, Norwegian lives next to the blue house

/// Do not meet the conditions

///

IF (all [2, i1]! = 2) Continue;

For (int J = 0; J <5; J , Answer [J, 1] = All [J, I1]);

For (i2 = 1; i2 <= 120; i2 ) ///

{

For (int J = 0; J <5; J , Answer [J, 2] = All [J, I2]);

/// 9, Norwegian people live in the first house

IF (All [1, I2]! = 1) Continue;

/// 1, the British live in the red house

///

IF (Find (1, 4)! = Find (2, 2)).

/// 4, green house on the left side of the white house

///

IF (Find (1, 5)> Find (1, 3)).

For (i3 = 1; i3 <= 120; i3 ) / / / smoke

{

For (int J = 0; J <5; J , Answer [J, 3] = All [J, I3]);

/// 13, German picks Prince smoke

///

IF (Find (2, 3)! = Find (3, 2)) Continue;

/// 7, Huang House owner smokes Dunhill smoke

///

IF (Find (1, 1)! = Find (3, 1)) Continue;

For (i4 = 1; i4 <= 120; i4 ) /// drink

{

For (int J = 0; J <5; J , Answer [J, 4] = All [J, I4]);

/// 8, people living in the middle of the house drink milk

///

IF (All [3, I4]! = 4) Continue;

/// 5, green house owner drink coffee

///

IF (Find (1,5)! = Find (4, 1)) Continue;

/// 3, Danish drink tea

///

IF (Find (2, 4)! = Find (4, 3)) Continue;

/// 15, the neighbors of the smoke, drinking mineral water

IF (Math.Abs ​​(Find (3, 3) -find (4, 2))! = 1) Continue;

/// 12, people who take Blue Master smoke drink beer

///

IF (Find (3, 5)! = Find (4, 5)) Continue;

For (i5 = 1; i5 <= 120; i5 ) // pet

{

For (int J = 0; J <5; J , Answer [J, 5] = All [J, I5]);

/// 10, people who smoke smoke live next to the fish

///

IF (Math.Abs ​​(Find (3, 3) -find (5, 1))! = 1) Continue;

/// 2, Sweden raised a dog

///

IF (Find (2, 5)! = Find (5, 5)) Continue;

/// 6, people who pumping the Pall Mall smoke have raised a bird.

///

IF (Find (3, 4)! = Find (5, 4)) Continue;

/// 11, the hippiece lives next to people in Dunhill smoke.

IF (Math.Abs ​​(Find (5, 3) -find (3, 1))! = 1) Continue;

///

/// can live to Data, of course, the answer

///

Write_answer ();

}

}

}

}

}

}

///

/// Very typical use of recursive implementation arrangement combination algorithm.

///

Public void p ()

{

Int ncount, njudge, key;

NLEVEL ;

IF (Nlevel> 5)

{

WriteAll (); /// has a arrangement to write to all arrays

NLEVEL -

Return;

}

For (ncount = 1; ncount <= 5; ncount )

{

Key = 0;

For (njudge = 0; njudge <= NLEVEL-1; NJUDGE )

IF (ncount == List [njudge])

{

Key = 1;

Break;

}

IF (Key == 0)

{

List [NLEVEL] = NCOUNT;

p ();

}

}

NLEVEL -

}

///

/// Write an ALL array

///

Void WriteAll ()

{

INT I;

For (i = 1; i <= 5; i )

{

All [i, count] = list [i];

}

COUNT ;

}

INT Find (Int i, int J)

{

INT K;

For (k = 0; k <= 5; k )

{

IF (Answer [k, i] == j)

{

Return K;

}

}

Return -1;

}

///

/// Print the answer out

///

Void Write_answer ()

{

For (INT i = 1; i <= 5; i )

{

For (int J = 1; j <= 5; J )

{

Console.write (DATA [I-1, Answer [J, I] -1] ",")

}

Console.writeLine ();

}

Console.writeLine ();

}

}

}

-------------------------------------------------- ---------------------------------

After the program, the answer is seven possible:

Yellow house, blue house, red house, green house, white house,

Norwegian, Danish, British, German, Sweden,

Dunhill, hybrid smoke, Pall Mall, Prince, Blue Master,

Mineral water, tea, milk, coffee, beer,

Fish, horse, bird, dinosaur, dog,

Green house, blue house, yellow house, red house, white house,

Norwegian, German, Sweden, British, Danish,

Hybrid, Prince, Dunhill, Blue Master, Pall Mall,

Coffee, mineral water, milk, beer, tea,

Dinosaur, Fish, Dog, Horse, Bird,

Green house, blue house, white house, yellow house, red house,

Norwegian, German, Sweden, Dane, British,

Pall Mall, Prince, Hybrid, Dunhill, Blue Master,

Coffee, mineral water, milk, tea, beer,

Bird, fish, dog, dinosaur, horse,

Green house, blue house, white house, yellow house, red house,

Norwegian, German, Sweden, Dane, British,

Pall Mall, Prince, Hybrid, Dunhill, Blue Master, Coffee, Miners, Milk, Tea, Beer,

Bird, dinosaur, dog, fish, horse,

Green house, blue house, white house, red house, yellow house,

Norwegian, German, Sweden, British, Danish,

Pall Mall, Prince, Hybrid, Blue Master, Dunhill,

Coffee, mineral water, milk, beer, tea,

Bird, fish, dog, horse, dinosaurs,

Green house, blue house, red house, yellow house, white house,

Norwegian, German, British, Danish, Sweden,

Pall Mall, Prince, Hybrid, Dunhill, Blue Master,

Coffee, mineral water, milk, tea, beer,

Bird, fish, horse, dinosaur, dog,

Green house, blue house, red house, yellow house, white house,

Norwegian, German, British, Danish, Sweden,

Pall Mall, Prince, Hybrid, Dunhill, Blue Master,

Coffee, mineral water, milk, tea, beer,

Bird, dinosaur, horse, fish, dog,

-------------------------------------------------- ----------------------------------------

转载请注明原文地址:https://www.9cbs.com/read-113871.html

New Post(0)