IRRIGATION LINES
Time Limit: 2000ms, Special Time Limit:5000ms, Memory Limit:65536KB
Total submit users: 6, Accepted users: 6
Problem 13449 : No special judgement
Problem description

A plantation consists of several rectangular fields, and a field is further subdivided into square zones. Under the multi-zone crop rotation, some zones are planted with crops, while some other zones are left fallow during a season. The zones of a field are rotated in this manner so that every few seasons, a zone would rest and be fallow. Crops of a season are selected based on their type, form, shape, and sun or shade requirements.

An irrigation system has been installed for each field. The system is constructed in a manner to simplify the operation and re-configuration of the system. The main water line runs around the field, which is depicted by the dark solid lines enclosing the field in the figure shown below. Dedicated control valves connect the mainline to the lateral (horizontal and vertical) irrigation lines that control the water flow to each of the rows and columns of zones. The valves are turned off if the irrigation line is not active. Only one lateral irrigation line is required to water a planting zone. The emitters or the holes on the active irrigation lines are closed over the zones that do not require to be watered. The layout of the planting field dictates the way the irrigation system is re-configured at the beginning of every season by turning off the valves of the inactive irrigation lines, and closing the unwanted emitters of the active lines.

To economise the management effort, the system needs to utilise a minimum number of lateral irrigation lines, i.e., lines that must be active. For example, the figure below shows a field divided into 4 x 4 zones. There are four zones that are planted with crops in the field marked by floral symbols, i.e., row 1 column 3, row 2 columns 2 and 4, and row 3 column 3. There are eight valves controlling the flow of water through their corresponding irrigation lines on the field. In the example, only the two lines whose valves have been turned on need to be activated to irrigate the crops on the planting zones. These active irrigation lines are outlined by solid lateral lines in the figure. The inactive lines whose valves have been turned off are not drawn to avoid clustering of the figure.

Write a program that reads layouts of planting fields and determines the minimum number of lateral irrigation lines that must be activated in these fields.

Input

The first line contains an integer T (T ≤ 100) denoting the number of cases. Each case describes a layout of a planting field, which starts on a new line with a pair of positive integers M and N (1 ≤ M, N ≤ 100), indicating the dimension of the field, i.e., the number of rows and columns of zones, respectively. The integers are separated by space. The next M lines of each test case delineate the layout of the field containing either a 1 or a 0, where 1 indicates the zone is planted and a 0 if it is fallow.

Output

For each case, output “Case #X: Y” (without quotes) in a line where X is the case number, starting from 1, followed by a single space, and Y is the minimum number of irrigation lines that must be active.

Sample Input
2
4 4
0010
0101
0010
0000
5 4
1001
0010
1100
1110
0101
Sample Output
Case #1: 2
Case #2: 4
Problem Source
ACM ICPC Asia Kuala Lumpur Regional Contest 2014

题目大意:给出n*m个区域,1代表这里有庄家,现在要灌溉庄稼,灌溉管道只能横着和竖着铺,输出最少的灌溉管道。YY

这个真是好题!用二分图的最大匹配解决。二分图的最小顶点覆盖=最大匹配数,以横坐标和纵坐标建图,横纵坐标的交点为1 代表有关连。

