zoukankan      html  css  js  c++  java
  • BZOJ 1854: [Scoi2010]游戏( 二分图最大匹配 )

    匈牙利算法..从1~10000依次找增广路, 找不到就停止, 输出答案. 

    ----------------------------------------------------------------------------

    #include<bits/stdc++.h>
     
    using namespace std;
     
    const int MAXL = 10009, MAXR = 1000009;
     
    struct edge {
    int to;
    edge* next;
    } E[MAXR << 1], *pt = E, *head[MAXL];
     
    inline void addedge(int u, int v) {
    pt->to = v; pt->next = head[u];
    head[u] = pt++;
    }
     
    int match[MAXR], vis[MAXR], N, C;
     
    bool dfs(int x) {
    for(edge* e = head[x]; e; e = e->next) if(vis[e->to] != C) {
    vis[e->to] = C;
    if(!~match[e->to] || dfs(match[e->to])) {
       match[e->to] = x;
    return true;
    }
    }
    return false;
    }
     
    int main() {
    memset(match, -1, sizeof match);
    memset(vis, -1, sizeof vis);
    scanf("%d", &N);
    for(int i = 0; i < N; i++) {
    int a, b; scanf("%d%d", &a, &b); a--; b--;
    addedge(a, i); addedge(b, i);
    }
    int ans = 0;
    for(C = 0; C < 10000; C++) {
    if(dfs(C)) ans++;
    else break;
    }
    printf("%d ", ans);
    return 0;
    }

    ---------------------------------------------------------------------------- 

    1854: [Scoi2010]游戏

    Time Limit: 5 Sec  Memory Limit: 162 MB
    Submit: 3022  Solved: 1100
    [Submit][Status][Discuss]

    Description

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

    Input

    输入的第一行是一个整数N,表示lxhgww拥有N种装备 接下来N行,是对这N种装备的描述,每行2个数字,表示第i种装备的2个属性值

    Output

    输出一行,包括1个数字,表示lxhgww最多能连续攻击的次数。

    Sample Input

    3
    1 2
    3 2
    4 5

    Sample Output

    2

    HINT

    【数据范围】
    对于30%的数据,保证N < =1000
    对于100%的数据,保证N < =1000000

    Source

  • 相关阅读:
    CS224n, lec 10, NMT & Seq2Seq Attn
    CS231n笔记 Lecture 11, Detection and Segmentation
    CS231n笔记 Lecture 10, Recurrent Neural Networks
    CS231n笔记 Lecture 9, CNN Architectures
    CS231n笔记 Lecture 8, Deep Learning Software
    CS231n笔记 Lecture 7, Training Neural Networks, Part 2
    pytorch坑点排雷
    Sorry, Ubuntu 17.10 has experienced an internal error
    VSCode配置python插件
    tmux配置与使用
  • 原文地址:https://www.cnblogs.com/JSZX11556/p/4779498.html
Copyright © 2011-2022 走看看