Who raises cats?

Source: Internet
Author: User

Five people come from different places, live in different houses, raise different animals, smoke different brands of cigarettes, drink different drinks, and like different foods. Identify who is the cat-raising person based on the following clues

1. The Red House is on the right of the Blue House and on the left of the White House (not necessarily close to each other)
2. The owner of the yellow house is from Hong Kong, and his house is not on the far left.
3. People who love pizza live next to those who love mineral water.
4. People from Beijing Love Moutai and live next to people from Shanghai.
5. who smoke Hilton cigarettes and live in horse-raising? Next door on the right.
6. Beer lovers also love chicken.
7. People in the Green House raise dogs.
8. People who love noodles live next to snakes.

9. A neighbor from Tianjin (nearby) loves beef and a neighbor from Chengdu.
10. fish farmers live in the rightmost house.
11. The person who smoked the Green Road cigarette lives in the middle of the person who smoked the Hilton cigarette and the person who smoked the 555 cigarette (close)
12. Red houses love tea.

13. People who love wine live next to those who love tofu.
14. People who smoke cigarettes in hongtashan do not live in the vicinity of the people who smoke cigarettes, nor are they from Shanghai.
15. People from Shanghai lived in the second house on the left.
16. Those who love mineral water live in the middle of the house.
17. Noodle lovers also love wine.
18. People who smoke 555 cigarettes tend to be right-aligned than those who smoke Hilton cigarettes.

 

I have knocked on 2 hours +, and I have launched it all at this time...

Cat raising in Room 4


