爱因斯坦的问题,以下是问题提示和C++的解决方案(老外写的) 供大家学习ING

下面的问题相信很多人都听过:
1 有五栋五种颜色的房子
2 每一位房子的主人国籍都不同
3 这五个人每人只喝一种饮料,只抽一种牌子的香烟,只养一种宠物
4 没有人有相同的宠物,抽相同牌子的香烟,喝相同的饮料
提示:
1、 英国人住在红房子里
2 、瑞典人养了一条狗
3 、丹麦人喝茶
4 、绿房子在白房子左边
5 、绿房子主人喝咖啡
6 、抽PALL MALL烟的人养了一只鸟
7 、黄房子主人抽DUNHILL烟
8 、住在中间那间房子的人喝牛奶
9 、挪威人住第一间房子
10 、抽混合烟的人住在养鱼人的旁边
11 、养马人住在DUNHILL烟的人旁边
12 、抽BLUE MASTER烟的人喝啤酒
13、 德国人抽PRINCE烟
14 、挪威人住在蓝房子旁边
15 、抽混合烟的人的邻居喝矿泉水
问题是:谁养鱼?

#include "Einstein.h"
#include <windows.h>

#define COUNT_SEARCHES 1
#define FILL_IN 1

CHouse CHint::house[COUNT_HOUSES];
CHouse* CHint::propowner[COUNT_CATEGORIES*COUNT_EXTENDED_CatID];
int CSolver::count_nodes = 0;
int CHint::count_solutions = 0;

// Array of pointers to CHint objects, i.e. a list of hints.
//
// I just keep the hint list in Einstein's order.
// Should you not want to be fooled by his
// tricky order, you could move the smiplest
// hints, hint 8 and hint 9 for example, to the
// top of the list so that the program searches
// fewer nodes.
//
CHint* CSolver::hint[] =
{
 // 1. the Brit lives in the red house
 new CSingleHouseHint(BRIT, RED),

// 2. the Swede keeps dogs as pets
 new CSingleHouseHint(SWEDE, DOG),

// 3. the Dane drinks tea
 new CSingleHouseHint(DANE, TEA),

// 4. the green house is on the immediate left of the white house
 new COrderedNeighborsHint(GREEN, WHITE),
 
 // 5. the green house's owner drinks coffee
 new CSingleHouseHint(GREEN, COFFEE),

// 6. the person who smokes Pall Mall rears birds
 new CSingleHouseHint(PALLMALL, BIRD),

// 7. the owner of the yellow house smokes Dunhill
 new CSingleHouseHint(YELLOW, DUNHILL),

// 8. the man living in the center house drinks milk
 new CKnownHouseHint(HOUSE2, MILK),

// 9. the Norwegian lives in the first house
 new CKnownHouseHint(HOUSE0, NORWEGIAN),

// 10. the man who smokes blends lives next to the one who keeps cats
 new CNeighborsHint(BLENDS, CAT),

// 11. the man who keeps horses lives next to the man who smokes Dunhill
 new CNeighborsHint(HORSE, DUNHILL),

// 12. the owner who smokes BlueMaster drinks beer
 new CSingleHouseHint(BLUEMASTER, BEER),

// 13. the German smokes Prince
 new CSingleHouseHint(GERMAN, PRINCE),

// 14. the Norwegian lives next to the blue house
 new CNeighborsHint(NORWEGIAN, BLUE),

// 15. the man who smokes blends has a neighbor who drinks water
 new CNeighborsHint(BLENDS, WATER)
};

int __cdecl main(int argc, char* argv[])
{
 CSolver::DoTheWork();
 printf("Press any key to end the program ....");
 getch();
 return 0;
}

