曼哈顿最小距离生成树(poj 3241&& UVALive 3662)

poj 3241 http://poj.org/problem?id=3241

求曼哈顿距离最小生成树第K长的边的长度

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define MEM(a,x) memset(a,x,sizeof a)
#define eps 1e-8
#define MOD 10009
#define MAXN 100010
#define MAXM 100010
#define INF 99999999
#define ll __int64
#define bug cout<<"here"< '9') c = getchar();
    int x = 0;
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x;
}

void Print(int a)
{
     if(a>9)
         Print(a/10);
     putchar(a%10+'0');
}

struct Point
{
    int x,y,id;
}p[MAXN];
bool cmp(Point a,Point b)
{
    if(a.x!=b.x) return a.x0)
    {
        if(val=0;i--)
        {
            int pos=lower_bound(b,b+m,a[i])-b+1;
            int ans=ask(pos,m);
            if(ans!=-1)
                addedge(p[i].id,p[ans].id,dist(p[i],p[ans]));
            update(pos,p[i].x+p[i].y,i);
        }
    }
}

int solve(int k)
{
    Manhattan_minmum_spanning_tree(n,p);
    MEM(F,-1);
    sort(edge,edge+tot,cmpedge);
    for(int i=0;i

UVALive 3662  http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=23379

求曼哈顿距离最小生成树中边的权值和

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define MEM(a,x) memset(a,x,sizeof a)
#define eps 1e-8
#define MOD 10009
#define MAXN 100010
#define MAXM 100010
#define INF 99999999
#define ll long long
#define bug cout<<"here"< '9') c = getchar();
    int x = 0;
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x;
}

void Print(int a)
{
     if(a>9)
         Print(a/10);
     putchar(a%10+'0');
}

struct Point
{
    int x,y,id;
}p[MAXN];
bool cmp(Point a,Point b)
{
    if(a.x!=b.x) return a.x0)
    {
        if(val=0;i--)
        {
            int pos=lower_bound(b,b+m,a[i])-b+1;
            int ans=ask(pos,m);
            if(ans!=-1)
                addedge(p[i].id,p[ans].id,dist(p[i],p[ans]));
            update(pos,p[i].x+p[i].y,i);
        }
    }
}

ll solve()
{
    Manhattan_minmum_spanning_tree(n,p);
    MEM(F,-1);
    sort(edge,edge+tot,cmpedge);
    ll ans=0;
    for(int i=0;i




你可能感兴趣的:(图论)