bzoj 4808: 马

题意:

在图上放最多马,使它们不能相互攻击。

题解:

同bzoj 攻击装置。3175
一开始狂T,抄了个偏移量竟然快了10几倍?
玄学……
code:

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
int map[210][210],id=0,n,m;
int match[40010],chw[40010],tim=0;
struct node{
    int y,next;
}a[400010];int len=0,last[40010];
//int yh[15]={-2,-2,-1,1,2, 2, 1,-1};
//int yl[15]={-1, 1, 2,2,1,-1,-2,-2};

int yh[15]={-1,-2, 1, 2,-1,-2,1,2};
int yl[15]={-2,-1,-2,-1, 2, 1,2,1};

int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void ins(int x,int y)
{
    a[++len].y=y;
    a[len].next=last[x];last[x]=len;
}
bool findma(int x)
{
    for(int i=last[x];i;i=a[i].next)
    {
        int y=a[i].y;
        if(chw[y]!=tim)
        {
            chw[y]=tim;
            if(match[y]==0||findma(match[y]))
                return match[y]=x,true;
        }
    }
    return false;
}
int main()
{
    scanf("%d %d",&n,&m);
    memset(map,-1,sizeof(map));
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        {
            int x;x=read();
            if(x==0) map[i][j]=++id;
        }
    for(int x=1;x<=n;x++)
        for(int y=1;y<=m;y++)
            for(int i=0;i<8;i++)
            {
                int tx=x+yh[i],ty=y+yl[i];
                if(tx>0&&tx<=n&&ty>0&&ty<=m&&map[tx][ty]!=-1) ins(map[x][y],map[tx][ty]);
            }
    memset(match,0,sizeof(match));
    int ans=0;
    for(int i=1;i<=id;i++)
    {
        tim++;
        if(findma(i)) ans++;
    }
    printf("%d",id-ans/2);
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值