void CSolver::DoTheWork()
{
 __int64 start, finish, freq;

PrintEinsteinRiddleDescription();
 QueryPerformanceFrequency((LARGE_INTEGER*) &freq);
 QueryPerformanceCounter((LARGE_INTEGER*) &start);
 for (int i = 0; i < COUNT_SEARCHES; i++)
  Search(&hint[0]); // start the engine with the first hint
 QueryPerformanceCounter((LARGE_INTEGER*) &finish);
 
 printf("/nProgram finished the exhaustive search of %d nodes in %.5f seconds and/n",
     GetNodeCount(), (double) (finish - start) / (double) freq);
 printf("found %d solution(s)./n/n", CHint::GetSolutionCount()/COUNT_SEARCHES);
}

void CSolver::PrintEinsteinRiddleDescription()
{
 // this is the problem decription
 static const char sRiddle[][75] =
 {
  "Einstein wrote a riddle last century. He said that 98% of the world could",
  "not solve it. ",
  "",
  "Einstein's riddle",
  "There are 5 houses in five different colors in a row.",
  "In each house lives a person with a different nationality. ",
  "The five owners drink a certain type of beverage, smoke a certain brand of",
  "cigar and keep a certain pet.",
  "No owners have the same pet, smoke the same brand of cigar or drink the",
  "same beverage.",
  "",
  "The question is: Who owns the fish?",
  "",
  "Einstein's hints:",
  " 1. The Brit lives in the red house",
  " 2. The Swede keeps dogs as pets",
  " 3. The Dane drinks tea",
  " 4. The green house is on the immediate left of the white house",
  " 5. The green house's owner drinks coffee",
  " 6. The person who smokes Pall Mall rears birds",
  " 7. The owner of the yellow house smokes Dunhill",
  " 8. The man living in the center house drinks milk",
  " 9. The Norwegian lives in the first house",
  "10. The man who smokes blends lives next to the one who keeps cats",
  "11. The man who keeps horses lives next to the one who smokes Dunhill",
  "12. The owner who smokes BlueMaster drinks beer",
  "13. The German smokes Prince",
  "14. The Norwegian lives next to the blue house",
  "15. The man who smokes blends has a neighbor who drinks water"
 };

for (int i = 0; i < sizeof(sRiddle)/75; i++)
  puts(sRiddle[i]);
 puts("/n/nMachine's solution(s):/n");
}

void CSolver::Search(CHint** ppCHint)
{
 CHint* pCHint = *ppCHint;      // pointer to current hint
 
 IncNodeCount();         // increament node count
 pCHint->ResetSeekPosition();     // reset to start position

while (pCHint->AssignPropToNextEligibles())  // seek and assign each eligibles
 {            // with properties.
  if (ppCHint != &hint[sizeof(hint)/sizeof(CHint*) - 1])  // is not the last
   Search(ppCHint + 1);     // search with next hint
  else          // all hints have been met
   CHint::PrintOut();      // a solution has been found
  pCHint->RemovePropFromPrevEligibles();  // undo the assign operations
 }
}

// remove property from the new owner if it exists
//
inline void CHint::RemoveProperty()
{
 if (m_pNewOwner0)
 {
  m_pNewOwner0->ClearProperty(m_pid0);
  RegisterOwnership(m_pid0, NULL);  // nobody owns m_pid0 now
 }
}

__forceinline int CHint::AssignPropertySetNextPos(CHouse* p0, CHouse* pNext)
{
 m_pNext = pNext;       // set next start for next seek
 if (p0 == NULL)        // m_pid0 has a owner alread
  m_pNewOwner0 = NULL;     // set no new owner flag
 else
 {
  m_pNewOwner0 = p0;      // keep the new owner for later recall
  p0->SetProperty(m_pid0);   
  RegisterOwnership(m_pid0, p0);   // p0 now has the title for m_pid0
 }
 return -1;
}
 
void CMultiPropertiesHint::RemovePropFromPrevEligibles()
{
 RemoveProperty();
 if (m_pNewOwner1)
 {
  m_pNewOwner1->ClearProperty(m_pid1);
  RegisterOwnership(m_pid1, NULL);   // nobody owns m_pid1 now
 }
}

