UVA 12549Sentry Robots

Source: Internet
Author: User

This problem is quite like hdu 5093 Battle ships, but that question is required to place the most points, and this problem is required minimum coverage.

An important position has (x, y) two coordinates, and to hold this position is equivalent to a side x to Y edge.

Selecting one (x, y) is equivalent to selecting all sides of the same x or all the same y edges.

When all x or Y is selected, the guard is completed. The equivalent is cut x and Y, so is the minimum cut, for a capacity of 1 models can be used in the Hungarian algorithm.

If you have an obstacle, just consider the separate side of the barrier and take a break.

The array is bigger, don't re.

#include <bits/stdc++.h>using namespacestd;Const intN =5002;Const intMAXN =101;CharG[MAXN][MAXN];intyid[maxn][maxn],y_cnt;intMatch[n];intDfst[n],dfstime;vector<int>G[n];#definePB push_backBOOLDfsintu) {     for(inti =0; I < g[u].size (); i++){        intv =G[u][i]; if(Dfst[v]! =dfstime) {Dfst[v]=Dfstime; if(!~match[v] | |DFS (Match[v])) {Match[v]= u;return true; }        }    }    return false;}intMaxmatch () {intRET =0; memset (Match,-1,sizeof(match)); memset (DFST,0,sizeof(DFST)); Dfstime=0;  for(inti =0; i < y_cnt; i++) {Dfstime++; if(Dfs (i)) ret++; }    returnret;}intMain () {//freopen ("In.txt", "R", stdin);    intC scanf"%d",&b);  while(c--){        intY, X, P; scanf"%d%d%d",&y,&x,&P); Memset (g,0,sizeof(g));  while(p--) {            intR,C;SCANF ("%d%d",&r,&c); G[R][C]='*'; } scanf ("%d",&q);  while(p--){            intR,C;SCANF ("%d%d",&r,&c); G[R][C]='#'; } y_cnt=0;  for(inti =1; I <= y;i++){            BOOLFlag =false;  for(intj =1; J <= X; J + +){                if(G[i][j] = ='*') flag =true, yid[i][j] =y_cnt; Else if(G[i][j] = ='#'&& flag) y_cnt++; }            if(flag) y_cnt++; }         for(inti =0; i < y_cnt; i++) g[i].clear (); intx_cnt =0;  for(intj =1; J <= X; J + +){            BOOLFlag =false;  for(inti =1; I <= Y; i++){                if(G[i][j] = ='*') {flag=true; G[YID[I][J]].                PB (X_CNT); }Else if(G[i][j] = ='#'&&flag) {x_cnt++; }            }            if(flag) x_cnt++; } printf ("%d\n", Maxmatch ()); }    return 0;}

UVA 12549Sentry Robots

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.