题意

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> /* ⊂_ヽ
  \\ Λ_Λ 来了老弟
   \('ㅅ')
    > ⌒ヽ
   /   へ\
   /  / \\
   レ ノ   ヽ_つ
  / /
  / /|
 ( (ヽ
 | |、\
 | 丿 \ ⌒)
 | |  ) /
'ノ )  Lノ */ 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<<;
const ll mos = 0x7FFFFFFF; //
const ll nmos = 0x80000000; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //
const int mod = 1e9+;
const double esp = 1e-;
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=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
}
struct FastIO {
static const int S = 4e6;
int wpos;
char wbuf[S];
FastIO() : wpos() {}
inline int xchar() {
static char buf[S];
static int len = , pos = ;
if (pos == len)
pos = , len = fread(buf, , S, stdin);
if (pos == len) exit();
return buf[pos++];
}
inline int xuint() {
int c = xchar(), x = ;
while (c <= ) c = xchar();
for (; '' <= c && c <= ''; c = xchar()) x = x * + c - '';
return x;
}
inline int xint()
{
int s = , c = xchar(), x = ;
while (c <= ) c = xchar();
if (c == '-') s = -, c = xchar();
for (; '' <= c && c <= ''; c = xchar()) x = x * + c - '';
return x * s;
}
inline void xstring(char *s)
{
int c = xchar();
while (c <= ) c = xchar();
for (; c > ; c = xchar()) * s++ = c;
*s = ;
}
inline void wchar(int x)
{
if (wpos == S) fwrite(wbuf, , S, stdout), wpos = ;
wbuf[wpos++] = x;
}
inline void wint(int x)
{
if (x < ) wchar('-'), x = -x;
char s[];
int n = ;
while (x || !n) s[n++] = '' + x % , x /= ;
while (n--) wchar(s[n]);
wchar('\n');
}
inline void wstring(const char *s)
{
while (*s) wchar(*s++);
}
~FastIO()
{
if (wpos) fwrite(wbuf, , wpos, stdout), wpos = ;
}
} 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 = ;
struct E{
int v,nxt;
}edge[];
int head[maxn],gtot;
void addedge(int u,int v){
edge[gtot].v = v;
edge[gtot].nxt = head[u];
head[u] = gtot++;
}
int used[],pt[]; 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]== || hungry(pt[v],col)){
pt[v] = u;
return true;
}
}
}
return false;
}
int main(){
int n; scanf("%d", &n);
memset(head, -, sizeof(head));
for(int i=; i<=n; i++){
int x,y;
scanf("%d%d", &x, &y);
addedge(x, i);
addedge(y, i);
}
int ans = ,col = ;
for(int i=; i<=; i++){
++col;
if(hungry(i,col)) ans = i;
else break;
}
printf("%d\n", ans);
return ;
}

P1640 [SCOI2010]连续攻击游戏 二分图构造的更多相关文章

  1. P1640 [SCOI2010]连续攻击游戏 二分图最大匹配 匈牙利算法

    题目描述 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备时,他只能使用该装备的某一个属性.并且每种装备 ...

  2. 洛谷 P1640 [SCOI2010]连续攻击游戏 解题报告

    P1640 [SCOI2010]连续攻击游戏 题目描述 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备 ...

  3. 洛谷——P1640 [SCOI2010]连续攻击游戏

    P1640 [SCOI2010]连续攻击游戏 题目描述 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备 ...

  4. 洛谷P1640 [SCOI2010]连续攻击游戏(二分图)

    题目描述 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备时,他只能使用该装备的某一个属性.并且每种装备 ...

  5. [luogu1640 SCOI2010]连续攻击游戏 (二分图最大匹配)

    传送门 Description lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备时,他只能使用该装备的某 ...

  6. 洛谷—— P1640 [SCOI2010]连续攻击游戏

    https://www.luogu.org/problem/show?pid=1640 题目描述 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1, ...

  7. [P1640][SCOI2010]连续攻击游戏

    Link: P1640 传送门 Solution: 可以发现这道题其实是属性值集合和装备集合的对应,且每个点只能用一次 那么就能想到二分图最大匹配,一旦不可行直接退出就行了 Tip: 1.$Hungr ...

  8. 洛谷P1640 [SCOI2010]连续攻击游戏 题解

    题目链接: https://www.luogu.org/problemnew/show/P1640 分析: 这道题用二分图来解决即可.应该可以作为网络流中的模板题来食用, 每一个武器有两个属性,但是只 ...

  9. P1640 [SCOI2010]连续攻击游戏【并查集】

    题目描述 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备时,他只能使用该装备的某一个属性.并且每种装备 ...

随机推荐

  1. Cocos2d-x v3.11 中的新内存模型

    Cocso2d-x v3.11 一项重点改进就是 JSB 新内存模型.这篇文章将专门介绍这项改进所带来的新研发体验和一些技术细节. 1. 成果 在 Cocos2d-x v3.11 之前的版本中,使用 ...

  2. memCached的配置文件 配置

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  3. python redis连接 有序集合去重

    # -*- coding: utf-8 -*- import redisfrom constant import redis_ip, redis_db, redis_pw, logger, redis ...

  4. S2:java集合框架

    Java集合就是一个容器.面向对象语言对事物的体现都是以对象的形式存在,所以为了方便对多个对象的操作,就对对象进行存储,集合就是存储对象最常用的一种方式.集合只用于存储对象,集合长度是可变的,集合可以 ...

  5. 6.源码分析---和dubbo相比SOFARPC是如何实现负载均衡的?

    官方目前建议使用的负载均衡包括以下几种: random(随机算法) localPref(本地优先算法) roundRobin(轮询算法) consistentHash(一致性hash算法) 所以我们接 ...

  6. 夯实Java基础(五)——==与equals()

    1.前言 我们在学习Java的时候,看到==.equals()就认为比较简单,随便看了一眼就过了,其实你并没有深入去了解二者的区别.这个问题在面试的时候出现的频率比较高,而且据统计有85%的人理直气壮 ...

  7. 限流降级神器,带你解读阿里巴巴开源 Sentinel 实现原理

    Sentinel 是阿里中间件团队开源的,面向分布式服务架构的轻量级高可用流量控制组件,主要以流量为切入点,从流量控制.熔断降级.系统负载保护等多个维度来帮助用户保护服务的稳定性. 大家可能会问:Se ...

  8. 解决:Navicat连接不上MySQL 8.0

    转载自 https://www.cnblogs.com/shiysin/p/shiysin.html Navicat连接不上,总是报错1251: 原因是MySQL8.0版本的加密方式和MySQL5.0 ...

  9. [Spring cloud 一步步实现广告系统] 16. 增量索引实现以及投送数据到MQ(kafka)

    实现增量数据索引 上一节中,我们为实现增量索引的加载做了充足的准备,使用到mysql-binlog-connector-java 开源组件来实现MySQL 的binlog监听,关于binlog的相关知 ...

  10. Netty学习(十)-Netty文件上传

    今天我们来完成一个使用netty进行文件传输的任务.在实际项目中,文件传输通常采用FTP或者HTTP附件的方式.事实上通过TCP Socket+File的方式进行文件传输也有一定的应用场景,尽管不是主 ...