P1640 [SCOI2010]连续攻击游戏 二分图构造

题意

lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示。当他使用某种装备时,他只能使用该装备的某一个属性。并且每种装备最多只能使用一次。游戏进行到最后,lxhgww遇到了终极boss,这个终极boss很奇怪,攻击他的装备所使用的属性值必须从1开始连续递增地攻击,才能对boss产生伤害。也就是说一开始的时候,lxhgww只能使用某个属性值为1的装备攻击boss,然后只能使用某个属性值为2的装备攻击boss,然后只能使用某个属性值为3的装备攻击boss……以此类推。现在lxhgww想知道他最多能连续攻击boss多少次?

武器的个数<=1000000

思路

这个构图我觉得是比较巧妙的。单单拆点按不同属性分两边不太好想。
这道题合理的二分图中,左边1~10000表示攻击的序列,右边1~n表示武器。从左边向右边对应武器连两条有向边,跑二分图匹配,就很巧妙的使得这两条边不会同时成立。

#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <cassert>

using namespace std;
#define lson (l, mid, rt << 1)
#define rson (mid + 1, r, rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

typedef long long ll;
typedef unsigned long long ull;
//typedef __int128 bll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, pii> p3;

//priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl '\n'

#define boost                    \
    ios::sync_with_stdio(false); \
    cin.tie(0)
#define rep(a, b, c) for (int a = (b); a <= (c); ++a)
#define max3(a, b, c) max(max(a, b), c);
#define min3(a, b, c) min(min(a, b), c);

const ll oo = 1ll << 17;
const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //18
const int mod = 1e9 + 7;
const double esp = 1e-8;
const double PI = acos(-1.0);
const double PHI = 0.61803399; //黄金分割点
const double tPHI = 0.38196601;

template <typename T>
inline T read(T &x) {
    x = 0;
    int f = 0;
    char ch = getchar();
    while (ch < '0' || ch > '9') f |= (ch == '-'), ch = getchar();
    while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    return x = f ? -x : x;
}
struct FastIO {
    static const int S = 4e6;
    int wpos;
    char wbuf[S];
    FastIO() :
        wpos(0) {
    }
    inline int xchar() {
        static char buf[S];
        static int len = 0, pos = 0;
        if (pos == len)
            pos = 0, len = fread(buf, 1, S, stdin);
        if (pos == len) exit(0);
        return buf[pos++];
    }
    inline int xuint() {
        int c = xchar(), x = 0;
        while (c <= 32) c = xchar();
        for (; '0' <= c && c <= '9'; c = xchar()) x = x * 10 + c - '0';
        return x;
    }
    inline int xint() {
        int s = 1, c = xchar(), x = 0;
        while (c <= 32) c = xchar();
        if (c == '-') s = -1, c = xchar();
        for (; '0' <= c && c <= '9'; c = xchar()) x = x * 10 + c - '0';
        return x * s;
    }
    inline void xstring(char *s) {
        int c = xchar();
        while (c <= 32) c = xchar();
        for (; c > 32; c = xchar()) *s++ = c;
        *s = 0;
    }
    inline void wchar(int x) {
        if (wpos == S) fwrite(wbuf, 1, S, stdout), wpos = 0;
        wbuf[wpos++] = x;
    }
    inline void wint(int x) {
        if (x < 0) wchar('-'), x = -x;
        char s[24];
        int n = 0;
        while (x || !n) s[n++] = '0' + x % 10, x /= 10;
        while (n--) wchar(s[n]);
        wchar('\n');
    }
    inline void wstring(const char *s) {
        while (*s) wchar(*s++);
    }
    ~FastIO() {
        if (wpos) fwrite(wbuf, 1, wpos, stdout), wpos = 0;
    }
} io;
inline void cmax(int &x, int y) {
    if (x < y) x = y;
}
inline void cmax(ll &x, ll y) {
    if (x < y) x = y;
}
inline void cmin(int &x, int y) {
    if (x > y) x = y;
}
inline void cmin(ll &x, ll y) {
    if (x > y) x = y;
}

/*-----------------------showtime----------------------*/
const int maxn = 10009;
struct E {
    int v, nxt;
} edge[2000009];
int head[maxn], gtot;
void addedge(int u, int v) {
    edge[gtot].v = v;
    edge[gtot].nxt = head[u];
    head[u] = gtot++;
}
int used[1000009], pt[1000009];

bool hungry(int u, int col) {
    for (int i = head[u]; ~i; i = edge[i].nxt) {
        int v = edge[i].v;
        if (used[v] < col) {
            used[v] = col;
            if (pt[v] == 0 || hungry(pt[v], col)) {
                pt[v] = u;
                return true;
            }
        }
    }
    return false;
}
int main() {
    int n;
    scanf("%d", &n);
    memset(head, -1, sizeof(head));
    for (int i = 1; i <= n; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        addedge(x, i);
        addedge(y, i);
    }
    int ans = 0, col = 0;
    for (int i = 1; i <= 10000; i++) {
        ++col;
        if (hungry(i, col))
            ans = i;
        else
            break;
    }
    printf("%d\n", ans);
    return 0;
}
View Code

 

posted @ 2019-02-16 23:54  ckxkexing  阅读(203)  评论(0编辑  收藏  举报