Eddy's picture

本文探讨了一个在给定坐标点上绘制最短连线的问题,通过使用并查集算法来解决如何将所有点连接在一起,形成最小总长度的连线。详细介绍了输入输出规范及示例代码。

                                                  Eddy's picture

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 8   Accepted Submission(s) : 3
Problem Description
Eddy begins to like painting pictures recently ,he is sure of himself to become a painter.Every day Eddy draws pictures in his small room, and he usually puts out his newest pictures to let his friends appreciate. but the result it can be imagined, the friends are not interested in his picture.Eddy feels very puzzled,in order to change all friends 's view to his technical of painting pictures ,so Eddy creates a problem for the his friends of you.
Problem descriptions as follows: Given you some coordinates pionts on a drawing paper, every point links with the ink with the straight line, causes all points finally to link in the same place. How many distants does your duty discover the shortest length which the ink draws?
 

Input
The first line contains 0 < n <= 100, the number of point. For each point, a line follows; each following line contains two real numbers indicating the (x,y) coordinates of the point. Input contains multiple test cases. Process to the end of file.
 

Output
Your program prints a single real number to two decimal places: the minimum total length of ink lines that can connect all the points.
 

Sample Input
3 1.0 1.0 2.0 2.0 2.0 4.0
 

Sample Output
3.41
 

Author
eddy
 
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int pre[101];
void itin()
{
    for(int i=0;i<101;i++)
    pre[i]=i;
}
struct point
{
    float x,y;
}p[100];
struct dis
{
    int u,v;
    float val;
}d[100010];
int cmp(dis n1,dis n2)
{
    if(n1.val<n2.val)
    return 1;
    return 0;
}
int find(int x)
{
    while(x!=pre[x])
    x=pre[x];
    return x;
}
bool join(int x,int y)
{
    int fx=find(x);
    int fy=find(y);
    if(fx!=fy)
    {
        pre[fx]=fy;
        return true;
    }
    return false;
}
int main()
{
    int t;
    while(scanf("%d",&t)!=EOF)
    {
        itin();
        int i,j;
        memset(p,0,sizeof(p));
        float sum=0;
        for(i=0;i<t;i++)
        scanf("%f%f",&p[i].x,&p[i].y);
        int cnt=0;
        for(i=0;i<t;i++)
        for(j=i+1;j<t;j++)
        {
            float dist=sqrt((p[i].x-p[j].x)*(p[i].x-p[j].x)+(p[i].y-p[j].y)*(p[i].y-p[j].y));
            d[cnt].u=i;
            d[cnt].v=j;
            d[cnt++].val=dist;
        }
        sort(d,d+cnt,cmp);
        /*for(i=0;i<cnt;i++)
        printf("%f ",d[i].val);
        printf("\n");*/
        for(i=0;i<cnt;i++)
        {
            if(join(d[i].u,d[i].v))
            {
            sum+=d[i].val;
            //printf("%f\n",sum);
            }
            
        }
        printf("%.2f\n",sum);
    }
    return 0;
}


转载于:https://www.cnblogs.com/playboy307/p/5273838.html

### Eddy与CUDA集成概述 Eddy 是一种用于处理扩散加权磁共振成像 (DWI) 数据的工具,主要用于校正由涡流效应引起的图像失真。而 CUDA 则是由 NVIDIA 提供的一种并行计算平台和编程模型,允许开发者利用 GPU 的强大算力来加速应用程序。 当提到 **Eddy with CUDA** 集成时,这通常意味着通过 CUDA 技术优化 Eddy 工具中的某些计算密集型部分[^1]。这种集成可以显著提高数据处理速度,尤其是在涉及大量 DWI 图像的情况下。以下是关于两者关系及其使用的详细介绍: #### 1. CUDA 加速原理 CUDA 能够让程序运行在支持 CUDA 的 GPU 上,从而实现多线程并行化操作。对于 Eddy 这样的科学计算软件来说,其核心算法可能涉及到大量的矩阵运算、傅里叶变换以及插值等复杂过程。这些都可以被映射到 GPU 中执行以获得性能提升[^2]。 #### 2. 如何启用 CUDA 支持? 为了使 FSL-Eddy 使用 CUDA 功能,在安装过程中需要特别配置环境变量或者指定编译选项。具体方法如下所示: ```bash export USE_CUDA=1 fsl_install_eddy_openmp_cuda.sh ``` 上述命令会告知系统构建带有 CUDA 扩展版本的 eddy binary 文件。需要注意的是,只有当目标机器上存在兼容硬件(即具备适当架构代号的支持NVIDIA GPUs),此设置才会生效[^3]。 另外还需确认已正确加载对应驱动程序及相关库文件;否则即便完成了上述步骤也可能无法正常工作。 #### 3. 性能收益评估 采用GPU辅助方式确实能够带来可观的时间节省效果——特别是在高分辨率扫描条件下更是如此。然而实际增益程度取决于多种因素共同作用的结果,比如输入数据集规模大小、特定参数选取情况等等[^4]。 ```python import subprocess def run_eddy_with_cuda(input_file, output_dir): command = [ 'eddy', '--imain=' + input_file, '--mask=brain_mask.nii.gz', '--acqp=acq_params.txt', '--index=index.eddy', '--bvecs=bvecs.rotated', '--bvals=bval', '--out=' + output_dir + '/eddy_corrected' ] result = subprocess.run(command, capture_output=True, text=True) if result.returncode !=0 : raise Exception(f"Eddy failed {result.stderr}") run_eddy_with_cuda('data.nii','/path/to/output') ``` 以上脚本展示了调用带cuda增强版eddy的一个简单例子。其中包含了必要的位置参数定义以及其他一些常见选项说明。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值