2018山东省ACM大学生程序设计竞赛B.Bullet

每次二分后找最大匹配数

Bullet

Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description

In GGO, a world dominated by gun and steel, players are fighting for the honor of being the strongest gunmen. Player Shino is a sniper, and her aimed shot kills one monster at a time. Now she is in an n×nn \times nn×n map, and there are monsters in some grids. Each monster has an experience. As a master, however, Shino has a strange self-restrain. She would kill at most one monster in a column, and also at most one in a row. Now she wants to know how to get max experience, under the premise of killing as many monsters as possible.

Input

The first line contains an integer nnn
Then n lines follow. In each line there are n integers, and AijAijAij represents the experience of the monster at grid (i,j)(i,j)(i,j). If Aij=0Aij=0Aij=0, there is no monster at grid (i,j)(i,j)(i,j).

Output

One integer, the value of max experience.

Sample Input
2
2 0
1 8
Sample Output
2
Hint
Source
“浪潮杯”山东省第九届ACM大学生程序设计竞赛(感谢山东财经大学)
#define happy

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define all(a) (a).begin(),(a).end()
#define pll pair<ll,ll>
#define vi vector<int>
#define P pair<int,int>
#define pb push_back
const int inf=0x3f3f3f3f;
ll rd(){
    ll 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;
}
const int N=500+10;
int path[N][N],mp[N][N],link[N],vis[N],n;

bool hungarian(int pos){
    rep(i,1,n){
        if(vis[i]==0&&path[pos][i]==1){
            vis[i]=1;
            if(link[i]==0||hungarian(link[i])){
                link[i]=pos;
                return true;
            }
        }
    }
    return false;
}

int solve(){
    memset(link,0,sizeof(link));
    int ans=0;
    rep(i,1,n){
        memset(vis,0,sizeof(vis));
        if(hungarian(i))ans++;
    }
    return ans;
}

int main(){
#ifdef happy
    freopen("in.txt","r",stdin);
#endif
    n=rd();
    rep(i,1,n)rep(j,1,n){
        mp[i][j]=rd();
        if(mp[i][j]!=0)
            path[i][j]=1;
        else path[i][j]=0;
    }
    int tmp=solve();
    if(tmp==0)return puts("0"),0;
    int le=-inf,ri=inf;
    ll ans=0;
    while(le<=ri){
        int mid=(le+ri)/2;
        rep(i,1,n)rep(j,1,n){
            if(mp[i][j]>=mid&&mp[i][j]!=0)
            path[i][j]=1;
            else path[i][j]=0;
        }
        int mm=solve();
        if(mm==tmp){
            ans=mid;
            le=mid+1;
        }else{
            ri=mid-1;
        }
    }
    printf("%lld\n",ans);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值