__forceinline int CMultiPropertiesHint::AssignPropertiesSetNextPos(CHouse* p0,
                   CHouse* p1,
                   CHouse* pNext)
{
 AssignPropertySetNextPos(p0, pNext);
 if (p1 == NULL)        // m_pid1 has a owner alread
  m_pNewOwner1 = NULL;     // set no new owner flag
 else
 {
  m_pNewOwner1 = p1;      // keep the new owner for later recall
  p1->SetProperty(m_pid1);    
  RegisterOwnership(m_pid1, p1);   // p1 now has the title for m_pid1
 }
 return -1;
}

int CKnownHouseHint::AssignPropToNextEligibles()
{
 if (m_pNext == NULL)      // NULL is the stop sign
  return 0;

CHouse* pOwner = GetPropertyOwner(m_pid0);

if (pOwner)         // property m_pid0 has a owner already
 {
  if (pOwner == m_pKnownHouse)   // is it the required owner?
   return AssignPropertySetNextPos(NULL, NULL);
  return 0;
 }
 else if (m_pKnownHouse->IsEmpty(m_pid0))
  return AssignPropertySetNextPos(m_pKnownHouse, NULL);
 else
  return 0;
}

int COrderedNeighborsHint::AssignPropToNextEligibles()
{
 if (m_pNext >= &house[HOUSE4])  // &house[HOUSE4] acts as a stop sign:)
  return 0;

CHouse* pOwner0 = GetPropertyOwner(m_pid0);
 CHouse* pOwner1 = GetPropertyOwner(m_pid1);

if (pOwner0 && pOwner1)    // both m_pid0 and m_pid1 have owners already
 {
  if (pOwner1 == pOwner0 + 1)  // pOwner0 is on the immmeadiate left of pOwner1
   return AssignPropertiesSetNextPos(NULL, NULL, &house[HOUSE4]);
  return 0;
 }
 else if (pOwner0)     // pOwner1 == NULL; nobody owns m_pid1
 { 
  if (pOwner0 < &house[HOUSE4] && (pOwner0 + 1)->IsEmpty(m_pid1))
   return AssignPropertiesSetNextPos(NULL, pOwner0 + 1, &house[HOUSE4]);
  return 0;
 }
 else if (pOwner1)     // pOwner0 == NULL; nobody owns m_pid0
 {
  if (pOwner1 > &house[HOUSE0] && (pOwner1 - 1)->IsEmpty(m_pid0))
   return AssignPropertiesSetNextPos(pOwner1 - 1, NULL, &house[HOUSE4]);
  return 0;
 }
 else // pOwner0 == NULL && pOwner1 == NULL;  nobody owns m_pid0 or m_pid1
 {
  CHouse* p = m_pNext;
  
  while (p < &house[HOUSE4])
  {
   if (p->IsEmpty(m_pid0) && (p + 1)->IsEmpty(m_pid1))
    return AssignPropertiesSetNextPos(p, p + 1, p + 1);
   p++;
  }
  return 0;
 }
}

int CSingleHouseHint::AssignPropToNextEligibles()
{
 if (m_pNext >= &house[COUNT_HOUSES])  // &house[COUNT_HOUSES] acts as stop sign
  return 0;

CHouse* pOwner0 = GetPropertyOwner(m_pid0);
 CHouse* pOwner1 = GetPropertyOwner(m_pid1);

if (pOwner0 && pOwner1)
 {
  if (pOwner0 == pOwner1)  
   return AssignPropertiesSetNextPos(NULL, NULL, &house[COUNT_HOUSES]);
  return 0;
 }
 else if (pOwner0)       // pOwner1 == NULL; nobody owns m_pid1
 {
  if (pOwner0->IsEmpty(m_pid1))
   return AssignPropertiesSetNextPos(NULL, pOwner0, &house[COUNT_HOUSES]);
  return 0;        // failed
 }
 else if (pOwner1)       // pOwner0 == NULL; nobody owns m_pid0
 {
  if (pOwner1->IsEmpty(m_pid0))
   return AssignPropertiesSetNextPos(pOwner1, NULL, &house[COUNT_HOUSES]);
  return 0;
 }
 else // pOwner0 == NULL && pOwner1 == NULL;  nobody owns m_pid0 or m_pid1
 {
  CHouse* p = m_pNext;
 
  while (p < &house[COUNT_HOUSES])
  {
   if (p->IsEmpty(m_pid0) && p->IsEmpty(m_pid1))
    return AssignPropertiesSetNextPos(p, p, p + 1);
   p++;
  }
  return 0;
 }
}

