26.时空跳跃者的魔法

时间限制: 1 s

 空间限制: 32000 KB

 题目等级 : 白银 Silver

题解

 查看运行结果

题目描述 Description

背景:suntian正准备将飞翔带回圣殿,不料一声巨响,suntian的三维时空被飞翔炸开,飞翔再次出现在suntian面前,两人同时出手……随着两人昏天暗地的打斗,时空开始扭曲并产生波动,影响了suntian施咒,然而就是这一下,飞翔抓住了时机,释放巨大的能量将suntian送入了一个扭曲的四维时空……

描述:为了快一点追到飞翔,suntian希望在最短的时间内逃出这个四维时空。

他马上集中精力,在0.0000000000000001ms之内找到了这个时空的奇点。令他吃惊的是,这个空间竟然有n个奇点!这让suntian摸不着头脑。但作为圣殿战士,suntian也不是吃素的,他在冥思苦想之后得出了一个结论:只有在某个奇点处用咒术将其他n-1个奇点拉到这个奇点,才能将奇点打开。但是,将奇点拉拽到另一个奇点耗费的能量不同。能量W为:trunc(sqrt((x1-x2)^2+(y1-y2)^2+(z1-z2)^2))+abs(t1-t2) Tas。奇点拉在一起将被合并,suntian可以先把某些奇点合并再拉到他所处的奇点。为了抓捕到飞翔,suntian想用最少的能量来打开奇点,但是suntian能量已经所剩不多了。那么,suntian能否逃脱呢?

输入描述 Input Description

第一行,为n(0

2n+1行,为每行的坐标x,y,z,t(0<=10^4,x,y,z,t∈N) n+2行,为suntian剩余能量L(0

输出描述 Output Description

共一行。

 如果所用最少能量tot>L,那么输出“Death”

 否则,输出tot(tot

样例输入 Sample Input

5

1 1 1 1

1 1 1 2

2 2 2 2

3 3 3 3

3 3 3 4

5Tas

样例输出 Sample Output

5Tas

代码:

#include

using namespace std;

#include

#include

#include

#include

#include//trunc ==floor

#define maxn 1001//ji dian shu

struct Point{

       int x,y,z,t;

};

Point point[maxn];

long long l,tot,k=0;

int t=0;

struct Edge{

       int u,v;

       int w;

};

Edge edge[maxn*maxn];

int n,father[maxn];

void input();

void kruskal();

void turn1();

int main()

{

       input();

       turn1();

       kruskal();

       if(tot>l)

       {

              printf("Death ");

              return 0;

       }

       printf("%lldTas ",tot);

       return 0;

}

int cmp(const Edge &a,const Edge &b)

{

       return a.w

}

int find(int x)

{

       if(father[x]!=x) father[x]=find(father[x]);

       return father[x];

}

void unionn(int a,int b)

{

       father[b]=a;

}

void kruskal()

{

       for(int i=1;i<=n;++i)

       father[i]=i;

       tot=0;

       sort(edge+1,edge+t+1,cmp);

       for(int i=1;i<=t;++i)

       {

              int r1=find(edge[i].u);

              int r2=find(edge[i].v);

              if(r1!=r2)

              {

                     unionn(r1,r2);

                     k++;

                     tot+=edge[i].w;

                     if(k==n-1)return;

              }

       }

}

void input()

{

       scanf("%d",&n);

       for(int i=1;i<=n;++i)

       scanf("%d%d%d%d",&point[i].x,&point[i].y,&point[i].z,&point[i].t);

       scanf("%lld",&l);

}

void turn1()

{

       t=0;

       for(int i=1;i<=n;++i)

         for(int j=1;j<=n;++j)

         {

             edge[++t].u=i;

             edge[t].v=j;

                edge[t].w=sqrt(pow(point[i].x-point[j].x,2 )+pow(point[i].y-point[j].y,2)+pow(point[i].z-point[j].z,2))+abs(point[i].t-point[j].t);    

         //trunc(sqrt((x1-x2)^2+(y1-y2)^2+(z1-z2)^2))+abs(t1-t2) Tas

         }

}

原文地址:https://www.cnblogs.com/csgc0131123/p/5290492.html