CÓïÑÔº¯Êý£¨¶þ£©
¡¾Àý8.6¡¿HanoiËþÎÊÌâ
Ò»¿é°åÉÏÓÐÈý¸ùÕ룬A£¬B£¬C¡£AÕëÉÏÌ×ÓÐ64¸ö´óС²»µÈµÄÔ²ÅÌ£¬´óµÄÔÚÏ£¬Ð¡µÄÔÚÉÏ¡£Èçͼ5.4Ëùʾ¡£Òª°ÑÕâ64¸öÔ²ÅÌ´ÓAÕëÒƶ¯CÕëÉÏ£¬Ã¿´ÎÖ»ÄÜÒƶ¯Ò»¸öÔ²ÅÌ£¬Òƶ¯¿ÉÒÔ½èÖúBÕë½øÐС£µ«ÔÚÈκÎʱºò£¬ÈκÎÕëÉϵÄÔ²Å̶¼±ØÐë±£³Ö´óÅÌÔÚÏ£¬Ð¡ÅÌÔÚÉÏ¡£ÇóÒƶ¯µÄ²½Öè¡£
±¾ÌâËã·¨·ÖÎöÈçÏ£¬ÉèAÉÏÓÐn¸öÅÌ×Ó¡£
Èç¹ûn=1£¬Ôò½«Ô²ÅÌ´ÓAÖ±½ÓÒƶ¯µ½C¡£
Èç¹ûn=2£¬Ôò£º
1.½«AÉϵÄn-1(µÈÓÚ1)¸öÔ²ÅÌÒƵ½BÉÏ£»
2.ÔÙ½«AÉϵÄÒ»¸öÔ²ÅÌÒƵ½CÉÏ£»
3.×îºó½«BÉϵÄn-1(µÈÓÚ1)¸öÔ²ÅÌÒƵ½CÉÏ¡£
Èç¹ûn=3£¬Ôò£º
A. ½«AÉϵÄn-1(µÈÓÚ2£¬ÁîÆäΪn`)¸öÔ²ÅÌÒƵ½B(½èÖúÓÚC)£¬²½ÖèÈçÏ£º
(1)½«AÉϵÄn`-1(µÈÓÚ1)¸öÔ²ÅÌÒƵ½CÉÏ¡£
(2)½«AÉϵÄÒ»¸öÔ²ÅÌÒƵ½B¡£
(3)½«CÉϵÄn`-1(µÈÓÚ1)¸öÔ²ÅÌÒƵ½B¡£
B. ½«AÉϵÄÒ»¸öÔ²ÅÌÒƵ½C¡£
C. ½«BÉϵÄn-1(µÈÓÚ2£¬ÁîÆäΪn`)¸öÔ²ÅÌÒƵ½C(½èÖúA)£¬²½ÖèÈçÏ£º
(1)½«BÉϵÄn`-1(µÈÓÚ1)¸öÔ²ÅÌÒƵ½A¡£
(2)½«BÉϵÄÒ»¸öÅÌ×ÓÒƵ½C¡£
(3)½«AÉϵÄn`-1(µÈÓÚ1)¸öÔ²ÅÌÒƵ½C¡£
µ½´Ë£¬Íê³ÉÁËÈý¸öÔ²Å̵ÄÒƶ¯¹ý³Ì¡£
´ÓÉÏÃæ·ÖÎö¿ÉÒÔ¿´³ö£¬µ±n´óÓÚµÈÓÚ2ʱ£¬Òƶ¯µÄ¹ý³Ì¿É·Ö½âΪÈý¸ö²½Ö裺
µÚÒ»²½ °ÑAÉϵÄn-1¸öÔ²ÅÌÒƵ½BÉÏ£»
µÚ¶þ²½ °ÑAÉϵÄÒ»¸öÔ²ÅÌÒƵ½CÉÏ£»
µÚÈý²½ °ÑBÉϵÄn-1¸öÔ²ÅÌÒƵ½CÉÏ£»ÆäÖеÚÒ»²½ºÍµÚÈý²½ÊÇÀàͬµÄ¡£
µ±n=3ʱ£¬µÚÒ»²½ºÍµÚÈý²½ÓÖ·Ö½âΪÀàͬµÄÈý²½£¬¼´°Ñn`-1¸öÔ²ÅÌ´ÓÒ»¸öÕëÒƵ½ÁíÒ»¸öÕëÉÏ£¬ÕâÀïµÄn`=n-1¡£ ÏÔÈ»ÕâÊÇÒ»¸öµÝ¹é¹ý³Ì£¬¾Ý´ËËã·¨¿É±à³ÌÈçÏ£º
move(int n,int x,int y,int z)
{
if(n==1)
printf("%c-->%c\n",x,z);
else
{
move(n-1,x,z,y);
printf("%c-->%c\n",x,z);
move(n-1,y,x,z);
}
}
main()
{
int h;
printf("\ninput number:\n");
scanf("%d",&h);
printf("the step to moving %2d diskes:\n",h);
move(h,'a','b','c');
}
´Ó³ÌÐòÖпÉÒÔ¿´³ö,moveº¯ÊýÊÇÒ»¸öµÝ¹éº¯Êý£¬ËüÓÐËĸöÐβÎn,x,y,z¡£n±íʾԲÅÌÊý£¬x,y,z·Ö±ð±íʾÈý¸ùÕë¡£move º¯ÊýµÄ¹¦ÄÜÊÇ°ÑxÉϵÄn¸öÔ²ÅÌÒƶ¯µ½zÉÏ¡£µ±n==1ʱ£¬Ö±½Ó°
Ïà¹ØÎĵµ£º
cÓëc++ staticº¯ÊýµÄÇø±ð
±¾ÎÄת×Ô£ºhttp://blog.csdn.net/lipps/archive/2007/05/18/1615419.aspx
static¹Ø¼ü×ÖÊÇC, C++Öж¼´æÔڵĹؼü×Ö, ËüÖ÷ÒªÓÐÈýÖÖʹÓ÷½Ê½, ÆäÖÐÇ°Á½ÖÖÖ»Ö¸ÔÚCÓïÑÔÖÐʹÓÃ, µÚÈýÖÖÔÚC++ÖÐʹÓÃ(C,C++ÖоßÌåϸ΢²Ù×÷²»¾¡Ïàͬ, ±¾ÎÄÒÔC++Ϊ׼).
(1)¾Ö²¿¾²Ì¬±äÁ¿
(2)Íⲿ¾²Ì¬±ä ......
1£®½ø³ÌºÍÏ̵߳IJî±ð¡£
Ïß³ÌÊÇÖ¸½ø³ÌÄÚµÄÒ»¸öÖ´Ðе¥Ôª,Ò²Êǽø³ÌÄڵĿɵ÷¶ÈʵÌå.
Óë½ø³ÌµÄÇø±ð:
(1)µ÷¶È£ºÏß³Ì×÷Ϊµ÷¶ÈºÍ·ÖÅäµÄ»ù±¾µ¥Î»£¬½ø³Ì×÷ΪӵÓÐ×ÊÔ´µÄ»ù±¾µ¥Î»
(2)²¢·¢ÐÔ£º²»½ö½ø³ÌÖ®¼ä¿ÉÒÔ²¢·¢Ö´ÐУ¬Í¬Ò»¸ö½ø³ÌµÄ¶à¸öÏß³ÌÖ®¼äÒ²¿É²¢·¢Ö´ÐÐ
(3)ÓµÓÐ×ÊÔ´£º½ø³ÌÊÇÓµÓÐ×ÊÔ´µÄ¶ÀÁ¢µ¥Î»£¬Ï̲߳»ÓµÓÐϵͳ×ÊÔ´£¬µ«¿ÉÒ ......
¡¾checkpass.c¡¿
#include <stdio.h>
#include <string.h>
int checkpass(void){
int x;
char a[9];
x = 0;
fprintf(stderr,"a at %p and\nx at %p\n", (void *)a, (void *)&x);
printf("Enter a short word: ");
&nbs ......
±ê×¼C¿ØÖÆ̨³ÌÐòÒ²¿ÉÒÔ×Ô¶¨ÒåÎÄ×ÖÊä³öÑÕÉ«£¬ÈôòÓ¡ÐÅÏ¢¸üÏÊÃ÷£¬ÔÚdebugµÄʱºòÌرðÓÐÓ᣷½·¨ºÜ¼òµ¥£º
ת×Ô£ºhttp://www.diybl.com/course/3_program/c/c_js/20090303/157456.html
ÏÈ´ÓÒ»¸öÀý×Ó¿ªÊ¼
printf("\033[31m ####----->> \033[32m" "hello\n" "\033[m");
ÑÕÉ«·ÖΪ±³¾°É«ºÍ×ÖÌåÉ«£¬30~39ÓÃÀ´ÉèÖÃ×ÖÌåÉ« ......
¡¡¡¡Ò»¡¢c³ÌÐò´æ´¢¿Õ¼ä²¼¾Ö
¡¡¡¡C³ÌÐòÒ»Ö±ÓÉÏÂÁв¿·Ö×é³É£º
¡¡¡¡1£©ÕýÎĶΗ—CPUÖ´ÐеĻúÆ÷Ö¸Á·Ö£»Ò»¸ö³ÌÐòÖ»ÓÐÒ»¸ö¸±±¾£»Ö»¶Á£¬·ÀÖ¹³ÌÐòÓÉÓÚÒâÍâʹʶøÐÞ¸Ä×ÔÉíÖ¸Á
¡¡¡¡2£©³õʼ»¯Êý¾Ý¶Î£¨Êý¾Ý¶Î£©——ÔÚ³ÌÐòÖÐËùÓи³Á˳õÖµµÄÈ«¾Ö±äÁ¿£¬´æ·ÅÔÚÕâÀï¡£
¡¡¡¡3£©·Ç³õʼ»¯Êý¾Ý¶Î£¨bss¶Î£©&mdas ......