题目大意:有n(<=1000000)个装备,每个装备有两个属性值(<=10000),每个装备只能用一次,使用某一个值,攻击boss必须先使用属性为1的,再使用属性为2的,再使用属性为3的,以此类推······问最多攻击多少次。

  每个武器和他的两个属性值连边,跑匈牙利。

  学会了新的技巧,可以省掉1w个memset(这题是真·1w个 2333333)。

代码如下:

#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
using namespace std;
struct poi{int too,pre;}e[2000001];
int n,x,y,t,tot,ans,num,lin[1000001],last[1000001],v[1000001];
void add(int x,int y){e[++tot].too=y;e[tot].pre=last[x];last[x]=tot;}
bool dfs(int x)
{
    for(int i=last[x],too=e[i].too;i;i=e[i].pre,too=e[i].too)
    if(v[too]!=t)
    {
        v[too]=t;
        if((!lin[too])||dfs(lin[too]))
        {
            lin[too]=x;
            return 1;
        }
    }
    return 0;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d %d",&x,&y),add(x,i),add(y,i);
    for(int i=1;i<=10000;i++)
    {
        ++t;
        if(dfs(i))ans++;
        else break;
    }
    printf("%d\n",ans);
}
View Code

相关文章:

  • 2022-12-23
  • 2021-12-21
  • 2021-06-13
  • 2021-07-24
  • 2021-10-05
  • 2022-12-23
猜你喜欢
  • 2022-02-20
  • 2021-06-13
  • 2021-10-22
  • 2022-01-06
  • 2021-12-13
相关资源
相似解决方案