• <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>

            我希望你是我獨家記憶

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

            ZJU--2039--二部圖

            Posted on 2008-08-01 21:21 Hero 閱讀(134) 評論(0)  編輯 收藏 引用 所屬分類: 代碼如詩--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 ;//定義隊列
                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 ;
                            }
                        }
            //構造二部圖的link[][]

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

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

                
            return 0 ;
            }
            伊人久久大香线焦AV综合影院| 久久久久亚洲AV成人网人人网站| 一本久道久久综合狠狠躁AV| 热99RE久久精品这里都是精品免费| A级毛片无码久久精品免费| 伊人久久大香线蕉av一区| 丁香五月网久久综合| 色婷婷噜噜久久国产精品12p| 亚洲国产精品无码久久| 久久国产香蕉一区精品| 日韩人妻无码精品久久免费一| 四虎国产精品免费久久久| 精品无码久久久久国产动漫3d| 精品久久人人做人人爽综合| 久久成人国产精品| 伊人情人综合成人久久网小说| 好属妞这里只有精品久久| 久久中文字幕人妻丝袜| 精品久久国产一区二区三区香蕉| 久久精品中文騷妇女内射| 国产精品久久久久久久app | 亚洲精品无码久久久影院相关影片| 国产午夜精品理论片久久影视| 精产国品久久一二三产区区别| 精品久久久久久久国产潘金莲| 狠狠综合久久综合88亚洲| 日韩精品无码久久一区二区三| 91久久婷婷国产综合精品青草| 久久精品国产亚洲av麻豆蜜芽 | 漂亮人妻被黑人久久精品| 狠狠综合久久综合88亚洲| 欧美午夜精品久久久久久浪潮| 狠狠色综合网站久久久久久久| 久久久久免费精品国产| 久久AV高清无码| 久久中文字幕一区二区| 国产91色综合久久免费分享| 久久精品国产福利国产秒| 国产精品无码久久四虎| 亚洲欧美另类日本久久国产真实乱对白 | 久久噜噜久久久精品66|