int CNeighborsHint::AssignPropToNextEligibles()
{
 if (m_pNext >= &house[HOUSE4])    // &house[HOUSE4] acts as stop sign
  return 0;

CHouse* pOwner0 = GetPropertyOwner(m_pid0);
 CHouse* pOwner1 = GetPropertyOwner(m_pid1);

if (pOwner0 && pOwner1)
 {
  if (pOwner0 - pOwner1 == 1 || pOwner0 - pOwner1 == -1)  
   return AssignPropertiesSetNextPos(NULL, NULL, &house[HOUSE4]);
  return 0;
 }
 else if (pOwner0)       // pOwner1 == NULL; nobody owns m_pid1
 {
  if (!m_NextReverse && pOwner0 < &house[HOUSE4] && (pOwner0 + 1)->IsEmpty(m_pid1))
  {
   m_NextReverse = -1;
   return AssignPropertiesSetNextPos(NULL, pOwner0 + 1, pOwner0);
  }
  if (pOwner0 > &house[HOUSE0] && (pOwner0 - 1)->IsEmpty(m_pid1))
   return AssignPropertiesSetNextPos(NULL, pOwner0 - 1, &house[HOUSE4]);
  return 0;
 }
 else if (pOwner1)       // pOwner0 == NULL; nobody owns m_pid0
 {
  if (!m_NextReverse && pOwner1 < &house[HOUSE4] && (pOwner1 + 1)->IsEmpty(m_pid0))
  {
   m_NextReverse = -1;
   return AssignPropertiesSetNextPos(pOwner1 + 1, NULL, pOwner1);
  }
  if (pOwner1 > &house[HOUSE0] && (pOwner1 - 1)->IsEmpty(m_pid0))
   return AssignPropertiesSetNextPos(pOwner1 - 1, NULL, &house[HOUSE4]);
  return 0;
 }
 else      // pOwner0 == NULL && pOwner1 == NULL
 {
  CHouse* p = m_pNext;
 
  while (p < &house[HOUSE4])
  {
   if (!m_NextReverse && p->IsEmpty(m_pid0) && (p + 1)->IsEmpty(m_pid1))
   {
    m_NextReverse = -1;
    return AssignPropertiesSetNextPos(p, p + 1, p);
   }
   if (p->IsEmpty(m_pid1) && (p + 1)->IsEmpty(m_pid0))
   {
    m_NextReverse = 0;
    return AssignPropertiesSetNextPos(p + 1, p, p + 2);
   }
   p += 2;
  }
  return 0;
 }
}

// This function is to verify current solution and is to be called whenever a
// solution is found.
//
// return:
//   NULL: failed for search error(s).
//   nonzero: pointer to the owner of the fish
//
CHouse* CHint::VerifyCurrentSolution()
{
 CHouse* pFishOwner = NULL;

for (int i = 0; i < COUNT_HOUSES; i++)
 {
  if (house[i].IsEmpty(COLOR) || house[i].IsEmpty(NATIONALITY) ||
   house[i].IsEmpty(BAVERAGE) || house[i].IsEmpty(CIGAR)
   )
   return NULL;

if (house[i].IsEmpty(PET))
   if (pFishOwner)
    return NULL;
   else
    pFishOwner = &house[i];
 }
 return pFishOwner;
}

// This interface function verifies and prints out the current solution
//
void CHint::PrintOut()
{
 IncSolutionCount();     // the solution is valid
#if FILL_IN > 0
 CHouse* pFishOwner = VerifyCurrentSolution();

if (pFishOwner == NULL)
 {
  puts("found a search error./n");
  return;
 }
 // we have also to fill in the fish before sending a solution solution to
 // the screen because Einstein did not mention it in his hints.
 //
 pFishOwner->SetProperty(FISH);
#endif

printout();

#if FILL_IN > 0
 pFishOwner->ClearProperty(FISH); // restore the world for further search
#endif
}

