[SCOI2010] [BZOJ1854] games | binary map matching | Hungarian algorithm | and search set

Source: Internet
Author: User
Tags cmath

1854: [Scoi2010] game time limit:5 Sec Memory limit:162 MB
submit:3018 solved:1099
[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

Binary graph matching: The attribute to the weapon edge, starting from 1 to match, see where the match to end.
#include <iostream>#include<cstdio>#include<cstdlib>#include<algorithm>#include<cmath>#include<cstring>using namespacestd;inthead[1000005],lk[1000005],state[1000005];intlist[2000005],next[2000005];intCnt,t;inlineintRead () {intA=0, f=1;CharC=GetChar ();  while(c<'0'|| C>'9') {if(c=='-') f=-1; C=GetChar ();}  while(c>='0'&&c<='9') {a=a*Ten+c-'0'; C=GetChar ();} returnA *F;} InlinevoidInsertintXinty) {next[++cnt]=Head[x]; HEAD[X]=CNT; LIST[CNT]=y;}BOOLHungary (intx) {     for(intI=head[x];i;i=Next[i]) {        if(state[list[i]]==t)Continue; State[list[i]]=u; if(!lk[list[i]]| |Hungary (Lk[list[i])) {Lk[list[i]]=x; return 1; }    }    return 0;}intMain () {intn=read (), i,x,y;  for(i=1; i<=n;i++) X=read (), y=read (), insert (x,i), insert (y,i);  for(i=1; i<=10000; i++) {T++; if(! Hungary (i)) Break; } printf ("%d", I-1); return 0;}

And check the set:

References to Hzwer:

For a unicom block, if it does not contain a ring (is a tree), then must be able to meet any of the p-1 points.

For a unicom block, if it contains a ring, then all the P points must be satisfied.

Then a vis can be used to maintain this property when merging and checking the set.

Think of weights as points and weapons as edges.

If the edge of each join is a merge of two unicom blocks

The right value of the Unicom block and to a large value of the Unicom block, and then to the weight of the small vis=true

If not

The vis=true of the vertex of the connecting block is changed.

This ensures that if a size of n Unicom block

=n-1 Edge composition, maximum point of Vis=false, others true

≥n, vis=true of all points

And then the last time you scan vis, you can come up with an answer.

#include <iostream>#include<cstdio>#include<algorithm>#include<cmath>#include<cstdlib>#include<cstring>using namespacestd;intn,f[1000005];BOOLv[1000005];inlineintRead () {intA=0, f=1;CharC=GetChar ();  while(c<'0'|| C>'9') {if(c=='-') f=-1; C=GetChar ();}  while(c>='0'&&c<='9') {a=a*Ten+c-'0'; C=GetChar ();} returnA *F;}intFindintx) {returnx==f[x]?x:f[x]=find (F[x]);} InlinevoidUnintXinty) {    if(x<y) Swap (x, y); F[y]=x; V[y]=1;}intMain () {n=read ();  for(intI=1; i<=n+1; i++) f[i]=i; memset (V,0,sizeof(v));  for(intI=1; i<=n;i++)     {        intX=read (), y=read (); intP=find (x), q=find (y); if(p!=q) UN (P,Q);Elsev[p]=1; }     for(intI=1; i<=n+1; i++)         if(!v[i]) {printf ("%d", I-1); Break;} return 0;}

[SCOI2010] [BZOJ1854] games | binary map matching | Hungarian algorithm | and search set

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.