1854: [Scoi2010] game time limit:5 Sec Memory limit:162 MB
submit:2538 solved:905
[Submit] [Status] 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
The problem: One get, not difficult to find is a more obvious two-figure matching, but as phile god Ben said (orzPhile2333), the time complexity of the Hungarian algorithm is O (NM), but this problem actually n<=10000 m<=1000000, This is not the inevitable rhythm-but the seemingly naked Hungarian algorithm is still duly accept ... So magical ... Ask for an expert explanation
1/**************************************************************2Problem:18543 User:hansbug4 language:pascal5 result:accepted6Time:3396Ms7Memory:43248KB8****************************************************************/9 Ten type OnePoint=^node; ANode=Record - G:longint; - Next:point; the End; - - var - I,j,k,l,m,n,pt:longint; +C,f:Array[0..1000500] ofLongint; -A:Array[0..1000500] ofPoint ; + functionmin (x,y:longint): Longint;inline; A begin at ifX<y ThenMin:=xElsemin:=y; - End; - procedureAdd (x,y:longint); inline; - varP:point; - begin - new (p); inp^.g:=y; -p^.next:=A[x]; toa[x]:=p; + End; - functionCheck (x:longint): Boolean;inline; the varP:point; * begin $p:=A[x];Panax Notoginseng whileP<>Nil Do - begin the ifF[p^.g]<>pt Then + begin Af[p^.g]:=pt; the ifc[p^.g]=0 Then + begin -c[p^.g]:=x; $ exit (true); $ End - Else ifCheck (C[P^.G]) Then - begin thec[p^.g]:=x; - exit (true);Wuyi End; the End; -p:=P^.next; Wu End; - exit (false); About End; $ begin - READLN (n); - fori:=1 toN Doa[i]:=Nil; - fori:=1 toN Do A begin + readln (j,k); the Add (j,i); add (k,i); - End; $Fillchar (C,sizeof (c),0); theFillchar (F,sizeof (f),0); thept:=0; the fori:=1 to 10000 Do the begin - Inc (PT); in if not(check (i)) Then the begin theWriteln (I-1); About Halt; the End; the End; theWriteln (10000); + End.
1854: [Scoi2010] Games