Hungary & Discrete (the board)

It was originally intended to do with the example of GYM-102458A but this can (gai) love (si) of the title is so downright.
So we do dingy example of the use poj-3041, (although this problem does not require discrete)
poj-3041 and GYM-102458A needs to be as abscissa and ordinate as the two sides of FIG Hungarian then run (this is a magic graph theory, two unrelated problems intended, the composition method does the same)
paste it here before recall the nature of two bar graphs (lest my mind made muddy, forgot ...)
minimum Vertex cover = maximum matching
minimum path coverage = number of points - the biggest match
the largest independent set = points - the largest match

here GYM-102458A is seeking the maximum matching
poj-3041 is the smallest point calculated to cover
the following Hungary's board, as it has been very familiar with, not to go into details, there is a problem and then look at previous notes like (in fact, because I'm too lazy)
Hungary board:

bool dfs(int now)
{
    for (int i = head[now]; i != -1; i = edge[i].nxt)
    {
        int v = edge[i].to;
        if (!vis[v])
        {
            vis[v] = 1;
            if (link[v] == -1 || dfs(link[v]))
            {
                link[v]=now;
                return 1;
            }
        }
    }
    return 0;
}
void getans()
{
    int ans = 0;
    for (int i = 1; i <= mx; i++)
    {
        memset(vis, 0, sizeof(vis));
        if (dfs(i))ans++;
    }
    cout << ans;
}

The following highlights summarize discrete board, used to always feel that simple, did not mind, the result of a write themselves, always all kinds of trouble ... finally feel the need to sum up, save some for the future do it ...

Description link

Method 1: comprising a repeating element, and the same elements have the same discretization

int n;
int  s[Max_n],t[Max_n];

for(int i=1;i<=n;i++){
	scanf("%d",&s[i]);
	t[i]=s[i];
}
sort(t+1,t+n+1);
int m=unique(t+1,t+n+1)-t-1; //m为不重复元素的个数 
for(int i=1;i<=n;i++){
	s[i]=lower_bound(t+1,t+m+1,s[i])-t;
}

Method 2: whether or not a repeating element, the discrete elements vary.

int n;
struct node{
	int x,id;
	operator<(const node& no)const{
		 if(x!=no.x)
		 return x<no.x;
		 else
		 return id<no.id;
	}
}no[Max_n];
int s[Max_n];

for(int i=1;i<=n;i++){
	scanf("%d",&no[i].x);
	no[i].id=i;
} 
sort(no+1,no+n+1);
for(int i=1;i<=n;i++)s[no[i].id]=i;

Well ... the original bloggers I like the wind code, to borrow friends

Finally Tucao wave of God (sha) odd (que) of GYM-102458A

Published 30 original articles · won praise 9 · views 1290

Guess you like

Origin blog.csdn.net/Zhang_sir00/article/details/104470401