codevs 3315 时空跳跃者的魔法 MST

题目:
http://codevs.cn/problem/3315/

最小生成树模板题;

WA的原因:
没有考虑字符串L的长度,以为只有以为,于是l=s[0]-‘0’;

什么时候才永远不会犯这么低级的错误啊!!!

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;

const int MAXN=2000001;
struct hh {int from,to,cost;}ma[MAXN];
struct sh {int x,y,z,t;}mp[MAXN];
int n,tot,sum,cnt;
int fa[MAXN];
string s;

int get(sh a,sh b)
{
    return trunc(sqrt( (a.x-b.x) * (a.x-b.x) + (a.y-b.y) * (a.y-b.y) + (a.z-b.z) * (a.z-b.z) )) + abs(a.t-b.t);
}

void build(int f,int t,int c)
{
    ma[++tot]=(hh){f,t,c};
    return;
}

bool cmp(hh a,hh b)
{
    return a.cost < b.cost;
}

int find(int x)
{
    int r=x,t;
    while(r!=fa[r]) r=fa[r];
    while(x!=r) t=fa[x],fa[x]=r,x=t;
    return r;
}

void kruskal()
{
    for(int i=1;i<=n;i++) fa[i]=i;

    sort(ma+1,ma+tot+1,cmp);

    for(int i=1;i<=tot;i++)
    {
        int fx=find(ma[i].from),fy=find(ma[i].to);
        if(fx!=fy)
        {
            fa[fx]=fy;
            sum+=ma[i].cost;
        }
    }
    return;
}
void solve()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d%d%d%d",&mp[i].x,&mp[i].y,&mp[i].z,&mp[i].t);

    cin>>s;

    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
            build(i,j,get(mp[i],mp[j]));        

    kruskal();

    int l=0;
    for(int i=0;i<s.size();i++)
        if(s[i]>='0' && s[i]<='9')
            l=l*10+s[i]-'0';

    if(sum>l) printf("Death\n");
    else printf("%dTas\n",sum);
    return;
}
int main()
{
    solve();
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值