{"id":1199,"date":"2014-08-12T12:17:07","date_gmt":"2014-08-12T04:17:07","guid":{"rendered":"http:\/\/www.hsyyf.me\/?p=1199"},"modified":"2014-08-12T12:17:07","modified_gmt":"2014-08-12T04:17:07","slug":"%e6%a8%a1%e6%8b%9f%e6%b1%82%e9%80%be%e6%b8%97%e7%90%86%e8%ae%ba%e7%9a%84%e9%98%88%e5%80%bc","status":"publish","type":"post","link":"https:\/\/www.hsyyf.me\/?p=1199","title":{"rendered":"\u6a21\u62df\u6c42\u903e\u6e17\u7406\u8bba\u7684\u9608\u503c"},"content":{"rendered":"<p>\u903e\u6e17\u7406\u8bba\u4f5c\u4e3a\u4e00\u4e2a\u7ecf\u5178\u7684\u7406\u8bba\uff0c\u5728\u5b8f\u89c2\u3001\u5fae\u89c2\u9886\u57df\u90fd\u6709\u6781\u5176\u91cd\u8981\u7684\u5e94\u7528\uff0c\u5982\u91cd\u6574\u5316\u7fa4\u3001\u7535\u963b\u7f51\u7edc\u3001\u76f8\u53d8\u7b49\u7b49\u3002\u4e8c\u7ef4\u683c\u5b50\u662f\u903e\u6e17\u7406\u8bba\u6700\u57fa\u672c\u7684\u4e00\u79cd\u6a21\u578b\uff0c\u5176\u4e2d\u903e\u6e17\u9608\u503c\u5219\u662f\u5176\u4e2d\u5c24\u4e3a\u91cd\u8981\u7684\u4e00\u4e2a\u6982\u5ff5\u3002<\/p>\n<p>\u903e\u6e17\u6a21\u62df\u6700\u5927\u7684\u96be\u70b9\u5728\u4e8e\u56e2\u7c07\u5206\u7ec4\uff0c\u673a\u5668\u4e0d\u6bd4\u4eba\uff0c\u5bfb\u5e38\u9012\u5f52\u5206\u7ec4\u8fc7\u4e8e\u7e41\u7410\uff0c\u6211\u8fd9\u7528\u7684\u662f\u6700\u7b28\u7684\u4e8c\u6b21\u5206\u7ec4\u6cd5\u3002<\/p>\n<p>1\uff0c\u4ece\u5de6\u4e0a\u89d2\u5f00\u59cb\u5411\u53f3\u8d70\uff0c\u82e5\u6709\u683c\u70b9\uff0c\u5411\u5de6\u548c\u5411\u4e0a\u770b\u6700\u8fd1\u4e34\u70b9\uff0c\u5982\u679c\u6709\u4e00\u4e2a\u70b9\u683c\u70b9\uff0c\u5206\u4e3a\u6539\u4e3a\u6539\u7ec4\u7ec4\u53f7\uff0c\u4e8c\u8005\u90fd\u6709\u683c\u70b9\uff0c\u9009\u62e9\u8f83\u5c0f\u8005\u3002<\/p>\n<p>2\uff0c\u4f9d\u6b21\u8d70\u904d\u6bcf\u4e00\u884c\u3002<\/p>\n<p>3\uff0c\u8d70\u5b8c\u4e00\u904d\u4e4b\u540e\uff0c\u518d\u4ece\u5de6\u4e0a\u89d2\u8d70\uff0c\u8fd9\u6b21\u770b\u76f8\u4e0b\u548c\u76f8\u53f3\u7684\u683c\u70b9\uff0c\u9047\u5230\u6bd4\u81ea\u5df1\u7ec4\u53f7\u5c0f\u7684\uff0c\u5219\u628a\u81ea\u5df1\u7ec4\u6240\u6709\u7684\u6210\u5458\u7684\u7ec4\u53f7\u53d8\u6210\u5c0f\u53f7\u3002<\/p>\n<p>4\uff0c\u4f9d\u6b21\u8d70\u5b8c\u6bcf\u4e00\u884c\u3002<\/p>\n<p>\u7814\u7a76\u5b8c\u5206\u7ec4\u7684\u7b97\u6cd5\uff0c\u518d\u6765\u770b\u903e\u6e17\u9608\u503c\u7684\u7b97\u6cd5\u5c31\u7b80\u5355\u591a\u4e86\u3002<\/p>\n<p>1\uff0c\u5728\u65b9\u683c\u5185\u4ee5\u67d0\u4e2a\u8f83\u5c0f\u7684\u6982\u7387\u503c\u5f00\u59cb\u6492\u70b9<\/p>\n<p>2\uff0c\u5bf9\u6492\u7684\u70b9\u8fdb\u884c\u5206\u7ec4<\/p>\n<p>3\uff0c\u5224\u65ad\u662f\u5426\u4e0a\u4e0b\u8d2f\u901a\uff0c\u5982\u679c\u8d2f\u901a\uff0c\u5219\u6c42\u51fa\u683c\u70b9\u5bc6\u5ea6\uff08\u6982\u7387\u503c\u3001\u9608\u503c\uff09\uff0c\u5982\u679c\u672a\u8d2f\u901a\uff0c\u589e\u52a0\u6982\u7387\u503c\uff0c\u91cd\u65b0\u6563\u70b9\uff0c\u8c03\u56de\u7b2c\u4e8c\u6b65<\/p>\n<p>4\uff0c\u591a\u6b21\u5faa\u73af1~3\u6b65\uff0c\u6c42\u51fa\u5e73\u5747\u503c<\/p>\n<p>5\uff0c\u6269\u5927\u65b9\u683c\uff0c\u5faa\u73af1~4\u6b65\uff0c\u7edf\u8ba1\u65b9\u683c\u548c\u9608\u503c\u5173\u7cfb<\/p>\n<p>\u8fd9\u4e2a\u9898\u76ee\u7684\u8ba1\u7b97\u91cf\u8d85\u5927\uff0c\u65b9\u683c\u8fb9\u957f\u4ece2~256\uff0c\u7edf\u8ba110\u6b21\u6c42\u5e73\u5747\uff0c\u5927\u6982\u9700\u8981\u534a\u4e2a\u5c0f\u65f6\u5de6\u53f3\u3002\u673a\u5668\u6027\u80fd\u582a\u5fe7\u7684\u540c\u5b66\u8c28\u614e\u8fd0\u884c\u3002<\/p>\n<p><code lang=\"Fortran\">program main<br \/>\n    implicit none<br \/>\n    integer,parameter   :: s=4,e=256<br \/>\n    integer :: i,N,j,k<br \/>\n    real(8)    :: cal,avg<br \/>\n    open(10,file='data.dat')<br \/>\n    open(100,file='pc.dat')<br \/>\n    k=0<br \/>\n    do i=2,7<br \/>\n        N=2**i<br \/>\n        avg=0.0d0<br \/>\n        do j=1,10<br \/>\n            avg=avg+cal(N)<br \/>\n            write(100,*) k,cal(N)<br \/>\n            k=k+1<br \/>\n            print*,N,j<br \/>\n        enddo<br \/>\n        write(10,*)N,avg\/10.d0<br \/>\n    enddo<br \/>\nend program main<\/p>\n<p>real(8) function cal(l)<br \/>\n    integer :: l,switch,i,j<br \/>\n    integer :: Space(l,l),Group(l,l)<br \/>\n    real(8)    :: pc,dpc<br \/>\n    pc=0.5d0<br \/>\n    dpc=0.005d0<br \/>\n    !\u8d4b\u521d\u503c<br \/>\n    do i=1,l<br \/>\n        do j=1,l<br \/>\n            Space(i,j)=0<br \/>\n            Group(i,j)=0<br \/>\n        enddo<br \/>\n    enddo<br \/>\n    call D(Space,Group,l,pc)<\/p>\n<p>    do while(switch(Group,l)==0)  !\u5224\u65ad\u662f\u4e0d\u662f\u8d2f\u901a\uff0c\u4e0d\u662f\u7684\u8bddpc+dpc<br \/>\n        pc=pc+dpc<br \/>\n        call D(Space,Group,l,pc)<br \/>\n    enddo<br \/>\n    !cal=1.0*sum(SPace)\/l**2.0<br \/>\n    cal=pc<br \/>\nend<\/p>\n<p>subroutine D(Space,Group,l,pc)<br \/>\n    integer ::l,i,j,g,g1,g2,nn,xi,yi<br \/>\n    integer ::Space(l,l),Group(l,l)<br \/>\n    real(8)    ::pc,x,y ,r<br \/>\n    call RANDOM_SEED()<\/p>\n<p>    nn=int(1.0*l**2.0*pc)+1<br \/>\n     i=0<br \/>\n     do<br \/>\n        call random_number(x)<br \/>\n        xi=int(l*x)+1<br \/>\n        call random_number(y)<br \/>\n        yi=int(l*y)+1<br \/>\n        if (space(xi,yi)==0)then<br \/>\n            Space(xi,yi)=1<br \/>\n        endif<br \/>\n       if (sum(space)>nn) exit<br \/>\n   enddo<\/p>\n<p>    g=0<br \/>\n    !\u7b2c\u4e00\u6b21\u5206\u7ec4<br \/>\n    do i=1,l<br \/>\n        do j=1,l<br \/>\n            if (i==1 .and. j==1 .and. space(i,j)==1) then<br \/>\n                g=g+1<br \/>\n                group(i,j)=1<br \/>\n            endif<\/p>\n<p>            if (i==1 .and. j\/=1 .and. space(i,j)==1) then<br \/>\n                if (space(i,j-1)==1) then<br \/>\n                    group(i,j)=group(i,j-1)<br \/>\n                else<br \/>\n                    g=g+1<br \/>\n                    group(i,j)=g<br \/>\n                endif<br \/>\n            endif<\/p>\n<p>            if (i\/=1 .and. space(i,j)==1) then<br \/>\n                if (j==1) then<br \/>\n                    if (group(i-1,j)==0) then<br \/>\n                        g=g+1<br \/>\n                        group(i,j)=g<br \/>\n                    else<br \/>\n                        group(i,j)=group(i,j)<br \/>\n                    endif<br \/>\n                else<br \/>\n                    if (group(i-1,j)==0 .and. group(i,j-1)==0)then<br \/>\n                        g=g+1<br \/>\n                        group(i,j)=g<br \/>\n                    else<br \/>\n                        if (group(i-1,j)*group(i,j-1)\/=0) then<br \/>\n                            group(i,j)=min(group(i-1,j),group(i,j-1))<\/p>\n<p>                        else<br \/>\n                            group(i,j)=group(i-1,j)+group(i,j-1)<br \/>\n                        endif<br \/>\n                    endif<br \/>\n                endif<br \/>\n            endif<br \/>\n        enddo<br \/>\n    enddo<br \/>\n    !\u7b2c\u4e8c\u6b21\u4fee\u6b63<br \/>\n    do i=1,l<br \/>\n        do j=1,l<br \/>\n            if (i==l .and. j==l) exit<br \/>\n            if (i==l .and. group(i,j)\/=0) then<br \/>\n                if (group(i,j+1)\/=0) then<br \/>\n                    if (group(i,j)<group(i,j+1)) then\n                        g1=group(i,j)\n                        g2=group(i,j+1)\n                        call Change(Group,l,g1,g2)\n                    else\n                        g1=group(i,j+1)\n                        g2=group(i,j)\n                        call Change(Group,l,g1,g2)\n                    endif\n                endif\n            endif\n\n            if (j==l .and. group(i,j)\/=0) then\n                if (group(i+1,j)\/=0) then\n                    if (group(i,j)<group(i+1,j))then\n                        g1=group(i,j)\n                        g2=group(i+1,j)\n                        call Change(Group,l,g1,g2)\n                    else\n                        g1=group(i+1,j)\n                        g2=group(i,j)\n                        call Change(Group,l,g1,g2)\n                    endif\n                endif\n            endif\n\n            if (i\/=l .and. j\/=l .and. group(i,j)\/=0) then\n                if (group(i+1,j)*group(i,j+1)\/=0)then\n                    g1=min(group(i,j+1),group(i,j))\n                    g1=min(g1,group(i+1,j))\n                    g2=max(group(i,j+1),group(i,j))\n                    g2=max(g2,group(i+1,j))\n                    call Change(Group,l,g1,g2)\n                else\n                    if (group(i+1,j)\/=0) then\n                        if (group(i,j)<group(i+1,j)) then\n                            g1=group(i,j)\n                            g2=group(i+1,j)\n                            call Change(Group,l,g1,g2)\n                        else\n                            g1=group(i+1,j)\n                            g2=group(i,j)\n                            call Change(Group,l,g1,g2)\n                        endif\n                    endif\n                    if (group(i,j+1)\/=0) then\n                        if (group(i,j)<group(i,j+1))then\n                            g1=group(i,j)\n                            g2=group(i,j+1)\n                            call Change(Group,l,g1,g2)\n                        else\n                            g1=group(i,j+1)\n                            g2=group(i,j)\n                            call Change(Group,l,g1,g2)\n                        endif\n                    endif\n                endif\n            endif\n        enddo\n    enddo\nend\n\nsubroutine Change(Group,l,g1,g2)\n    integer :: l,group(l,l),g1,g2\n    integer :: i,j\n    do i=1,l\n        do j=1,l\n            if (group(i,j)==g2) group(i,j)=g1\n        enddo\n    enddo\nend\n\ninteger function switch(Group,l)\n    integer :: l\n    integer :: Group(l,l),flag,i\n    flag=0\n    do i=1,l\n        if (Group(1,i)\/=0) then\n            do j=1,l\n                if (Group(1,i)==Group(l,j)) then\n                    flag=1\n                    exit\n                endif\n            enddo\n        endif\n        if (flag==1)    exit\n    enddo\n    switch=flag\nend<\/code><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u903e\u6e17\u7406\u8bba\u4f5c\u4e3a\u4e00\u4e2a\u7ecf\u5178\u7684\u7406\u8bba\uff0c\u5728\u5b8f\u89c2\u3001\u5fae\u89c2\u9886\u57df\u90fd\u6709\u6781\u5176\u91cd\u8981\u7684\u5e94\u7528\uff0c\u5982\u91cd\u6574\u5316\u7fa4\u3001\u7535\u963b\u7f51\u7edc\u3001\u76f8\u53d8\u7b49\u7b49\u3002\u4e8c\u7ef4\u683c\u5b50\u662f\u903e\u6e17 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[16],"tags":[108,163,164],"class_list":["post-1199","post","type-post","status-publish","format-standard","hentry","category-16","tag-fortran","tag-163","tag-164"],"_links":{"self":[{"href":"https:\/\/www.hsyyf.me\/index.php?rest_route=\/wp\/v2\/posts\/1199","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hsyyf.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hsyyf.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hsyyf.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hsyyf.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1199"}],"version-history":[{"count":0,"href":"https:\/\/www.hsyyf.me\/index.php?rest_route=\/wp\/v2\/posts\/1199\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.hsyyf.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1199"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hsyyf.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1199"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hsyyf.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1199"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}