/* ***********************************************
Author :pk28
Created Time :2015/10/6 12:25:40
File Name :10.6hnul.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 10000+10
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std; bool cmp(int a,int b){
return a>b;
} struct node{
int v,next;
}edge[maxn];
int pre[maxn],l,vis[maxn],match[maxn];
int tot,n,m;
void init(){
l=;
memset(pre,-,sizeof pre);
memset(match,-,sizeof match);
}
void add(int u,int v){
edge[l].v=v;
edge[l].next=pre[u];
pre[u]=l++;
}
int dfs(int u){
for(int i=pre[u];i+;i=edge[i].next){
int v=edge[i].v;
if(!vis[v]){
vis[v]=;
if(match[v]==-||dfs(match[v])){
match[v]=u;
return ;
}
}
}
return ;
}
int hungary(){
tot=;
for(int i=;i<=max(n,m);i++){
cle(vis);
if(dfs(i))tot++;
}
return tot;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int t,a,cnt=;
cin>>t;
while(t--){
init();
cin>>n>>m;
getchar();
char s[];
for(int i=;i<=n;i++){
gets(s);
for(int j=;j<m;j++){
if(s[j]==''){
add(i,j+);
// add(j+1,i);
}
}
}
printf("Case #%d: %d\n",++cnt,hungary());
}
return ;
}

IRRIGATION LINES的更多相关文章

  1. ZOJ 2412 Farm Irrigation

    Farm Irrigation Time Limit: 2 Seconds      Memory Limit: 65536 KB Benny has a spacious farm land to ...

  2. hdu.1198.Farm Irrigation(dfs +放大建图)

    Farm Irrigation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. HDU1198水管并查集Farm Irrigation

    Benny has a spacious farm land to irrigate. The farm land is a rectangle, and is divided into a lot ...

  4. ZOJ 2412 Farm Irrigation(DFS 条件通讯块)

    意甲冠军  两个农田管内可直接连接到壳体  他们将能够共享一个水源   有11种农田  管道的位置高于一定  一个农田矩阵  问至少须要多少水源 DFS的连通块问题  两个相邻农田的管道能够直接连接的 ...

  5. HDU 1198 Farm Irrigation (并检查集合 和 dfs两种实现)

    Farm Irrigation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. 【简单并查集】Farm Irrigation

    Farm Irrigation Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Tot ...

  7. Farm Irrigation(非常有意思的并查集)

    Farm Irrigation Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Tot ...

  8. ZOJ2412 Farm Irrigation(农田灌溉) 搜索

    Farm Irrigation Time Limit: 2 Seconds      Memory Limit: 65536 KB Benny has a spacious farm land to ...

  9. HDUOJ--------(1198)Farm Irrigation

    Farm Irrigation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

随机推荐

  1. 刷题总结——营业额统计(bzoj1588)

    题目: Description 营业额统计 Tiger最近被公司升任为营业部经理,他上任后接受公司交给的第一项任务便是统计并分析公司成立以来的营业情况. Tiger拿出了公司的账本,账本上记录了公司成 ...

  2. 北京集训TEST13——PA(Goodness)

    题目: Description 桌面上放有 n 张卡牌.对于每张卡牌,一面是绿色的,另一面是红色的.卡牌的每一面都标有一个整数.对于卡牌a和卡牌b,卡牌a对卡牌b的好感度为卡牌a绿色面的数与卡牌b红色 ...

  3. 阐述struts2的执行流程。

    Struts 2框架本身大致可以分为3个部分:核心控制器FilterDispatcher.业务控制器Action和用户实现的企业业务逻辑组件. 核心控制器FilterDispatcher是Struts ...

  4. Mybatis 如何自动生成bean dao xml 配置文件 generatorconfig.xml (main()方法自动生成更快捷)

    最近项目要用到mybatis中间件,中间涉及到要对表结构生成bean,dao,和sqlconfig.xml 所以记录一下学习过程 首先是准备工作,即准备需要的jar包:我们的数据库mysql,所以驱动 ...

  5. hdu3315 /最大权最佳匹配(最大权下尽量不改变次序)(有权田忌赛马类问题)/费用流

    题意:2个人比赛,每场比赛有得分,每场每人派一支圣兽( brute ,字典翻译为畜生,感觉这里不太符╮(╯▽╰)╭),有攻击力和血条...一堆规则... 合理安排,让1号人获得最大分数,并尽量不要改变 ...

  6. 什么是 Linux

    什么是Linux Linux是一套免费使用和自由传播的类Unix操作系统,是一个基于POSIX和UNIX的多用户.多任务.支持多线程和多CPU的操作系统.它能运行主要的UNIX工具软件.应用程序和网络 ...

  7. BZOJ 4034 [HAOI2015]树上操作(树链剖分)

    题目链接  BZOJ4034 这道题树链剖分其实就可以了. 单点更新没问题. 相当于更新 [f[x], f[x]]这个区间. f[x]表示树链剖分之后每个点的新的标号. 区间更新的话类似DFS序,求出 ...

  8. P3378 堆【模板】 洛谷

    https://www.luogu.org/problem/show?pid=3378 题目描述 如题,初始小根堆为空,我们需要支持以下3种操作: 操作1: 1 x 表示将x插入到堆中 操作2: 2 ...

  9. 8.Java web—JSP基本语法

    1)脚本标识 <%-- <%@这两都之间不能为空格 ,但page前面可以任意空格 --%> <%@ page language="java" content ...

  10. Spring MVC集成Spring Data Reids和Spring Session实现Session共享出现:No bean named 'springSessionRepositoryFilter' available

    出现这个问题:No bean named 'springSessionRepositoryFilter' available的的原因: 1.Spring MVC加载了多个配置文件导致的,并不是版本问题 ...