Time Limit: 5 Sec Memory Limit: 162 MB
Submit: 2538 Solved: 905
lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示。当他使用某种装备时,他只能使用该装备的某一个属性。并且每种装备最多只能使用一次。 游戏进行到最后,lxhgww遇到了终极boss,这个终极boss很奇怪,攻击他的装备所使用的属性值必须从1开始连续递增地攻击,才能对boss产生伤害。也就是说一开始的时候,lxhgww只能使用某个属性值为1的装备攻击boss,然后只能使用某个属性值为2的装备攻击boss,然后只能使用某个属性值为3的装备攻击boss……以此类推。 现在lxhgww想知道他最多能连续攻击boss多少次?
输入的第一行是一个整数N,表示lxhgww拥有N种装备 接下来N行,是对这N种装备的描述,每行2个数字,表示第i种装备的2个属性值
输出一行,包括1个数字,表示lxhgww最多能连续攻击的次数。
3 1 2 3 2 4 5
2
【数据范围】 对于30%的数据,保证N < =1000 对于100%的数据,保证N < =1000000
题解:此题一拿到,不难发现是一个比较明显的二分图匹配,可是如phile神犇所言(orzPhile2333),匈牙利算法的时间复杂度为O(NM),可是此题中实际上N<=10000 M<=1000000,这不是必死无疑的节奏么——可是貌似裸的匈牙利算法还是妥妥Accept了。。。so神奇。。。求高人解释
1 /**************************************************************
2 Problem: 1854
3 User: HansBug
4 Language: Pascal
5 Result: Accepted
6 Time:3396 ms
7 Memory:43248 kb
8 ****************************************************************/
9
10 type
11 point=^node;
12 node=record
13 g:longint;
14 next:point;
15 end;
16
17 var
18 i,j,k,l,m,n,pt:longint;
19 c,f:array[0..1000500] of longint;
20 a:array[0..1000500] of point;
21 function min(x,y:longint):longint;inline;
22 begin
23 if x<y then min:=x else min:=y;
24 end;
25 procedure add(x,y:longint);inline;
26 var p:point;
27 begin
28 new(p);
29 p^.g:=y;
30 p^.next:=a[x];
31 a[x]:=p;
32 end;
33 function check(x:longint):boolean;inline;
34 var p:point;
35 begin
36 p:=a[x];
37 while p<>nil do
38 begin
39 if f[p^.g]<>pt then
40 begin
41 f[p^.g]:=pt;
42 if c[p^.g]=0 then
43 begin
44 c[p^.g]:=x;
45 exit(true);
46 end
47 else if check(c[p^.g]) then
48 begin
49 c[p^.g]:=x;
50 exit(true);
51 end;
52 end;
53 p:=p^.next;
54 end;
55 exit(false);
56 end;
57 begin
58 readln(n);
59 for i:=1 to n do a[i]:=nil;
60 for i:=1 to n do
61 begin
62 readln(j,k);
63 add(j,i);add(k,i);
64 end;
65 fillchar(c,sizeof(c),0);
66 fillchar(f,sizeof(f),0);
67 pt:=0;
68 for i:=1 to 10000 do
69 begin
70 inc(pt);
71 if not(check(i)) then
72 begin
73 writeln(i-1);
74 halt;
75 end;
76 end;
77 writeln(10000);
78 end.