Arctic Network POJ - 2349

The Department of National Defence (DND) wishes to connect several northern outposts by a wireless network. Two different communication technologies are to be used in establishing the network: every outpost will have a radio transceiver and some outposts will in addition have a satellite channel.
Any two outposts with a satellite channel can communicate via the satellite, regardless of their location. Otherwise, two outposts can communicate by radio only if the distance between them does not exceed D, which depends of the power of the transceivers. Higher power yields higher D but costs more. Due to purchasing and maintenance considerations, the transceivers at the outposts must be identical; that is, the value of D is the same for every pair of outposts.

Your job is to determine the minimum D required for the transceivers. There must be at least one communication path (direct or indirect) between every pair of outposts.

Input

The first line of input contains N, the number of test cases. The first line of each test case contains 1 <= S <= 100, the number of satellite channels, and S < P <= 500, the number of outposts. P lines follow, giving the (x,y) coordinates of each outpost in km (coordinates are integers between 0 and 10,000).

Output

For each case, output should consist of a single line giving the minimum D required to connect the network. Output should be specified to 2 decimal points.

Sample Input

1
2 4
0 100
0 300
0 600
150 750

Sample Output

212.13

题意:现有 m 个地点, n 个卫星。  卫星有一个神奇的作用, 作用在于只要某个地方安装有卫星, 不论他们之间距离为多远, 都能够互相接收到彼此间信 号, 那么其他地方需要通过收发器 D 来连接。让你求1 - m 个地方在共安装过 n 个卫星后,我们所需要     的 收发器 D 所需的最大距离是多少?

输出用%lf 然后一直错

printf的%f说明符的确既可以输出float型又可以输出double型。根据“默认参数提升”规则float型会被提升为double型。因此printf()只会看到双精度数。对于scanf,情况就完全不同了,它接受指针,这里没有类似的类型提升。向float存储和向double存储大不一样,因此,scanf区别%f和%lf。      
也就是说输出的时候不管输出的是双精度还是单精度都用%f就没错了,但是输入的时候,输入单精度要用%f而输入双精度要用%lf

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>

using namespace std;

struct node
{
    int u, v;
    double w;
} edge[1110000];

struct dian
{
    int x, y;
} p[111000];

int tol = 0;
void addedge(int u, int v, double w)
{
    edge[tol].u = u;
    edge[tol].v = v;
    edge[tol++].w = w;
}
int f[111000];
int Find(int x)
{
    if(f[x] == x)return x;
    else
    {
        return f[x] = Find(f[x]);
    }
}
int cmp(node a, node b)
{
    return a.w < b.w;
}
void init(int n)
{
    for(int i = 0; i <= n; i++)
    {
        f[i] = i;
    }
}
double s(int n, int k)
{
    int cnt = 0;
    init(n);
    sort(edge, edge + tol, cmp);
    for(int i = 0; i < tol; i++)
    {
        int u = edge[i].u;
        int v = edge[i].v;
        double w = edge[i].w;
        int tx = Find(u);
        int ty = Find(v);
        if(tx != ty)
        {
            f[tx] = ty;
            cnt++;
        }
        if(cnt >= n - k)
        {
            return w;
        }
    }
    return 0;
}
double len(dian a, dian b)
{
    return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
void in()
{
    int t;
    scanf("%d", &t);
    while(t--)
    {
        int n, k;
        tol = 0;
        scanf("%d %d", &k, &n);
        for(int i = 0; i < n; i++)
        {
            scanf("%d %d", &p[i].x, &p[i].y);
        }
        for(int i = 0; i < n; i++)
        {
            for(int j = i + 1; j < n; j++)
            {
                double l = len(p[i], p[j]);
                addedge(i, j, l);
            }
        }
        double sum = s(n, k);
        printf("%.2f\n", sum);
    }
}
int main()
{
    in();
    return 0;
}

 

Arctic是一个专门用于金融数据管理的开源数据库,可以用于存储、管理和查询各种类型的金融数据,例如时间序列数据、交易数据、统计数据等。它基于MongoDB数据库,提供了简单易用的Python API,可以方便地进行数据的读写和查询。下面是Arctic数据库的安装步骤: 1. 安装MongoDB数据库 Arctic数据库是基于MongoDB数据库的,所以首先需要安装MongoDB数据库。可以到官网上下载对应版本的MongoDB,并按照官方文档进行安装。 2. 安装Python API 使用pip命令安装arctic库: ``` pip install arctic ``` 3. 连接MongoDB数据库 使用arctic库中的arctic库中的arctic库中的arctic连接函数,将Python中的连接MongoDB数据库。在连接函数中需要指定MongoDB数据库的地址和端口号,例如: ``` import pymongo from arctic import Arctic # 连接MongoDB数据库 conn = pymongo.MongoClient('localhost', 27017) # 创建Arctic数据库对象 store = Arctic(conn) ``` 4. 创建库和集合 可以使用Arctic库中的库和集合函数来创建库和集合,例如: ``` # 创建名为test的库 library = store['test'] # 创建名为stock的集合,并指定数据类型为TICK library.initialize_library('stock', lib_type=Arctic.TICK_STORE) ``` 5. 存储数据 使用Arctic库中的集合对象来进行数据的存储,例如: ``` # 获取名为stock的集合对象 collection = library['stock'] # 存储数据 symbol = 'AAPL' timestamp = '2022-01-01 09:30:00' price = 100.0 volume = 10000 collection.write(symbol, {'timestamp': timestamp, 'price': price, 'volume': volume}) ``` 以上就是Arctic数据库的安装步骤,可以根据实际需要来进行安装和使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值