// Print a solution on console screen
// Some of the drawing code in this function was borrowed from Manfred Becker's.
//
void CHint::printout()
{
 static const char sColor[][7 + 1] =
 {
  "  blue ", "  green", "   red ", "  white", " yellow"
 };
 static const char sNationality[][9 + 1] =
 {
  "  Brit   ", "  Dane   ", " German  ", "Norwegian", "  Swede  "
 };
 static const char sBaverage[][7 + 1] =
 {
  "  Beer ", " Coffee", "  Milk ",  "   Tea ", "  Water"
 };
 static const char sCigar[][9 + 1] =
 {
  " Blends  ", "BlueMastr", " Dunhill ", "Pall Mall", " Prince  " };
 static const char sPet[][7 + 1] =
 {
  "  Bird ", "   Cat ", "   Dog ", "  Fish ", "  Horse"
 };

static const char sWild7[] =  "   *   ";
 static const char sWild9[] = "    *    ";

static char sln[][79] =
 {
  "     / //            / //            / //            / //            / //",
  "    /   //          /   //          /   //          /   //          /   //",
  "   /  1  //        /  2  //        /  3  //        /  4  //        /  5  //",
  "  /       //      /       //      /       //      /       //      /       //",
  " /         //    /         //    /         //    /         //    /         // ",
  "/___________//  /___________//  /___________//  /___________//  /___________//",
  "|           |  |           |  |           |  |           |  |           |",
  "|           |  |           |  |           |  |           |  |           |",
  "|           |  |           |  |           |  |           |  |           |",
  "|           |  |           |  |           |  |           |  |           |",
  "|           |  |           |  |           |  |           |  |           |",
  "|___________|  |___________|  |___________|  |___________|  |___________|"
 };

// Print houses...
 int i;
 for (i = 0; i < COUNT_HOUSES; i++)
 {
  memcpy(&sln[4][2 + 15*i], house[i].IsEmpty(COLOR) ? sWild7 : sColor[house[i].GetPropIndex(COLOR)], 7);
  memcpy(&sln[7][2 + 15*i], house[i].IsEmpty(NATIONALITY) ? sWild9 : sNationality[house[i].GetPropIndex(NATIONALITY)], 9);
  memcpy(&sln[8][2 + 15*i], house[i].IsEmpty(BAVERAGE) ? sWild7 : sBaverage[house[i].GetPropIndex(BAVERAGE)], 7);
  memcpy(&sln[9][2 + 15*i], house[i].IsEmpty(CIGAR) ? sWild9 : sCigar[house[i].GetPropIndex(CIGAR)], 9);
  memcpy(&sln[10][2 + 15*i], house[i].IsEmpty(PET) ? sWild7 : sPet[house[i].GetPropIndex(PET)], 7);
 }

for (i = 0; i < sizeof(sln)/79; i++)
  puts(sln[i]);
 puts("/n");
}

以下是头文件内容:

#include <iostream>
#include <conio.h>
#include <time.h>

enum Problem_Constants
{
 COUNT_HOUSES = 5,
    COUNT_CATEGORIES = 5,
// COUNT_HINTS = 15,
 BITS_CatID = 3,
 COUNT_EXTENDED_CatID = 1 << BITS_CatID   //  COUNT_EXTENDED_CatID = 8
};

// Property Category ID
enum CatID
{
 COLOR,
 NATIONALITY,
 BAVERAGE,
 CIGAR,
 PET
};

