接上一篇:

 

 
  
  1. int weekday(date a) 
  2.     int tm = a.month >= 3 ? (a.month-2) : (a.month + 10); 
  3.     int ty = a.month >= 3 ? (a.year) : (a.year-1); 
  4.     return (ty+ty/4-ty/100+ty/400+(int)(2.6*tm-0.2)+a.day)%7; 
  5.  
  6. void main65() 
  7.     date d; 
  8.     d.year = 2013; 
  9.     d.month = 3; 
  10.     d.day = 22; 
  11.     cout<<weekday(d)<<endl; 
  12.  
  13. string convertToString(double x) 
  14.     ostringstream o; 
  15.     if(o<<x) 
  16.         return o.str(); 
  17.     return "Conversion error"
  18.  
  19. double convertFromString(string s) 
  20.     istringstream i(s); 
  21.     double x; 
  22.     if(i>>x) 
  23.         return x; 
  24.     return 0.0; 
  25.  
  26. struct myComp 
  27.     bool operator() (const int &a,const int &b) 
  28.     { 
  29.         return a>b; 
  30.     } 
  31. }; 
  32.  
  33. bool myComp1(const int &a,const int &b) 
  34.     return a>b; 
  35.  
  36.  
  37. void main66() 
  38. /*  string s = "abcdefghijklmn"; 
  39.     s.replace(1,3,"good"); 
  40.     cout<<s<<endl; 
  41.     s.replace(s.begin() ,s.begin()+2,"bct"); 
  42.     cout<<s<<endl; 
  43.  
  44.     string ss = "tomcatdogkitty"; 
  45.     cout<<ss.find("cat")<<endl; 
  46.  
  47.     int loc; 
  48.     string s = "My cat's breath smells like cat food."; 
  49.  
  50.     loc = s.rfind( "breath", 8 ); 
  51.     cout << "The word breath is at index " << loc << endl; 
  52.  
  53.     loc = s.rfind( "breath", 20 ); 
  54.     cout << "The word breath is at index " << loc << endl; 
  55.      
  56.     char ch[100]; 
  57.     cin>>ch; 
  58.  
  59.     int a,b; 
  60.     char c; 
  61.     sscanf(ch,"%d%c%d",&a,&c,&b); 
  62.     cout<<a<<"  "<<b<<"  "<<c<<endl; 
  63.      
  64.     char c[100]; 
  65.     sprintf(c,"%f",120.33f); 
  66.     cout<<c<<endl; 
  67.     cout<<convertToString(44.32)<<endl; 
  68.     cout<<convertFromString("23.23")<<endl; 
  69.      
  70.     set<int,myComp> s; 
  71.     s.insert(43); 
  72.     s.insert(54); 
  73.     s.insert(0); 
  74.     s.insert(3); 
  75.     set<int,myComp>::iterator b = s.begin(); 
  76.     copy(s.begin(),s.end(),ostream_iterator<int>(cout,"  ")); 
  77.  
  78.     multiset<int> ms; 
  79.      
  80.     ms.insert(3); 
  81.     ms.insert(3); 
  82.     ms.insert(33); 
  83.     copy(ms.begin(),ms.end(),ostream_iterator<int>(cout," ")); 
  84.  
  85.     deque<int> d; 
  86.     d.push_back(2); 
  87.     d.push_back(44); 
  88.     d.push_back(12); 
  89.     d.push_back(9); 
  90.     copy(d.begin(),d.end(),ostream_iterator<int>(cout," ")); 
  91.     cout<<endl; 
  92.     d.push_front(8); 
  93.     d.push_front(01);    
  94.     copy(d.begin(),d.end(),ostream_iterator<int>(cout," ")); 
  95.     cout<<endl; 
  96.     d.insert(d.begin()+4,19); 
  97.     copy(d.begin(),d.end(),ostream_iterator<int>(cout," ")); 
  98.     cout<<endl; 
  99.     d.insert(d.begin()+2,20); 
  100.     copy(d.begin(),d.end(),ostream_iterator<int>(cout," ")); 
  101.      
  102.     list<int> l,ll; 
  103.     ll.push_back(12); 
  104.     ll.push_back(11); 
  105.     ll.push_back(2); 
  106.     ll.push_back(9); 
  107.     ll.push_back(110); 
  108.     ll.push_back(17); 
  109.     ll.push_back(42); 
  110.     ll.push_back(82); 
  111.     l.push_back(3); 
  112.     l.push_back(23); 
  113.     l.push_back(53); 
  114.     l.push_back(34); 
  115.     l.push_back(32); 
  116.     l.push_back(31); 
  117.     l.push_back(13); 
  118.     copy(l.begin(),l.end(),ostream_iterator<int>(cout," ")); 
  119.     cout<<endl; 
  120.     l.sort(); 
  121.     copy(l.begin(),l.end(),ostream_iterator<int>(cout," ")); 
  122.     cout<<endl; 
  123.     ll.sort(); 
  124.     l.merge(ll); 
  125.     copy(l.begin(),l.end(),ostream_iterator<int>(cout," ")); 
  126.     cout<<endl; 
  127.     cout.precision(4); 
  128.     cout<<23.2323<<endl; 
  129.     */ 
  130.  
  131. bool myComp2(const string &s1,const string &s2) 
  132.     int c1 = count(s1.begin(),s1.end(),'1'); 
  133.     int c2 = count(s2.begin(),s2.end(),'1'); 
  134.  
  135.     if(c1 != c2) 
  136.         return c1 < c2;  //其中'1'的个数不相等时候,按照'1'的个数进行排序 
  137.     else 
  138.         return s1 < s2;     //相等的时候,按照字典序排列 
  139.  
  140. void main68() 
  141.     vector<string> vs; 
  142.     string s; 
  143.     while(cin>>s) 
  144.     { 
  145.         vs.push_back(s); 
  146.     } 
  147.     sort(vs.begin(),vs.end(),myComp2); 
  148.     copy(vs.begin(),vs.end(),ostream_iterator<string>(cout,"\n")); 
  149.  
  150. class student 
  151. public
  152.     string name; 
  153.     double score; 
  154.     bool operator<(const student s) 
  155.     { 
  156.         if(abs(score - s.score) < 10e-6)   //认为成绩点相等 
  157.             return name < s.name; 
  158.         else 
  159.             return score > s.score; 
  160.     } 
  161.     void output() 
  162.     { 
  163.         cout<<fixed<<setprecision(2); 
  164.         cout<<left<<setw(11); 
  165.         cout<<name<<score<<endl; 
  166.     } 
  167. }; 
  168.  
  169.  
  170. void main69() 
  171.     int classNum = 0; 
  172.     int courseNum = 0; 
  173.     int studentNum = 0; 
  174.     int courseScore[N]; 
  175.     int tmpcNum = 0; 
  176.     cin>>classNum; 
  177.     while(tmpcNum < classNum) 
  178.     { 
  179.         cin>>courseNum; 
  180.         int tmp = 0; 
  181.         while(tmp<courseNum) 
  182.         { 
  183.             cin>>courseScore[tmp]; 
  184.             ++tmp; 
  185.         } 
  186.         cin>>studentNum; 
  187.         tmp = 0; 
  188.         vector<student> vs; 
  189.         while(tmp<studentNum) 
  190.         { 
  191.             student stmp; 
  192.             cin>>stmp.name; 
  193.              
  194.             int ctmp = 0; 
  195.             int scoretmp; 
  196.             double totalscore = 0.0; 
  197.             while(ctmp < courseNum) 
  198.             { 
  199.                 cin>>scoretmp; 
  200.                 if(scoretmp >= 60) 
  201.                 { 
  202.                     totalscore += ((double)(scoretmp-50) / 10) * courseScore[ctmp]; 
  203.                 } 
  204.                 ++ctmp; 
  205.             } 
  206.             stmp.score = totalscore / 10; 
  207.             ++tmp; 
  208.             vs.push_back(stmp); 
  209.         } 
  210.         sort(vs.begin(),vs.end()); 
  211.         vector<student>::iterator b = vs.begin(); 
  212.         vector<student>::iterator e = vs.end(); 
  213.         cout<<(tmpcNum ? "\n":""); 
  214.         cout<<"class "<<tmpcNum+1<<" :"<<endl; 
  215.         while(b != e) 
  216.         { 
  217.             b->output(); 
  218.             ++b; 
  219.         }             
  220.         ++tmpcNum; 
  221.     } 
  222.  
  223. void main70() 
  224.     double d = 23.212; 
  225.     cout<<fixed<<setprecision(0)<<d<<endl 
  226.         <<setprecision(1)<<d<<endl 
  227.         <<setprecision(2)<<d<<endl; 
  228.  
  229. bool myComp3(const string &s1,const string &s2) 
  230.     if(s1.length() == s2.length())   //若长度相同,则按照字典序排列 
  231.     { 
  232.         return s1 < s2; 
  233.     }else 
  234.         return s1.length() < s2.length(); 
  235.  
  236. void main71() 
  237.     vector<string> vs; 
  238.     string s; 
  239.  
  240.     while(cin>>s) 
  241.     { 
  242.         string ss = s; 
  243.         reverse(s.begin(),s.end()); 
  244.         if(ss == s) 
  245.             vs.push_back(ss); 
  246.     } 
  247.     sort(vs.begin(),vs.end(),myComp3); 
  248.     copy(vs.begin(),vs.end(),ostream_iterator<string>(cout,"\n")); 
  249.  
  250.  
  251. bool isPrime(int n) 
  252.     if(n == 1) return false
  253.     int i,j = (int)sqrt(n); 
  254.     for(i=2; i<=j; ++i) 
  255.         if(n % i == 0) 
  256.             return false
  257.     return true
  258.  
  259. bool duichen(int n) 
  260.     string s; 
  261.     ostringstream o(s); 
  262.     o<<n; 
  263.     string ss = s; 
  264.     reverse(s.begin(),s.end()); 
  265.     if(ss == s) 
  266.         return true
  267.     else return false
  268.  
  269. void main72() 
  270.     int n; 
  271.      
  272.     while(cin>>n) 
  273.     {        
  274.         cout<<(isPrime(n)&& duichen(n) ? "yes":"no" )<<endl; 
  275.     } 
  276.  
  277. void main73() 
  278.     int n,sum=1; 
  279.     for(n=1; n<=12; ++n) 
  280.         sum *= n; 
  281.     vector<int> vi; 
  282.     while(cin>>n) 
  283.     { 
  284.         if(sum % n == 0) 
  285.         { 
  286.             vi.push_back(n); 
  287.         } 
  288.     } 
  289.     int num = 0; 
  290.     while(!vi.empty()) 
  291.     { 
  292.         n = vi.front(); 
  293.         vi.erase(vi.begin()); 
  294.         vector<int>::iterator b = vi.begin(); 
  295.         vector<int>::iterator e = vi.end(); 
  296.         while(b != e) 
  297.         {    
  298.             int tmp = sum / n; 
  299.             if(*b == tmp) 
  300.             {// cout<<n<<"  "<<*b<<endl;  
  301.                 ++num; 
  302.                 vi.erase(b); 
  303.                 b = vi.begin(); 
  304.                 e = vi.end(); 
  305.             }else 
  306.                 ++b; 
  307.         } 
  308.     } 
  309.     cout<<num<<endl; 
  310.  
  311. void main75() 
  312.     stack<int> si; 
  313.     int n; 
  314.     bool flag; 
  315.     while(cin>>n) 
  316.     { 
  317.         if(n<0) 
  318.         { 
  319.             flag = false
  320.             n = -n; 
  321.         } 
  322.         else flag = true
  323.         do 
  324.         { 
  325.             si.push(n%2); 
  326.             n/=2; 
  327.         }while(n!=0); 
  328.         cout<<(flag?"":"-"); 
  329.         while(!si.empty()) 
  330.         { 
  331.             cout<<si.top(); 
  332.             si.pop(); 
  333.         } 
  334.         cout<<endl; 
  335.     } 
  336.  
  337.  
  338. //一下算法是迷宫求解 
  339. class mazeNode 
  340. public
  341.     int x,y,d; //分别代表坐标和方向 
  342. }; 
  343. #define MAZESIZE 10 
  344. int mg[MAZESIZE][MAZESIZE] = { 
  345.                 {1,1,1,1,1,1,1,1,1,1}, 
  346.                 {1,0,0,1,0,0,0,1,0,1}, 
  347.                 {1,0,0,1,0,0,0,1,0,1}, 
  348.                 {1,0,0,0,0,1,1,0,0,1}, 
  349.                 {1,0,1,1,1,0,0,0,0,1}, 
  350.                 {1,0,0,0,1,0,0,0,0,1}, 
  351.                 {1,0,1,0,0,0,1,0,0,1}, 
  352.                 {1,0,1,1,1,0,1,1,0,1}, 
  353.                 {1,1,0,0,0,0,0,0,0,1}, 
  354.                 {1,1,1,1,1,1,1,1,1,1} 
  355. };                      //迷宫的定义  1表示墙,0表示通道 
  356.  
  357. int dir[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};         //代表上右下左方向 
  358.  
  359. void findPath(int x1,int y1,int x2,int y2) 
  360.     stack<mazeNode> sm; 
  361.     mazeNode mn ,tmp; 
  362.     mg[x1][y1] = -1; 
  363.     mn.x = x1; 
  364.     mn.y = y1; 
  365.     mn.d = -1; 
  366.     sm.push(mn); 
  367.     while(!sm.empty()) 
  368.     { 
  369.         mn = sm.top();       
  370.         sm.pop(); 
  371.         if(mn.x == x2 && mn.y == y2)       //表示到了终点 
  372.         {    
  373.             cout<<"路径为: "<<endl; 
  374.             cout<<mn.x<<"  "<<mn.y<<endl; 
  375.             while(!sm.empty()) 
  376.             { 
  377.                 mn = sm.top(); 
  378.                 sm.pop(); 
  379.                 cout<<mn.x<<"  "<<mn.y<<endl; 
  380.             } 
  381.         } 
  382.         bool flag = false
  383.         while((++mn.d) < 4 && !flag) 
  384.         {                
  385.             int x = mn.x,y = mn.y; 
  386.             switch(mn.d) 
  387.             { 
  388.             case 0:  
  389.                 x += dir[0][0];     y += dir[0][1];              
  390.                 if(x > 0)         //表示没有到外墙      。这个方向向上 
  391.                 { 
  392.                     if(mg[x][y] == 0)           //表示有通道 
  393.                     { 
  394.                         mg[x][y] = -1; 
  395.                         flag = true
  396.                         tmp.x = x; 
  397.                         tmp.y = y; 
  398.                         tmp.d = -1; 
  399.                         sm.push(mn); 
  400.                         sm.push(tmp); 
  401.                         break;                              //注意此处的break不是中断if而是中断switch 
  402.                     } 
  403.                 } 
  404.                 break
  405.             case 1: 
  406.                 x += dir[1][0];     y += dir[1][1]; 
  407.                 if(y < MAZESIZE-1)                                  //表示没有到外墙。 这个方向向右 
  408.                 { 
  409.                     if(mg[x][y] == 0)  
  410.                     { 
  411.                         mg[x][y] = -1; 
  412.                         flag = true
  413.                         tmp.x = x; 
  414.                         tmp.y = y; 
  415.                         tmp.d = -1; 
  416.                         sm.push(mn); 
  417.                         sm.push(tmp); 
  418.                         break
  419.                     } 
  420.                 } 
  421.                 break
  422.             case 2: 
  423.                 x += dir[2][0];     y += dir[2][1]; 
  424.                 if(x < MAZESIZE-1)                                  //表示没有到外墙。 这个方向向右 
  425.                 { 
  426.                     if(mg[x][y] == 0)  
  427.                     { 
  428.                         mg[x][y] = -1; 
  429.                         flag = true
  430.                         tmp.x = x; 
  431.                         tmp.y = y; 
  432.                         tmp.d = -1; 
  433.                         sm.push(mn); 
  434.                         sm.push(tmp); 
  435.                         break;                           
  436.                     } 
  437.                 } 
  438.                 break
  439.             case 3: 
  440.                 x += dir[3][0];     y += dir[3][1]; 
  441.                 if(y > 0)                                   //表示没有到外墙。 这个方向向右 
  442.                 { 
  443.                     if(mg[x][y] == 0)  
  444.                     { 
  445.                         mg[x][y] = -1; 
  446.                         flag = true
  447.                         tmp.x = x; 
  448.                         tmp.y = y; 
  449.                         tmp.d = -1; 
  450.                         sm.push(mn); 
  451.                         sm.push(tmp); 
  452.                         break
  453.                     } 
  454.                 } 
  455.                 break
  456.             }            
  457.         } 
  458.     } 
  459.  
  460. void printMaze(int maze[][MAZESIZE]) 
  461.     for(int i=0; i<MAZESIZE; ++i) 
  462.     { 
  463.         for(int j=0; j<MAZESIZE; ++j) 
  464.         { 
  465.             cout<<maze[i][j]<<' '
  466.         } 
  467.         cout<<endl; 
  468.     } 
  469.  
  470. void main76() 
  471.     for(int i=0; i<100; ++i) 
  472.         if(true
  473.         { 
  474.             if(i ==23) break
  475.         } 
  476.     cout<<i<<endl; 
  477.     system("pause"); 
  478.     printMaze(mg); 
  479.     findPath(1,1,8,8); 
  480.  
  481. bool mark1[50][50][50]; 
  482. int maze[50][50][50]; 
  483.  
  484. typedef struct N1 
  485.     int x,y,z; 
  486.     int t; 
  487.     N1(int xx,int yy,int zz,int tt) 
  488.     { 
  489.         x =xx; y =yy; z =zz; t =tt; 
  490.     } 
  491.     N1(){} 
  492. }N1;                    //因为此处是 广度优先遍历所以不需要保存其方向 
  493.  
  494. int go[6][3] = { 
  495.     {1,0,0}, 
  496.     {-1,0,0}, 
  497.     {0,1,0}, 
  498.     {0,-1,0}, 
  499.     {0,0,1}, 
  500.     {0,0,-1} 
  501. }; 
  502.  
  503. queue<N1> q2; 
  504.  
  505. int BFS(int a,int b,int c) 
  506.     N1 tmp; 
  507.     while(!q2.empty()) 
  508.     { 
  509.         tmp = q2.front(); 
  510.         q2.pop(); 
  511.          
  512.         if(tmp.x == a-1 && tmp.y == b-1 && tmp.z == c-1) 
  513.         { 
  514.             return tmp.t; 
  515.         } 
  516.         for(int i=0; i<6; ++i) 
  517.         { 
  518.             int x = tmp.x + go[i][0]; 
  519.             int y = tmp.y + go[i][1]; 
  520.             int z = tmp.z + go[i][2]; 
  521.             if(x < 0 || x >= a || y < 0 || y >= b || z < 0 || z >= c) 
  522.                 continue;      //避免出墙 
  523.             if(mark1[x][y][z]) continue;        //表示此点已经遍历过  
  524.             if(maze[x][y][z] == 1)   continue
  525.             //表示此点是墙 
  526.              
  527.             q2.push(N1(x,y,z,tmp.t+1)); 
  528.             mark1[x][y][z] = true;        
  529.         } 
  530.     } 
  531.     return 100000; 
  532.  
  533. void main77() 
  534.     int T; 
  535.     cin>>T; 
  536.     while(T--) 
  537.     { 
  538.         int a,b,c,t; 
  539.         cin>>a>>b>>c>>t; 
  540.         for(int i=0; i<a; ++i) 
  541.             for(int j=0; j<b; ++j) 
  542.                 for(int k=0; k<c; ++k) 
  543.                 { 
  544.                     cin>>maze[i][j][k]; 
  545.                     mark1[i][j][k] = false
  546.                 } 
  547.         while(!q2.empty()) q2.pop(); 
  548.         mark1[0][0][0] = true
  549.         q2.push(N1(0,0,0,0)); 
  550.         int ret = BFS(a,b,c); 
  551.       
  552.         if(ret <= t) 
  553.             cout<<ret<<endl; 
  554.         else cout<<"-1"<<endl; 
  555.     } 
  556.  
  557. void AtoB(int &a,int sa,int &b,int sb) //sa sb 表示的是杯子的容积, a,b表示杯子中的液体体积 
  558. {                                    //此函数把A杯子中的水倒入B杯子中 
  559.     if(sb -b >= a)      //B杯子中能够盛下A杯子的水 
  560.     { 
  561.         b += a; 
  562.         a = 0;              
  563.     }else 
  564.     {    
  565.         a -= (sb-b);           //这两个顺序千万不能颠倒 
  566.         b = sb; 
  567.     } 
  568.  
  569. int BFS1(int s,int n,int m) 
  570.     N1 now ; 
  571.     int x,y,z; 
  572.     while(!q2.empty()) 
  573.     { 
  574.         now = q2.front(); 
  575.         q2.pop();        
  576.  
  577.         x = now.x; 
  578.         y = now.y; 
  579.         z = now.z; 
  580.   
  581.         AtoB(x,s,y,n);               //a倒向b 
  582.     //  cout<<x<<y<<z<<endl; 
  583.         if(!mark1[x][y][z])      //表示这种状态没有遇到过 
  584.         { 
  585.             mark1[x][y][z] = true
  586.             N1 tmp(x,y,z,now.t+1); 
  587.             q2.push(tmp); 
  588.              
  589.             if(x == s/2 && y == s/2) return now.t+1; 
  590.             if(y == s/2 && z == s/2) return now.t+1; 
  591.             if(x == s/2 && z == s/2) return now.t+1; 
  592.         } 
  593.  
  594.         x = now.x; 
  595.         y = now.y; 
  596.         z = now.z; 
  597.         AtoB(y,n,x,s); 
  598.         if(!mark1[x][y][z]) 
  599.         { 
  600.             mark1[x][y][z] = true
  601.             N1 tmp(x,y,z,now.t+1); 
  602.             q2.push(tmp); 
  603.              
  604.             if(x == s/2 && y == s/2) return now.t+1; 
  605.             if(y == s/2 && z == s/2) return now.t+1; 
  606.             if(x == s/2 && z == s/2) return now.t+1; 
  607.         } 
  608.  
  609.         x = now.x; 
  610.         y = now.y; 
  611.         z = now.z; 
  612.         AtoB(x,s,z,m); 
  613.         if(!mark1[x][y][z]) 
  614.         { 
  615.             mark1[x][y][z] = true
  616.             N1 tmp(x,y,z,now.t+1); 
  617.             q2.push(tmp); 
  618.              
  619.             if(x == s/2 && y == s/2) return now.t+1; 
  620.             if(y == s/2 && z == s/2) return now.t+1; 
  621.             if(x == s/2 && z == s/2) return now.t+1; 
  622.         } 
  623.  
  624.         x = now.x; 
  625.         y = now.y; 
  626.         z = now.z; 
  627.         AtoB(z,m,x,s); 
  628.         if(!mark1[x][y][z]) 
  629.         { 
  630.             mark1[x][y][z] = true
  631.             N1 tmp(x,y,z,now.t+1); 
  632.             q2.push(tmp); 
  633.              
  634.             if(x == s/2 && y == s/2) return now.t+1; 
  635.             if(y == s/2 && z == s/2) return now.t+1; 
  636.             if(x == s/2 && z == s/2) return now.t+1; 
  637.         } 
  638.  
  639.         x = now.x; 
  640.         y = now.y; 
  641.         z = now.z; 
  642.         AtoB(y,n,z,m); 
  643.         if(!mark1[x][y][z]) 
  644.         { 
  645.             mark1[x][y][z] = true
  646.             N1 tmp(x,y,z,now.t+1); 
  647.             q2.push(tmp); 
  648.              
  649.             if(x == s/2 && y == s/2) return now.t+1; 
  650.             if(y == s/2 && z == s/2) return now.t+1; 
  651.             if(x == s/2 && z == s/2) return now.t+1; 
  652.         } 
  653.  
  654.         x = now.x; 
  655.         y = now.y; 
  656.         z = now.z; 
  657.         AtoB(z,m,y,n); 
  658.         if(!mark1[x][y][z]) 
  659.         { 
  660.             mark1[x][y][z] = true
  661.             N1 tmp(x,y,z,now.t+1); 
  662.             q2.push(tmp); 
  663.              
  664.             if(x == s/2 && y == s/2) return now.t+1; 
  665.             if(y == s/2 && z == s/2) return now.t+1; 
  666.             if(x == s/2 && z == s/2) return now.t+1; 
  667.         } 
  668.     } 
  669.     return -1; 
  670.  
  671. void main78() 
  672.     int s,n,m; 
  673.     while(cin>>s>>n>>m && s) 
  674.     { 
  675.         if(s%2 != 0)   
  676.         { 
  677.             cout<<"NO"<<endl; 
  678.             continue
  679.         } 
  680.         for(int i=0; i<=s; ++i)                //注意边界,此题不同于上题,上题是个图。此题是确定的体积,边界就是输出的确定数,不必-1 
  681.             for(int j=0; j<=n; ++j)             //此题中没有图,只需要记录状态就行了 
  682.                 for(int k=0; k<=m; ++k) 
  683.                     mark1[i][j][k] = false
  684.  
  685.         while(!q2.empty())  q2.pop(); 
  686.         q2.push(N1(s,0,0,0)); 
  687.         mark1[s][0][0] = true
  688.         cout<<BFS1(s,n,m); 
  689.     } 
  690.  
  691. void hanoi(int n,char a,char b,char c)     //把盘子借助于b从a移动到c 
  692.     if(n==1)  
  693.         cout<<a<<"  -->  "<<c<<endl; 
  694.     else 
  695.     { 
  696.         hanoi(n-1,a,c,b); 
  697.         cout<<a<<"  -->  "<<c<<endl; 
  698.         hanoi(n-1,b,a,c); 
  699.     } 
  700.  
  701. __int64 hanoiIII(int n) 
  702.     if(n == 1) return 2; 
  703.     else 
  704.     { 
  705.         return hanoiIII(n-1)*3+2; 
  706.     } 
  707.  
  708. void main79() 
  709.     hanoi(3,'a','b','c' ); 
  710.     printf("%I64d\n",hanoiIII(12)); 
  711.