HDOJ 1045 – Fire Net 水二分圖..奇葩構圖…

來源:互聯網
上載者:User

                 題意:

                           給個地圖(最大4*4)..問能放多少個O...每個O是不能上下左右能看到的.(跟象棋的車一樣...)..問最多能放多少個...

                 題解:

                           水題找手感...我的奇葩構圖....對於當前(x,y)..若x左邊有n1個牆...y上邊有n2個牆..那麼其映射的座標為(x+10*n1,y+10*n2)....好吧...

Program:

#include<iostream>#include<stdio.h>#include<algorithm>#include<cmath>#include<stack>#include<queue>#define ll long long#define MAXN 105using namespace std;int n,match[MAXN];bool arc[MAXN][MAXN],used[MAXN];char s[MAXN][MAXN];bool dfs(int x){       int i;       for (i=1;i<=n;i++)          if (arc[x][i] && !used[i])          {                 used[i]=true;                 if (!match[i] || dfs(match[i]))                 {                       match[i]=x;                       return true;                 }          }              return false; }int getmax(){       int sum=0;       memset(match,0,sizeof(match));       for (int i=1;i<=n;i++)       {               memset(used,false,sizeof(used));               sum+=dfs(i);       }       return sum;}int main(){       int i,j,k,ans;       freopen("input.txt","r",stdin);       freopen("output.txt","w",stdout);        while (~scanf("%d",&n) && n)       {               memset(arc,false,sizeof(arc));               for (i=1;i<=n;i++) scanf("%s",s[i]+1);               memset(arc,false,sizeof(arc));               for (i=1;i<=n;i++)                  for (j=1;j<=n;j++)                  if (s[i][j]=='.')                  {                        int t1=i,t2=j;                        for (k=1;k<j;k++)                           if (s[i][k]=='X') t1+=10;                        for (k=1;k<i;k++)                           if (s[k][j]=='X') t2+=10;                //        printf("-----%d %d-----\n",t1,t2);                        arc[t1][t2]=true;                  }               n=100;               printf("%d\n",getmax());       }       return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.