题目是这样的:先在纸上用一笔画出一个五角星,然后在五角星的5个角上和内部交叉点上分别画上圆圈。也就是一共10个圆圈。从1-10这10个数中不能重复的填入到这10个圈里,使得这个五角星上的五个三角形上的数字相加的值都等与16先写出答案,然后编程实现。

解决方案 »

  1.   

    郁闷,一个ID连续只能发3次.为了发布答案,只得重新申请个号了.如果给分的话,请给我原来的号吧^&^   答案只有一个
             2
      10   5   9   4
         1       3
             7
         8       6呵呵,只用C写了下,JAVA还没开始学
      

  2.   

    chizhaowei(阿冰) ( ) 信誉:100  2006-05-29 08:43:00  得分: 0  
     
     
       还有一个答案哦!             5
               /   \
        2----10-----1-----8
          \  /       \  /
            4         7
           /  \     /  \
          /      3      \  
         /     /   \     \
        /    /       \    \
         / /            \ |
        9                  6
      
    这个确实是喔,可能我编程时条件判断没处理好^_^
      

  3.   

    挺有意思,但水平有限,写的比较乱。
    public class a {
      public static void main(String[] args) {
        int y=1,y5,y6,y7,y8,y9,y10;
        for(int i=0;i<10;i++)
        {
          for(int j=0;j<10;j++)
          {
            if (j==i)
          continue;
          for(int k=0;k<10;k++)
            {
              if(k==i||k==j)
            continue;
            for(int l=0;l<10;l++)
              {
                if (l==k||l==j||l==i)
                continue;
                y5=25-i-j-k-l;
                y6=16-i-y5;
                y7=16-i-j;
                y8=16-j-k;
                y9=16-k-l;
                y10=16-l-y5;
                if (y5>10|y6>10|y7>10|y8>10|y9>10|y10>10)
                continue;
                if (y5<0|y6<0|y7<0|y8<0|y9<0|y10<0)
                continue;
                if (y5==i|y5==j|y5==k|y5==l|y5==y6|y5==y7|y5==y8|y5==y9|y5==y10)
                continue;
                if (y6==i|y6==j|y6==k|y6==l|y6==y7|y6==y8|y6==y9|y6==y10)
                continue;
                if (y7==i|y7==j|y7==k|y7==l|y7==y8|y7==y9|y7==y10)
                continue;
                if (y8==i|y8==j|y8==k|y8==l|y8==y9|y8==y10)
                continue;
                if (y9==i|y9==j|y9==k|y9==l|y9==y10)
                continue;
                if (y10==i|y10==j|y10==k|y10==l)
                continue;
                else
                System.out.println("第"+y+++"个符合条件的: "+i+"  "
                                   +j+"  "+k+"  "+l+"  "+y5+"  "
                                   +y6+"  "+y7+"  "+y8+"  "+y9
                                   +" "+y10);
              }
            }
          }
        }
      }
    }
      

  4.   

    flymoon99(遗忘代码)分析得很好
      

  5.   

    其实这种面试题不在考你会不会,而是考你的思路清晰不清晰,其实到flymoon99(遗忘代码)那基本已经可以把答案做出来了.
      

  6.   

    我的解决方案:;* * * * * * * * * * *
    ;5 STAR POWER  VER * *
    ;* * * * * * * * * * *.386
    .model flat,stdcall
    option casemap:noneinclude c:\masm32\include\windows.inc
    include c:\masm32\include\user32.inc
    includelib c:\masm32\lib\user32.lib
    include c:\masm32\include\kernel32.inc
    includelib c:\masm32\lib\kernel32.lib .const
    dllname db 'msvcrt.dll',0
    fucmalloc db 'malloc',0
    fucfree db 'free',0
    ft db 'Total Time: %d (ms) Total Times == %d Finded == %d',0
    fft db '%s',0
    cp db 'windows xp (sp2)',0
    cpc db '5 Star Power Ver',0
    szClass db 'Notepad',0
    szexit db 'Press Any Key To Exit...',0
    ten dd 10 .data?
    hInstance dd ?
    nbn dw ? ;Numbers Bit Now
    dw ?
    TTs dd ?
    FC dd ? ;Finded Counter
    tmptime dd ?
    hpad dd ?
    hstdout dd ?
    hstdin dd ?
    lpnum dd ?
    ncn db 10 dup    (?) ;Number Combination Now unZip
    fbuf db 512 dup    (?)
    buf db 512 dup    (?) .code
    ;~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
    ShowLastC proc
    local i xor eax,eax
    mov i,0
    .while  TRUE
    mov al,[edi]
    .break .if al == 0
    .if al == 10
    mov al,65
    .else
    add al,30h
    .endif
    mov buf[0],al
    invoke WriteConsole,hstdout,addr buf,1,addr lpnum,NULL
    mov byte ptr buf[0],' '
    invoke WriteConsole,hstdout,addr buf,1,addr lpnum,NULL
    inc i
    xor edx,edx
    mov eax,i
    div ten
    .if edx == 0
    mov byte ptr buf[0],0ah
    invoke WriteConsole,hstdout,addr buf,1,\
    addr lpnum,NULL
    .endif
    inc edi
    .endw
    invoke WriteConsole,hstdout,addr buf,1,\
    addr lpnum,NULL
    invoke WriteConsole,hstdout,addr szexit,sizeof szexit,\
    addr lpnum,NULL
    invoke ReadConsole,hstdin,addr buf,1,lpnum,NULL ret
    ShowLastC endp;~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
    ShowLastW proc
    local i invoke FindWindow,addr szClass,NULL
    .if eax
    mov ecx,eax
    invoke ChildWindowFromPoint,ecx,20,20
    .endif
    .if eax
    mov hpad,eax
    lea edi,fbuf
    xor eax,eax
    mov i,0
    .while  TRUE
    mov al,[edi]
    .break .if al==0
    .if al==10
    mov al,65
    .else
    add al,30h
    .endif
    invoke PostMessage,hpad,WM_CHAR,eax,1
    mov al,' '
    invoke PostMessage,hpad,WM_CHAR,eax,1
    inc i
    xor edx,edx
    mov eax,i
    div ten
    .if edx == 0
    mov al,0dh
    invoke PostMessage,hpad,WM_CHAR,eax,1
    .endif inc edi

    .endw
    .else
    jmp quitme
    .endifquitme:
    retShowLastW endp
    ;~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
    calcncn proc

    mov al,ncn[0]
    add al,ncn[1]
    add al,ncn[2]
    sub al,16
    jnz quitme
    mov al,ncn[2]
    add al,ncn[3]
    add al,ncn[4]
    sub al,16
    jnz quitme
    mov al,ncn[4]
    add al,ncn[5]
    add al,ncn[6]
    sub al,16
    jnz quitme
    mov al,ncn[6]
    add al,ncn[7]
    add al,ncn[8]
    sub al,16
    jnz quitme
    mov al,ncn[8]
    add al,ncn[9]
    add al,ncn[0]
    sub al,16
    jnz quitme

    lea edi,fbuf
    mov ebx,FC
    lea ebx,[ebx*8]
    add ebx,FC
    add ebx,FC
    mov eax,dword ptr ncn[0]
    mov dword ptr [edi+ebx],eax
    mov eax,dword ptr ncn[4]
    mov dword ptr [edi+ebx+4],eax
    mov ax,word ptr ncn[8]
    mov word ptr [edi+ebx+8],ax inc FC
    quitme:
    retcalcncn endp
    ;~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
    calcncn2 proc

    mov al,ncn[0]
    add al,ncn[1]
    add al,ncn[2]
    .if al != 16
    jmp quitme
    .endif
    mov al,ncn[2]
    add al,ncn[3]
    add al,ncn[4]
    .if al != 16
    jmp quitme
    .endif
    mov al,ncn[4]
    add al,ncn[5]
    add al,ncn[6]
    .if al != 16
    jmp quitme
    .endif
    mov al,ncn[6]
    add al,ncn[7]
    add al,ncn[8]
    .if al != 16
    jmp quitme
    .endif
    mov al,ncn[8]
    add al,ncn[9]
    add al,ncn[0]
    .if al != 16
    jmp quitme
    .endif

    lea edi,fbuf
    mov ebx,FC
    lea ebx,[ebx*8]
    add ebx,FC
    add ebx,FC
    mov eax,dword ptr ncn[0]
    mov dword ptr [edi+ebx],eax
    mov eax,dword ptr ncn[4]
    mov dword ptr [edi+ebx+4],eax
    mov ax,word ptr ncn[8]
    mov word ptr [edi+ebx+8],ax inc FC
    quitme:
    retcalcncn2 endp
    ;~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
    ;Inc ncn ,Return 1 == OK,0 == err,-1 == overflow:means all over ^0^
    incncn proc
    local tmpRT
    local i
    ;align 4 ;push eax
    ;push ecx
    ;push ebx mov tmpRT,0
    xor ecx,ecx
    xor eax,eax
    xor ebx,ebx
    .while ecx<10 ;ecx<10

    mov al,ncn[ecx]
    t0:
    inc al
    .if al>10 ;al>10
    inc ecx
    .continue
    .else
    push ecx
    inc ecx
    mov nbn,0
    .while ecx<10 ;ecx<10
    mov bl,ncn[ecx]
    .if bl == al
    pop ecx
    jmp t0
    .else
    bts nbn,bx
    inc ecx
    .endif
    .endw
    pop ecx
    mov ncn[ecx],al
    bts nbn,ax
    dec ecx
    .while ecx != 0ffffffffh
    mov ax,1
    .while ax<=10 ;ax<=10
    bt nbn,ax
    .if CARRY?
    inc ax
    .continue
    .else
    mov ncn[ecx],al
    bts nbn,ax
    .break
    .endif
    .endw
    dec ecx
    .endw
    mov tmpRT,1
    jmp quitme
    .endif

    .endw
    mov tmpRT,-1
    quitme:
    ;pop ebx
    ;pop ecx
    ;pop eax
    mov eax,tmpRT
    retincncn endp;~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
    ;Init ncn
    initncn proc push eax
    mov eax,01020304h
    mov dword ptr ncn[6],eax
    mov eax,05060708h
    mov dword ptr ncn[2],eax
    mov ax,090ah
    mov word ptr ncn[0],ax
    pop eax
    retinitncn endp
    ;~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
    start:
    invoke GetModuleHandle,NULL
    mov hInstance,eax
    invoke SetConsoleTitleA,addr cpc
    invoke GetStdHandle,STD_INPUT_HANDLE
    mov hstdin,eax
    invoke GetStdHandle,STD_OUTPUT_HANDLE
    mov hstdout,eax
    invoke initncn
    mov FC,0
    mov TTs,1
    invoke GetTickCount
    mov tmptime,eax
    .repeat
    invoke calcncn
    invoke incncn
    inc TTs
    .until eax == -1
    dec TTs
    invoke GetTickCount
    sub eax,tmptime

    invoke wsprintf,addr buf,addr ft,eax,TTs,FC
    invoke MessageBox,NULL,addr buf,addr cp,MB_OK ;invoke ShowLastW
    invoke ShowLastC

    invoke CloseHandle,hstdin
    invoke CloseHandle,hstdout
    invoke ExitProcess,NULL
    ;~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
    end start
      

  7.   

    解释如下:a 大家不要看代码长,其实我在计算匹配和显示输出时都分别写了两种算法。
      显示一个是 console 显示,一个是 gui32 显示。b 控制台显示结果如下:A 5 1 8 7 6 3 9 4 2
    9 4 3 6 7 8 1 A 5 2
    5 A 1 8 7 6 3 4 9 2
    4 9 3 6 7 8 1 5 A 2
    9 2 5 A 1 8 7 6 3 4
    3 6 7 8 1 A 5 2 9 4
    A 2 4 9 3 6 7 8 1 5
    1 8 7 6 3 9 4 2 A 5
    7 8 1 A 5 2 9 4 3 6
    7 8 1 5 A 2 4 9 3 6
    3 9 4 2 A 5 1 8 7 6
    3 4 9 2 5 A 1 8 7 6
    7 6 3 9 4 2 A 5 1 8
    7 6 3 4 9 2 5 A 1 8
    1 A 5 2 9 4 3 6 7 8
    1 5 A 2 4 9 3 6 7 8
    4 2 A 5 1 8 7 6 3 9
    3 6 7 8 1 5 A 2 4 9
    5 2 9 4 3 6 7 8 1 A
    1 8 7 6 3 4 9 2 5 APress Any Key To Exit...
      

  8.   


    A 代表 10计算总耗时 : 1938(ms) ,共枚举 3628800 次,共找到 20 个符合条件的组合。