// Property Identifications
enum PropID
{
 BLUE       = (0 << BITS_CatID) | COLOR, 
 GREEN      = (1 << BITS_CatID) | COLOR,  
 RED        = (2 << BITS_CatID) | COLOR,     
 WHITE      = (3 << BITS_CatID) | COLOR,    
 YELLOW     = (4 << BITS_CatID) | COLOR,

BRIT    = (0 << BITS_CatID) | NATIONALITY,  
 DANE       = (1 << BITS_CatID) | NATIONALITY,       
 GERMAN     = (2 << BITS_CatID) | NATIONALITY,  
 NORWEGIAN  = (3 << BITS_CatID) | NATIONALITY,
 SWEDE      = (4 << BITS_CatID) | NATIONALITY,

BEER       = (0 << BITS_CatID) | BAVERAGE,
 COFFEE     = (1 << BITS_CatID) | BAVERAGE,
 MILK    = (2 << BITS_CatID) | BAVERAGE,
 TEA     = (3 << BITS_CatID) | BAVERAGE,
 WATER    = (4 << BITS_CatID) | BAVERAGE,

BLENDS     = (0 << BITS_CatID) | CIGAR,
 BLUEMASTER = (1 << BITS_CatID) | CIGAR,
 DUNHILL    = (2 << BITS_CatID) | CIGAR,
 PALLMALL   = (3 << BITS_CatID) | CIGAR,
 PRINCE    = (4 << BITS_CatID) | CIGAR,

BIRD    = (0 << BITS_CatID) | PET,
 CAT        = (1 << BITS_CatID) | PET,
 DOG     = (2 << BITS_CatID) | PET,
 FISH    = (3 << BITS_CatID) | PET,
 HORSE    = (4 << BITS_CatID) | PET
};

enum HouseID
{
 HOUSE0, HOUSE1, HOUSE2, HOUSE3, HOUSE4
};

class CHouse
{
private:
 enum
 { 
  // EMPTY is a flag to indicate a null property of any category.
  // Its value must not be equal to any real property (any element of PropID).
  EMPTY  = (0 << BITS_CatID) | PET + 1
 };

PropID m_property[COUNT_CATEGORIES];

// constructor
public:
 CHouse()
 {
  for (int i = 0; i < COUNT_CATEGORIES; i++)
   m_property[i] = (PropID) EMPTY;
 }

// operations
public:
 int IsEmpty(CatID cid)   { return m_property[cid] == EMPTY; }
 int IsEmpty(PropID pid)   { return IsEmpty(GetCatID(pid)); }
 int GetPropIndex(CatID cid)  { return GetIndex(m_property[cid]); }
 void SetProperty(PropID pid) { m_property[GetCatID(pid)] = pid; }
 void ClearProperty(PropID pid) { m_property[GetCatID(pid)] = (PropID) EMPTY;}

private:
 CatID GetCatID(PropID pid) { return (CatID) (pid & (COUNT_EXTENDED_CatID - 1)); }
 int GetIndex(PropID pid)   { return pid >> BITS_CatID; }
};

class CHint
{
protected:
 const PropID m_pid0; // a property in the hint
 CHouse* m_pNewOwner0; // ptr to a would-be owner of the property to meet the hint
 CHouse* m_pNext;  // the next house to be checked and filled

static CHouse house[COUNT_HOUSES];    // array of the houses
private:
 // array of pointers to house owners indexed by PropID
 static CHouse* propowner[COUNT_CATEGORIES*COUNT_EXTENDED_CatID];
 static int count_solutions;      // count of solutions found

// constructor
protected:
 CHint(PropID pid0) : m_pid0(pid0) {}

public:
 // starting from house specified by m_pNext, seek and assign the
 // first eligible houseowner(s) with properties.
 //
 // return value:
 //   0 : failed 
 // nonzero : successful
 //
 virtual int AssignPropToNextEligibles() = 0; 
 