# Include <cstdio> # include <cstdlib> # include <cmath> # include <map> # include <queue> # include <stack> # include <vector> # include <algorithm> # include <cstring> # include <string> # include <iostream> # define MS (X, y) memset (X, Y, sizeof (x) const int maxn = 1000 + 10; const int INF = 1 <30; using namespace STD; char A [8] [6]; char name [] [10] = {"color", "food", "place", "beverage", "cigarette ", "Pet", "room number"}; char color [] [10] = {"", "Red", "yellow", "blue", "green ", "White"}; char food [] [10] = {"," Sa pie "," chicken "," noodle "," beef "," Tofu "}; char from [] [10] = {"", "Beijing", "Shanghai", "Tianjin", "Chengdu", "Hong Kong"}; char drink [] [10] = {"", "Mineral Water ", "Moutai", "beer", "tea", "Wine"}; char cigar [] [10] = {"", "hilton", "inherit road ", "555", "hongtashan", "jian Pai"}; char pet [] [10] = {"", "horse", "snake", "fish ", "cat", "dog"}; char * PTR; // suppose/* NUM 1 2 3 4 5 color red, yellow, blue, green, white food, SA, chicken, noodle, beef, tofu from Beijing, Shanghai, Tianjin, Chengdu, Hong Kong, drink, mineral water, Moutai beer, tea, wine, smoke, Hilton else road 555 pet, horse, Snake, fish, cat, dog */bool J1 () {int red, blue, white; PTR = strchr (A [0],' 1 '); Red = PTR-A [0]; PTR = strchr (A [0], '3'); Blue = PTR-A [0]; PTR = strchr (A [0], '5'); White = PTR-A [0]; If (Red> blue & Red <white) return 1; return 0;} bool J2 () {int yellow; PTR = strchr (A [0], '2'); yellow = PTR-A [0]; char from = A [2] [yellow]; If (from = '5' & yellow! = 0) return 1; return 0;} bool J3 () {int num1, num2; PTR = strchr (A [1], '1 '); num1 = PTR-A [1]; PTR = strchr (A [3], '1'); num2 = PTR-A [3]; If (ABS (num2-num1) = 1) return 1; return 0;} bool J4 () {int num1, num2; char D; PTR = strchr (A [2], '1 '); D = A [3] [PTR-A [2]; num1 = PTR-A [2]; PTR = strchr (A [2], '2 '); num2 = PTR-A [2]; If (D = '2' & ABS (num1-num2) = 1) return 1; return 0;} bool J5 () {int num1, num2; PTR = strchr (A [4], '1'); num1 = PTR-A [4]; PTR = strchr ([ 5], '1'); num2 = PTR-A [5]; If (num1-num2 = 1) return 1; return 0;} bool J6 () {char food; PTR = strchr (A [3], '3'); Food = A [1] [PTR-A [3]; If (Food = '2 ') return 1; return 0;} bool j7 () {char PET; PTR = strchr (A [0], '4 '); PET = A [5] [PTR-A [0]; If (PET = '5') return 1; return 0;} bool J8 () {char PET; int num1, num2; PTR = strchr (A [1], '3'); num1 = PTR-A [1]; PTR = strchr (A [5], '2'); num2 = PTR-A [5]; If (ABS (num1-num2) = 1) return 1; return 0;} bool j9 () {Cha R food, from; int num, num1, num2; PTR = strchr (A [2], '3'); num = PTR-A [2]; int x = num-1; int y = num + 1; if (x <0 | Y> = 5) return 0; if (A [1] [x] = '4' & A [2] [Y] = '4') return 1; return 0;} bool j10 () {int num; PTR = strchr (A [5], '3'); num = PTR-A [5]; If (num = 4) return 1; return 0;} bool J11 () {int num, num1, num2; PTR = strchr (A [4], '2'); num = PTR-A [4]; PTR = strchr (A [4], '1'); num1 = PTR-A [4]; PTR = strchr (A [4], '3 '); num2 = PTR-A [4]; If (ABS (num-num1) = 1 & ABS (num2-num) = 1) return 1; return 0;} bool J12 () {char drink; PTR = strchr (A [0], '1 '); drink = A [3] [PTR-A [0]; If (drink = '4') return 1; return 0;} bool j13 () {int num1, num2; PTR = strchr (A [3], '5'); num1 = PTR-A [3]; PTR = strchr (A [1], '5 '); num2 = PTR-A [1]; If (num1-num2 = 1) return 1; return 0;} bool j14 () {int num, num1, num2; PTR = strchr (A [4], '4'); num = PTR-A [4]; PTR = strchr (A [4], '5 '); num1 = PTR-A [4]; PTR = strchr (A [2], '2'); num2 = PTR-[ 2]; If (ABS (num-num1)> 1 & ABS (num-num2)> 1) return 1; return 0;} bool j15 () {int num; PTR = strchr (A [2], '2'); num = PTR-A [2]; If (num = 1) return 1; return 0 ;} bool j16 () {int num; PTR = strchr (A [3], '1'); num = PTR-A [3]; If (num = 2) return 1; return 0;} bool J17 () {char drink; PTR = strchr (A [1], '3 '); drink = A [3] [PTR-A [1]; If (drink = '5') return 1; return 0;} bool J18 () {int num1, num2; PTR = strchr (A [4], '3'); num1 = PTR-A [4]; PTR = strchr (A [4], '1'); num2 = PTR-A [4]; If (num1-num2> 0) return 1; return 0;} bool judge () {If (J1 () & J2 () & J3 () & J4 () & J5 () & J6 () & j7 () & J8 () & j9 () & j10 () & J11 () & J12 () & j13 () & j14 () & j15 () & j16 () & J17 () & J18 () return 1; return 0;} void DFS (int cnt) {// here is a bunch of pruning ~ (No signature (Signature _ signature) used before. Complexity = 5! ^ 6, wait // for half a day... If (CNT = 1 & J1 () = 0) return; If (CNT = 3 & J2 () = 0) return; if (CNT = 3 & j9 () = 0) return; If (CNT = 3 & j15 () = 0) return; if (CNT = 4 & J3 () = 0) return; If (CNT = 4 & J6 () = 0) return; if (CNT = 4 & J12 () = 0) return; If (CNT = 4 & j13 () = 0) return; if (CNT = 4 & j16 () = 0) return; If (CNT = 4 & J17 () = 0) return; if (CNT = 5 & J11 () = 0) return; If (CNT = 5 & j14 () = 0) return; if (CNT = 5 & J18 () = 0) return; If (CNT = 6) {If (Judge () {printf ("\ n Room No: "); For (INT I = 1; I <= 5; I ++) printf (" %-10D ", I); printf (" \ n "); for (INT I = 0; I <6; I ++) {printf ("% s:", name [I]); For (Int J = 0; j <5; j ++) {int K = A [I] [J]-'0'; if (I = 0) printf ("%-10 s ", color [k]); if (I = 1) printf ("%-10 s", food [k]); if (I = 2) printf ("%-10 s", from [k]); if (I = 3) printf ("%-10 s", drink [k]); if (I = 4) printf ("%-10 s", cigar [k]); if (I = 5) printf ("%-10 s ", pet [k]);} printf ("\ n");} printf ("\ n");} return;} Char B [] = "12345 "; do {strcpy (A [CNT], B); DFS (CNT + 1);} while (next_permutation (B, B + 5);} int main () {// freopen ("in.txt", "r", stdin); DFS (0); Return 0 ;}


Who raises cats?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.