1854: [Scoi2010] Game time limit: 5 Sec Memory Limit: 162 MB
Submit: 3695 Solved: 1405
[Submit] [Status] [Discuss] DESCRIPTIONLXHGWW has recently been fascinated by a game in which he has a lot of equipment, each with 2 attributes, the values of which are expressed in numbers between [1,10000]. When he uses some kind of equipment, he can only use one of the properties of the equipment. And each device can be used at most once. At the end of the game, LXHGWW encountered the ultimate boss, the ultimate boss is very strange, attack his equipment used by the attribute value must start from 1 continuous incremental attack, in order to damage the boss. In other words, at first, LXHGWW can only use a device with a property value of 1 to attack the boss, and then only use a device with a property value of 2 to attack the boss, and then only use a property value of 3 of the equipment attack boss ... And so on Now LXHGWW want to know how many times he can attack bosses in succession? The first line of input inputs is an integer n, which means that LXHGWW has n equipment next n lines, is a description of the n equipment, 2 numbers per line, representing the 2 attribute values of the equipment of the first I output a row, including 1 numbers, indicating the maximum number of consecutive attacks Lxhgww. Sample Input3
1 2
3 2
4 5
Sample Output2
HINT
"Data Range"
For 30% of data, ensure n < =1000
For 100% of data, ensure n < =1000000
Source
Day1
[Submit] [Status] [Discuss] Solving : The maximum matching of a binary graph.
Since the weights of all properties are selected only once, and all weapons can only select one of them, all two properties from a weapon are connected to the weapon, and the Hungarian algorithm can be run. (seems to have written and checked on the Internet).
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < queue> #define N 3200000#define M 1200000#define inf 1000000000using namespace Std;int next[n*2],v[n*2],remain[n*2]; int Point[m];int belong[m],cur[m];int n,tot;void Add (int x,int y) {tot++; next[tot]=point[x]; point[x]=tot; v[tot]=y;} int dfs (int x) {for (int i=point[x];i;i=next[i]) {int t=v[i], if (cur[t]==i) continue; cur[t]=i; if (!belong[t]| | DFS (Belong[t])) { belong[t]=x; return true; } } return false;} int main () {scanf ("%d", &n), int maxn=0;for (int i=1;i<=n;i++) {int x, Y, scanf ("%d%d", &x,&y); add (x,i); add (Y,i); Maxn=max (MAXN,X); Maxn=max (Maxn,y); }memset (Belong,0,sizeof (belong)); for (int i=1;i<=maxn;i++) {if (!dfs (i)) { printf ("%d\n", i-1); return 0; } }printf ("%d\n", MAXN);}
Bzoj 1854: [Scoi2010] Game (the maximum match of the binary graph)