 virtual void RemovePropFromPrevEligibles() = 0; // undo AssignPropToNextEligibles
 virtual void ResetSeekPosition() = 0;   // reset the seek to start position
 static  void PrintOut();      // print out a solution

// helpers
protected:
 void RemoveProperty();       // remove property from new owner
 int AssignPropertySetNextPos(CHouse* p0, CHouse* pNext);

// property register operations
protected:
 static CHouse* GetPropertyOwner(PropID pid) { return propowner[pid]; }
 static void RegisterOwnership(PropID pid, CHouse* pOwner)
 { 
  propowner[pid] = pOwner;
 }

// counter
public:
 static int GetSolutionCount()  { return count_solutions; };
private:
 static void IncSolutionCount() { count_solutions++; };

// helper
 static CHouse*  VerifyCurrentSolution();    // verify a solution and check for errors
 static void printout();
};

// class for any hint of Known house number
//
class CKnownHouseHint : public CHint
{
private:
 CHouse* const m_pKnownHouse;

public:
 CKnownHouseHint(HouseID i, PropID pid) : CHint(pid), m_pKnownHouse(&house[i]) {}

private:
 virtual int AssignPropToNextEligibles(); 
 virtual void ResetSeekPosition()     { m_pNext = m_pKnownHouse; }
 virtual void RemovePropFromPrevEligibles() { RemoveProperty(); }
};

// class for any hint that involves Multiple properties
//
class CMultiPropertiesHint : public CHint
{
protected:
 const PropID m_pid1; // a property in the hint
 CHouse* m_pNewOwner1; // ptr to a would-be owner of the property to meet the hint

// implementations
protected:
 virtual void RemovePropFromPrevEligibles();

// constructor
protected:
 CMultiPropertiesHint(PropID pid0, PropID pid1) : CHint(pid0), m_pid1(pid1) { }

// helpers
protected:
 void ResetSeekPositionToFirstHouse() { m_pNext = &house[HOUSE0]; }
 int AssignPropertiesSetNextPos(CHouse* p0, CHouse* p1, CHouse* pNext);
};

// class for the any hint that only involves a Single houseowner
//
class CSingleHouseHint : public CMultiPropertiesHint
{
// constructor
public:
 CSingleHouseHint(PropID pid0, PropID pid1) : CMultiPropertiesHint(pid0, pid1) { }

// implementations
private:
 virtual int AssignPropToNextEligibles(); 
 virtual void ResetSeekPosition() { ResetSeekPositionToFirstHouse(); }
};

// class for any hint that involves 2 Neighbors Ordered by direction
//
class COrderedNeighborsHint : public CMultiPropertiesHint
{
// constructor
public:
 COrderedNeighborsHint(PropID pid0, PropID pid1) : CMultiPropertiesHint(pid0, pid1) {}

// implementations
private:
 virtual int AssignPropToNextEligibles(); 
 virtual void ResetSeekPosition() { ResetSeekPositionToFirstHouse(); }
};

// class for any hint that involves 2 Neighbors without a directional restriction
//
class CNeighborsHint : public CMultiPropertiesHint
{
private:
 int m_NextReverse;   // are the properties to be filled in reverse order?

// constructor
public:
 CNeighborsHint(PropID pid0, PropID pid1) : CMultiPropertiesHint(pid0, pid1) { }

// implementations
private:
 virtual int AssignPropToNextEligibles(); 
 virtual void ResetSeekPosition()  
 {
  ResetSeekPositionToFirstHouse();
  m_NextReverse = 0;
 }
};

// class for finding the solutions
//
class CSolver
{
private:
 static CHint* hint[];       // array of pointers to CHint objects
 static int count_nodes;       // count of nodes searched

// operations
public:
 static void DoTheWork();      // search driver

// helpers
private:
 static void Search(CHint** ppCHint);   // search engine
 static void PrintEinsteinRiddleDescription();
 static void IncNodeCount()    { count_nodes++; };
 static int GetNodeCount()    { return count_nodes; };
};

