zoukankan      html  css  js  c++  java
  • HDU1281--棋盘游戏

    棋盘游戏
    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 1615 Accepted Submission(s): 924


    Problem Description
    小希和Gardon在玩一个游戏:对一个N*M的棋盘,在格子里放尽量多的一些国际象棋里面的“车”,并且使得他们不能互相攻击,这当然很简单,但是Gardon限制了只有某些格子才可以放,小希还是很轻松的解决了这个问题(见下图)注意不能放车的地方不影响车的互相攻击。
    所以现在Gardon想让小希来解决一个更难的问题,在保证尽量多的“车”的前提下,棋盘里有些格子是可以避开的,也就是说,不在这些格子上放车,也可以保证尽量多的“车”被放下。但是某些格子若不放子,就无法保证放尽量多的“车”,这样的格子被称做重要点。Gardon想让小希算出有多少个这样的重要点,你能解决这个问题么?



    Input
    输入包含多组数据,
    第一行有三个数N、M、K(1<N,M<=100 1<K<=N*M),表示了棋盘的高、宽,以及可以放“车”的格子数目。接下来的K行描述了所有格子的信息:每行两个数X和Y,表示了这个格子在棋盘中的位置。


    Output
    对输入的每组数据,按照如下格式输出:
    Board T have C important blanks for L chessmen.


    Sample Input
    3 3 4
    1 2
    1 3
    2 1
    2 2
    3 3 4
    1 2
    1 3
    2 1
    3 2


    Sample Output
    Board 1 have 0 important blanks for 2 chessmen.
    Board 2 have 3 important blanks for 3 chessmen.

    枚举+二分匹配

     1 #include<cstdio>
     2 #include<cmath>
     3 #include<cstring>
     4 #include<iostream>
     5 #include<algorithm>
     6 using namespace std;
     7 
     8 int link[1001][1001];
     9 int cx[1001];
    10 int cy[1001];
    11 int mk[1001];
    12 int n,m;
    13 
    14 void init()
    15 {
    16     memset(link,0,sizeof(link));
    17 }
    18 
    19 int path(int u)
    20 {
    21     int v;
    22    for(v=1;v<=n;v++)
    23    {
    24         if(!mk[v]&&link[u][v])
    25         {
    26             mk[v]=1;
    27             if(cy[v]==-1||path(cy[v]))
    28             {
    29                 cx[u]=v;
    30                 cy[v]=u;
    31                 return 1;
    32             }
    33         }
    34    }
    35    return 0;
    36 }
    37 
    38 int maxmatch()
    39 {
    40     int i;
    41     int sum=0;
    42     memset(cx,0xff,sizeof(cx));
    43     memset(cy,0xff,sizeof(cy));
    44     memset(mk,0,sizeof(mk));
    45     for(i=1;i<=m;i++)
    46     {
    47         if(cx[i]==-1)
    48         {
    49             memset(mk,0,sizeof(mk));
    50             sum+=path(i);
    51         }
    52     }
    53     return sum;
    54 }
    55 
    56 int main()
    57 {
    58     int cas=1;
    59     int num;
    60     while(scanf("%d%d%d",&n,&m,&num)!=EOF)
    61     {
    62         init();
    63         int s,e;
    64         while(num--)
    65         {
    66             scanf("%d%d",&s,&e);
    67             link[s][e]=1;
    68         }
    69         int ans=maxmatch();
    70         int cnt=0;
    71         int i,j;
    72         for(i=1;i<=n;i++)
    73         {
    74             for(j=1;j<=n;j++)
    75             {
    76                 if(link[i][j]==0)continue;
    77                 link[i][j]=0;
    78                 if(ans>maxmatch())
    79                 {
    80                     cnt++;
    81                 }
    82                 link[i][j]=1;
    83             }
    84         }
    85         printf("Board %d have %d important blanks for %d chessmen.
    ",cas++,cnt,ans);
    86     }
    87     return 0;
    88 }
    View Code
  • 相关阅读:
    Linux Exploit系列之一 典型的基于堆栈的缓冲区溢出
    [Codeforces Round #433][Codeforces 853C/854E. Boredom]
    Educational Codeforces Round 4
    [Educational Round 3][Codeforces 609F. Frogs and mosquitoes]
    [ACM-ICPC 2018 徐州赛区网络预赛][D. Easy Math]
    Educational Codeforces Round 50
    [Codeforces Round #507][Codeforces 1039C/1040E. Network Safety]
    [Educational Round 3][Codeforces 609E. Minimum spanning tree for each edge]
    Educational Codeforces Round 3
    [Manthan, Codefest 18][Codeforces 1037E. Trips]
  • 原文地址:https://www.cnblogs.com/zafuacm/p/3217018.html
Copyright © 2011-2022 走看看