• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            我希望你是我獨(dú)家記憶

            一段永遠(yuǎn)封存的記憶,隨風(fēng)而去
            posts - 263, comments - 31, trackbacks - 0, articles - 3
               :: 首頁 :: 新隨筆 ::  :: 聚合  :: 管理

            ZJU--2039--二部圖

            Posted on 2008-08-01 21:21 Hero 閱讀(132) 評(píng)論(0)  編輯 收藏 引用 所屬分類: 代碼如詩(shī)--ACM
            /* Accepted 2039 C++ 00:00.02 416K */
            //還是二部圖

            #include 
            <stdio.h>
            #include 
            <stdlib.h>
            #include 
            <string.h>
            #include 
            <ctype.h>
            #include 
            <math.h>
            #define llong unsigned long long 
            #define unint unsigned int
            #define printline  printf( "\n" ) 

            const int INF = 1000000 ;
            const int size = 110 ;

            struct NODE {
                
            int x ;
                
            int y ;
            };
            struct NODE pnode[size] ;
            struct NODE dnode[size] ;

            int testnum, ct ;
            int inp, ind ;
            bool link[size][size] ;

            int Binmatch( int inn, int inm )
            {
                
            int matchnum = 0 ; int dn_node ;
                
            int queue[size*10] ; int head=0, tail = 0 ;//定義隊(duì)列
                int upmatch[size], dnmatch[size] ; int prev[size] ;
                memset( upmatch, 
            -1sizeof(upmatch) ) ;
                memset( dnmatch, 
            -1sizeof(dnmatch) ) ;

                
            forint i=1; i<=inn; i++ ) {
                    
            forint j=1; j<=inm; j++ )    prev[j] = -2 ;
                    head 
            = tail = 0 ;

                    
            forint j=1; j<=inm; j++ )    if( link[i][j] )
                    { prev[j] 
            = -1 ; queue[tail++= j ; }

                    
            while( head < tail ) {
                        dn_node 
            = queue[head] ;
                        
            if-1 == dnmatch[dn_node] )    break ;
                        head
            ++ ;
                        
            forint j=1; j<=inm; j++ ) if-2==prev[j]&&link[dnmatch[dn_node]][j] )
                        { prev[j] 
            = dn_node ; queue[tail++= j ; }
                    }

                    
            if( head == tail )    continue ;
                    
            while( prev[dn_node] > -1 ) {
                        upmatch[dnmatch[prev[dn_node]]] 
            = dn_node ;
                        dnmatch[dn_node] 
            = dnmatch[prev[dn_node]] ;
                        dn_node 
            = prev[dn_node] ;
                    }

                    dnmatch[dn_node] 
            = i ; upmatch[i] = dn_node ;
                    matchnum
            ++ ;
                }

                printf( 
            "%d\n", matchnum+inp ) ;
                
                
            forint i=1; i<inp; i++ ) {

                    printf( 
            "%d %d ", pnode[i].x, pnode[i].y ) ;
                    
            if( upmatch[i] != -1 ) 
                        printf( 
            "%d %d ", dnode[upmatch[i]].x, dnode[upmatch[i]].y ) ;
                }
                printf( 
            "%d %d\n",pnode[inp].x, pnode[inp].y ) ;

                
            return matchnum ;
            }

            double fdist( int x1, int y1, int x2, int y2 )
            {
                
            return sqrt( 1.0*(x1-x2)*(x1-x2) + 1.0*(y1-y2)*(y1-y2) ) ;
            }

            int main()
            {
                
            //freopen( "frac1.in", "r", stdin ) ;
                
            //freopen( "frac1.out","w",stdout ) ;

                
            while( scanf( "%d",&testnum ) != EOF )
                
            //scanf( "%d",&testnum ) ;
                {
                    
            forint ct=1; ct<=testnum; ct++ )
                    {
                        memset( link, 
            falsesizeof(link) ) ;
                        scanf( 
            "%d %d",&inp, &ind ) ;

                        
            forint i=1; i<=inp; i++ )
                            scanf( 
            "%d %d",&pnode[i].x, &pnode[i].y ) ;

                        
            forint i=1; i<=ind; i++ )
                            scanf( 
            "%d %d",&dnode[i].x, &dnode[i].y ) ;

                        
            forint i=1; i<inp; i++ ) {
                            
            double plen = fdist( pnode[i].x, pnode[i].y, pnode[i+1].x, pnode[i+1].y ) ;
                            
            forint j=1; j<=ind; j++ ) {
                                
            double dlen = fdist( pnode[i].x, pnode[i].y, dnode[j].x, dnode[j].y ) +
                                           fdist( pnode[i
            +1].x, pnode[i+1].y, dnode[j].x, dnode[j].y ) ;
                                
            if2*plen - dlen >= 0 )    link[i][j] = true ;
                            }
                        }
            //構(gòu)造二部圖的link[][]

                        
            int matchnum = Binmatch( inp-1, ind ) ;

                        
            if( testnum != ct )    printf( "\n" ) ;
                    }
                }
            //while

                
            return 0 ;
            }
            婷婷久久五月天| 久久婷婷五月综合色99啪ak| 久久人妻无码中文字幕| 亚洲国产精品无码久久青草| 久久精品成人免费国产片小草 | 国产精品美女久久久久AV福利| 久久九九青青国产精品| 99久久精品国产一区二区三区 | 伊人热热久久原色播放www| 色综合久久久久久久久五月| 久久免费视频网站| 午夜精品久久久久久久久| 欧美综合天天夜夜久久| 亚洲精品国产第一综合99久久| 久久精品欧美日韩精品| 亚洲国产精品成人久久蜜臀 | 国产Av激情久久无码天堂| 久久久久亚洲爆乳少妇无| 国内精品久久久人妻中文字幕| 久久久久亚洲?V成人无码| 久久精品aⅴ无码中文字字幕重口 久久精品a亚洲国产v高清不卡 | 国产日韩久久免费影院| 婷婷五月深深久久精品| 久久久久人妻一区精品果冻| 国产精品久久成人影院| 亚洲精品乱码久久久久久久久久久久 | 亚洲国产欧洲综合997久久| 久久综合亚洲色HEZYO国产 | 色综合合久久天天给综看| jizzjizz国产精品久久| 色8久久人人97超碰香蕉987| 热久久视久久精品18| 亚洲а∨天堂久久精品9966| 九九久久精品无码专区| 91精品观看91久久久久久| 精品永久久福利一区二区| 久久人妻AV中文字幕| 久久AV高潮AV无码AV| 99蜜桃臀久久久欧美精品网站| 久久无码专区国产精品发布| 亚洲天堂久久久|