• hdu4185 Oil Skimming


                              Oil Skimming

                                          Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
                                         Total Submission(s): 648    Accepted Submission(s): 288


    Problem Description
    Thanks to a certain "green" resources company, there is a new profitable industry of oil skimming. There are large slicks of crude oil floating in the Gulf of Mexico just waiting to be scooped up by enterprising oil barons. One such oil baron has a special plane that can skim the surface of the water collecting oil on the water's surface. However, each scoop covers a 10m by 20m rectangle (going either east/west or north/south). It also requires that the rectangle be completely covered in oil, otherwise the product is contaminated by pure ocean water and thus unprofitable! Given a map of an oil slick, the oil baron would like you to compute the maximum number of scoops that may be extracted. The map is an NxN grid where each cell represents a 10m square of water, and each cell is marked as either being covered in oil or pure water.
     
    Input
    The input starts with an integer K (1 <= K <= 100) indicating the number of cases. Each case starts with an integer N (1 <= N <= 600) indicating the size of the square grid. Each of the following N lines contains N characters that represent the cells of a row in the grid. A character of '#' represents an oily cell, and a character of '.' represents a pure water cell.
     
    Output
    For each case, one line should be produced, formatted exactly as follows: "Case X: M" where X is the case number (starting from 1) and M is the maximum number of scoops of oil that may be extracted.
     
    Sample Input
    1 6 ...... .##... .##... ....#. ....## ......
     
    Sample Output
    Case 1: 3
     
    Source
    // 题目要求用(1,2)的矩形去覆盖一个大矩形用有#的部分
    // 我们可以把这个转化为二分图匹配求解(因为用的是(1,2)的矩形)
    // 把有#的看成一个点周围有#的就连无向边,然后让它自己与自己匹配
    // 最后的最大匹配数 / 2 就是答案(因为是无向边)
    
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    using namespace std ;
    
    #define maxn 604
    char map[maxn][maxn] ;
    int map1[maxn][maxn] ;
    int len ,top , mark[maxn*maxn] ;
    int head[maxn*maxn] , next1[maxn*maxn] , to[maxn*maxn] ;
    bool vi[maxn*maxn] ;
    void Unit( int u , int v )
    {
        next1[top] = head[u] ; to[top] = v ;
        head[u] = top++ ;
        next1[top] = head[v] ; to[top] = u ;
        head[v] = top++ ;
    }
    bool find( int u )
    {
        int v , i , m ;
        for( i = head[u] ; i != -1 ;i = next1[i])
        {
            v = to[i] ;
            if(!vi[v]){
            vi[v] = 1 ;
            if( mark[v] == -1 || find(mark[v]))
            {
                mark[v] = u ;
                return 1 ;
            }
            }
        }
        return 0 ;
    }
    int main()
    {
        int i , j, n , T , m , case1 = 0 ;
        int  u , v , k ,ok  ;
         cin >> T ;
        while( T-- )
        {
            scanf("%d" , &n ) ;
            len = top = 0 ;
            for( i = 0 ; i < n ;i++ )
                scanf("%s" , map[i] ) ;
            memset(head,-1,sizeof(head)) ;
            memset(map1,0,sizeof(map1)) ;
    
            for( i = 0 ;  i < n ;i++ )
                for( j = 0 ; j < n ;j++ )
                    if(map[i][j] == '#')
                        map1[i][j] = ++len ;
            for( i = 0 ;  i < n ;i++ )
                for( j = 0 ; j < n ;j++ )
                    if(map[i][j] == '#')
                {    
                     u = map1[i][j] ;
                    if( j != n-1&&map[i][j+1] == '#')
                    {
                        v = map1[i][j+1] ; 
                        Unit(u,v) ;
                    }
                    if( i != n-1 && map[i+1][j] == '#')
                    {
                        v = map1[1+i][j] ; 
                        Unit(u,v) ;
                    }
                }
               int ans = 0 ;
               memset(mark,-1,sizeof(mark)) ;
               for( i = 1 ; i <= len ;i++ )
               {
                   memset(vi,0,sizeof(vi)) ;
                   if(find(i))
                       ans++ ;
               }
               printf("Case %d: " , ++case1 ) ;
               cout << ans/2 << endl ;
        }
    }
    
  • 相关阅读:
    LRU Algorithm Gym
    Running Routes Kattis
    Box HDU
    manjaro 安装 tim 后无法输入中文
    Angle Beats Gym
    Fish eating fruit 沈阳网络赛(树形dp)
    请求接口模板
    Droppable 拖拽实例
    线程处理
    网站的配置文件XML读写
  • 原文地址:https://www.cnblogs.com/20120125llcai/p/3352837.html
Copyright © 2020-2023  润新知