爱因斯坦的超级问题(C++ code)相关推荐

  1. 爱因斯坦的超级问题(人工智能实验二报告)

    文章目录 实验题目 实验目的 实验平台 实验内容 实验步骤 具体设计 1. 题目详情 2. 题目分析 3. Prolog代码 4. 运行结果 Prolog表相关知识 Prolog安装及使用 讨论与结论 ...

  2. 超级无敌VS Code配置Java开发环境教程

    如何在VS Code配置Java开发环境 参考翻译自官方文档:https://code.visualstudio.com/docs/java/java-tutorial 1.建立VS Code的Jav ...

  3. “爱因斯坦的超级问题:谁养鱼?”

    http://blog.tianya.cn/blogger/post_read.asp?BlogID=3262781&PostID=30709262

  4. 爱因斯坦的超级问题(谁养鱼)SQL解法

    问题: 在一条街上 有5座房子 喷了5种颜色 每个房里住着不同国籍的人 每个人喝不同的饮料        抽不同的香烟         养不同的宠物 请问,谁养鱼? 提示: A. 英国人住红色房子 B ...

  5. 《爱因斯坦的问题》解答

    看到这样一个问题,题目就叫<爱因斯坦的问题>,光看题目就很有意思,打开后看了问题内容,第一反应是"晕",而后在纸上画了画,大体理清了思路,不过实在是懒得算,就准备写个程 ...

  6. 2017吉首大学新生赛

    http://120.78.162.102/problem.php?cid=1333&pid=0 [问题 A: 4357买糖][等差数列] Code: #include <bits/st ...

  7. 非常实用的Asp.net常用的51个代码

    1.弹出对话框.点击转向指定页面 Code: Response.Write("<script>window.alert('该会员没有提交申请,请重新提交!')</scrip ...

  8. 如何假装自己读懂了《时间简史》

    什么!霍金他老人家都仙逝了,你还没看懂<时间简史>?作为一名当代精英,这实在是太丢人了,严重拖了人类进步的后腿!根据"死后地位自动升一级"公理,霍金的声望已不在牛顿和爱 ...

  9. 【今日CV 计算机视觉论文速览 第116期】Mon, 13 May 2019

    今日CS.CV 计算机视觉论文速览 Mon, 13 May 2019 Totally 40 papers ?上期速览✈更多精彩请移步主页 Interesting: ?T-Net新的编码器解码器架构,新 ...

最新文章

  1. python数据结构与算法:二分查找
  2. 21. Matlab中的Live scrip ---实时脚本
  3. 拼多多面试真题:如何用 Redis 统计独立用户访问量!
  4. 中国联轴器行业发展态势分析及十四五规划建议报告2021-2027年
  5. python使用redis在实际场景使用_Python使用Redis实现作业调度系统(超简单)
  6. 9读书1-我在义务发财(1)
  7. P7443-加边【博弈论】
  8. 我为什么不无偿加班,你也不应该
  9. [转载]MyISAM InnoDB 区别
  10. 肝了一夜,用90行代码打造最强PDF转换器,word、PPT、excel、markdown、html一键转换...
  11. 一个链接搞定源码下载
  12. C语言程序入门(零基础入门)
  13. Digester 解析遇到字符失败
  14. 两个点 定位_智造讲堂:RFID定位导航技术
  15. TR069协议与商业应用6——TR069动态库开发
  16. IDEA 重复执行 updating indices问题
  17. (转)计算机组成与结构:原码、反码、补码、移码、二进制乘除法运算
  18. DirectX诊断工具 dxdiag
  19. 安卓chrome插件开发!你有过迷茫吗?最全的BAT大厂面试题整理
  20. 高可靠环境 FileNet 系统介绍和应用实例

热门文章

  1. racket android,RacketGhost | F-Droid - Free and Open Source Android App Repository
  2. 股票公式编程是c语言,C语言编写公式的基础(飞狐用).doc
  3. signal函数——自定义信号处理方式
  4. 计算机大白菜是什么东西,大白菜u盘启动怎么样在计算机里查看图片
  5. 如何用javafx实现闪烁效果?
  6. 告诉你HR看完简历却不通知面试的真相!
  7. 饥荒联机版Mod开发——准备工具(一)
  8. mega-nerf安装流程
  9. 英特尔第十代处理器为什么不支持win7_新硬件不支持Win7怎么回事? 新CPU仅兼容Win10的原因解析...
  10. Maven | 05.Maven项目结构及Maven命令