1. 程式人生 > >P1640 [SCOI2010]連續攻擊遊戲 二分圖構造

P1640 [SCOI2010]連續攻擊遊戲 二分圖構造

遊戲 lin 割點 www int line emp 題意 序列

https://www.luogu.org/problemnew/show/P1640

題意

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<<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

P1640 [SCOI2010]連續攻擊遊戲 二分圖構造