POJ 3164 Command Network

poj3164 Command Network||openjudge 地震之后 这是题目: 6:地震之后 总时间限制: 1000ms 内存限制: 130000kB 描述 2008年地震之后,坚强县受灾严重,该县通信线路也收到了致命的打击,县总部为了能够及时的向各村的发送消息,命令小强去解决一下这个问题。 小强经过调查发现,为了能够快速的实现通信,当务之急是能够建立起一条从总部可以向各个村单向发送信息的通信系统。由于灾后情况紧急,不是每一个村之间都能够快速的建立起 阅读详情

POJ 3164 Command Network

Description

After a long lasting war on words, a war on arms finally breaks out between littleken’s and KnuthOcean’s kingdoms. A sudden and violent assault by KnuthOcean’s force has rendered a total failure of littleken’s command network. A provisional network must be built immediately. littleken orders snoopy to take charge of the project.

With the situation studied to every detail, snoopy believes that the most urgent point is to enable littenken’s commands to reach every disconnected node in the destroyed network and decides on a plan to build a unidirectional communication network. The nodes are distributed on a plane. If littleken’s commands are to be able to be delivered directly from a node A to another node B, a wire will have to be built along the straight line segment connecting the two nodes. Since it’s in wartime, not between all pairs of nodes can wires be built. snoopy wants the plan to require the shortest total length of wires so that the construction can be done very soon.

Input

The input contains several test cases. Each test case starts with a line containing two integer N (N ≤ 100), the number of nodes in the destroyed network, and M (M ≤ 104), the number of pairs of nodes between which a wire can be built. The next N lines each contain an ordered pair xi and yi, giving the Cartesian coordinates of the nodes. Then follow M lines each containing two integers i and j between 1 and N (inclusive) meaning a wire can be built between node i and node j for unidirectional command delivery from the former to the latter. littleken’s headquarter is always located at node 1. Process to end of file.

Output

For each test case, output exactly one line containing the shortest total length of wires to two digits past the decimal point. In the cases that such a network does not exist, just output ‘poor snoopy’.

Sample Input

4 6
0 6
4 6
0 0
7 20
1 2
1 3
2 3
3 4
3 1
3 2
4 3
0 0
1 0
0 1
1 2
1 3
4 1
2 3

Sample Output

31.19
poor snoopy

Source

POJ Monthly--2006.12.31, galaxy

Solution

朱刘算法,与HDU 2121 Ice_cream’s world II类似,只是这道题的根节点是0

Code

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <vector>
#include <queue>
#define L 200
#define LL long long
#define inf 2000000000
using namespace std;

struct point {
  double x, y;
} p[L];
struct node {
  int from, to;
  double w;
} e[L * L];
int n, m, pre[L], vis[L], id[L];
double in[L];

inline double len(int a, int b) {
  return sqrt(a * a + b * b);
}

inline double MST(int root, int N, int E) {
  double ret = 0;
  while (true) {
    for (int i = 0; i < N; ++i) in[i] = inf;
    for (int i = 0; i < E; ++i) {
      int u = e[i].from, v = e[i].to;
      double w = e[i].w;
      if (w < in[v] && v != u) in[v] = w, pre[v] = u;
    }
    for (int i = 0; i < N; ++i) {
      if (i == root) continue;
      if (in[i] == inf) return -1;
    }
    in[root] = 0;
    memset(vis, -1, sizeof(vis));
    memset(id, -1, sizeof(id));
    int node = 0;
    for (int i = 0; i < N; ++i) {
      ret += in[i];
      int v = i;
      while (vis[v] != i && v != root && id[v] == -1) vis[v] = i, v = pre[v];
      if (v != root && id[v] == -1) {
	for (int u = pre[v]; u != v; u = pre[u]) id[u] = node;
	id[v] = node++;
      }
    }
    if (node == 0) break;
    for (int i = 0; i < N; ++i)
      if (id[i] == -1) id[i] = node++;
    for (int i = 0; i < E; ++i) {
      int u = e[i].from, v = e[i].to;
      e[i].from = id[u], e[i].to = id[v];
      if (e[i].from != e[i].to) e[i].w -= in[v]; 
    }
    N = node, root = id[root];
  }
  return ret;
}

int main() {
  freopen("POJ3164.in", "r", stdin);
  freopen("POJ3164.out", "w", stdout);
  while (scanf("%d %d", &n, &m) != EOF) {
    for (int i = 0; i < n; ++i) scanf("%lf %lf", &p[i].x, &p[i].y);
    for (int i = 0; i < m; ++i) {
      scanf("%d %d", &e[i].from, &e[i].to);
      e[i].from--, e[i].to--;
      if (e[i].from != e[i].to) e[i].w = len(p[e[i].from].x - p[e[i].to].x, p[e[i].from].y - p[e[i].to].y);
      else e[i].w = inf;
    }
    double ans = MST(0, n, m);
    if (ans == -1) printf("poor snoopy\n");
    else printf("%.2f\n", ans);
  }
  return 0;
}

Summary

一开始本来都是对的,只是

printf("%.2f\n", ans);
打成了
printf("%.2lf\n", ans);
就WA了……


comfyui从入门到精通二:提示词规则详解 《AI绘画提示词使用全指南》摘要: 本文系统解析AI绘画提示词的核心规则与实用技巧。关键点包括:1) 空格与下划线的本质差异,webui会自动转换但comfyui保留原格式;2) 数字与单词表达(如1girl/one girl)会导致风格变化;3) 三种权重控制方式(数值标注、括号嵌套、位置效应),其中数值标注最直观有效;4) 位置衰减公式揭示提示词排序对效果的影响权重。同时指出当前AI绘画仍存在角色一致性等更复杂的技术瓶颈。全文通过多组对比实验,为创作者提供从基础语法到高阶控制的完整解决方案。 阅读详情

相关推荐

hpm6750evk2开发板(一)菜鸟入门

hpm6750与我们平时常用的stm单片机在开发环境和开发方法上有很大的区别,所以上手还是需要花一点时间的,拿到板子先不要急着上电调试,我们先找资料学习一下了,免得多走冤枉路,以下是我整理的一些学习资源,包括开发板使用手册、芯片SDK、开发工具、视频资料等,建议先把使用手册和学习视频先看了,再取搭建环境测试。最近刚入手一块hpm6750evk2开发板,花了几天时间学习,算是菜鸟入门了,今天分享一下学习过程。看完资料后,把开发工具安装上,下一篇文章我们分享一下调试工程的过程和遇到的问题。

Silas1750的博客 3098

poj 地震之后

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_34175509的博客 233

BIM Revit教程(六)尝试安装 Revit 时显示“Autodesk Revit 已安装。”

在安装Revit或RevitLT时,若系统提示“AutodeskRevit版本已安装”,通常是由于旧版本残留文件未完全清除所致。解决方案包括:1.通过控制面板或Windows设置卸载旧版本Revit,确保所有相关组件被移除;2.使用Autodesk卸载工具(AdskUninstallHelper)进一步清理;3.谨慎操作注册表,删除与Revit相关的残留项;4.确保系统有至少30GB的可用磁盘空间;5.完成上述步骤后,重新尝试安装Revit。此外,文章还提到了一个免费功能商店,供用户寻找提效工具,并鼓励粉丝

ZOZO_888的博客 2158

地震之后

6:地震之后 查看提交统计提问 总时间限制: 1000ms 内存限制: 130000kB 描述   2008年地震之后,坚强县受灾严重,该县通信线路也收到了致命的打击,县总部为了能够及时的向各村的发送消息,命令小强去解决一下这个问题。   小强经过调查发现,为了能够快速的实现通信,当务之急是能够建立起一条从总部可以向各个村单向发送信息的通信系统。由

m0_57375647的博客 598

Fluent Meshing边界层设置保姆级教程:从y+理论到实战避坑,看完就会

本文详细解析了Fluent Meshing边界层设置的全过程,从y+理论基础到实战避坑技巧,帮助用户精准计算第一层高度并优化参数配置。通过案例演示和常见问题诊断,指导读者掌握边界层网格生成的核心技术,提升CFD模拟精度。特别针对不同湍流模型的y+要求提供具体参数建议。

weixin_30576827的博客 820

Flutter版本升级踩坑实录:从3.27到3.35,我们是如何修复Impeller引擎导致的花屏问题的?

本文详细记录了团队在Flutter版本升级过程中遇到的Impeller引擎导致的花屏问题及解决方案。从问题诊断到最终升级至稳定版3.35,文章分享了排查步骤、升级策略和性能对比数据,为开发者提供了实用的参考经验。

weixin_26854555的博客 518

Poj 3164 Command Network【最小树形图】

Command Network Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 15914   Accepted: 4583 Description After a long lasting war on words, a war on arms fina

希望的专栏 1499

光学测量仿真软件:OpticsBuilder_(9).热应力分析与补偿

在OpticsBuilder中,定义材料的热膨胀系数可以通过API进行。以下是一个Python代码示例,展示如何在OpticsBuilder中定义材料的热膨胀系数。

kkchenjj的博客 1090

POJ3164:Command Network

Command Network Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 7267   Accepted: 2160 Description After a long lasting war on words, a war o

第七殿堂 605

SpringBoot+Vue+kkFileView实现文档管理(文档上传、下载、在线预览)

上面在使用OpenOffice实现doc、excel、ppt等文档的管理和预览。除此之外可用kkFileView实现包括且更多文档的预览。

BADAO_LIUMANG_QIZHI的博客 1万+

VN1640 CH5 I/O通道终极指南:【从硬件原理—>工程实战—>自动化测试实战】

摘要:本文详细解析Vector VN1640 CH5 I/O通道的硬件原理与工程应用,涵盖模拟输入(AIN)、数字输入(DIN)和数字输出(DOUT)三大功能模块的配置指南。通过硬件隔离设计实现高精度信号采集与驱动控制,重点分析开漏输出特性及保护机制。提供PWM控制、ECU上电时序测试、传感器闭环控制等实战案例的CAPL脚本代码,并强调多设备同步采集的精准性(时间偏差<1µs)。适用于汽车电子HIL测试、ECU信号监测等场景,所有方案均通过实际项目验证。

汽车控制器系统开发、VIL测试、HIL测试、MIL测试、EMS电喷系统标定与开发、热管理系统标定 763

poj3164-Command Network

给出平面上一些点,和连接它们的带权有向边,求把所有点连起来的最小总权值。 分析 由于这里边是有向的(unidirectional),所以这是经典的最小树形图问题,可以说是最小树形图的模板题。 代码 这个写法是我乱想的。最近写图啊树啊都喜欢开一个结构体~ 这个代码在poj上交,如果用g++的话会WA,因为奇怪的poj需要用%f输出浮点数。更奇怪的是c++直接编译错误,不想说了。 #incl...

dengtan9179的博客 199

WPF数据绑定Binding对数据的转换与效验(四)

Binding的作用就是架在Source与Target之间的桥梁,数据可以在这座桥梁的帮助下来流通。就像现实世界中的桥梁会设置一些关卡进行安检一样,Binding这座桥上也可以设置关卡对数据的有效性进行检验,不仅如此,当Binding的两端要求使用不同的数据类型时,我们还可以为数据设置转换器。Binding用于数据有效性检验的关卡是它的ValidationRules属性,用于数据类型转换的关卡是它的Converter属性。

qq_30725967的博客 1634

poj3164Command Network

传送门:http://poj.org/problem?id=3164 思路:最小树形图模板题 朱刘算法见http://blog.csdn.net/wsniyufang/article/details/6747392 #include #include #include #include #include #include const int maxn=105,maxm=50010;

thy的专栏 555

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

POJ 3164 Command Network

Description After a long lasting war on words, a war on arms finally breaks out between littleken’s and KnuthOcean’s kingdoms. A sudden and violent assault by KnuthOcean’s force has rendered a to

Occult 436

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

POJ3164 Command Network

Time Limit:1000MS Memory Limit:131072K Total Submissions:17235 Accepted:4959 Description After a long lasting war on words, a war on arms finally breaks out b...

dezhen7015的博客 157

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

POJ3164---Command Network

Command Network Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 13609   Accepted: 3925 Description After a long lasting war on words, a war on arms finally

Alex 803

poj3164 Command Network

http://poj.org/problem?id=3164 继续测测板子 #include<cstdio> #include<cmath> using namespace std; const int maxl=2e4+10; const int inf=1e9+10; int n,m;double ans=0; int x[maxl],y[maxl]; double ine[maxl];int pre[maxl],vis[maxl],id[maxl]; struct e

binarycopycode 177

【POJ 3164】【朱刘算法模板】Command Network

求解最小树形图:朱刘算法模板题~

Regina8023 1629

POJ-3164 Command Network

最小树形图模板题,用朱刘算法 注意自环和重边的处理 #include&lt;iostream&gt; #include&lt;cstdio&gt; #include&lt;cstring&gt; #include&lt;algorithm&gt; #include&lt;cmath&gt; #include&lt;queue&gt; using namespace std; typedef ...

wl16wzl的博客 251

poj 3164 Command Network

链接:http://poj.org/problem?id=3164     继续最小树形图~   这次的最小树形图直接套模板上去就可以了....我把刚才那篇的写法用上去,AC的还是相当顺利的,就只有刚开始打错了几个字,搞到TLE了一下。于是,我确定这种写法(我觉得已经是相当飘逸的了)可以加入我的模板...   题意就没必要解释了,这么明显。 View Code 1 #inclu...

weixin_33690367的博客 75
上一篇: HDU 2121 Ice_cream’s world II
下一篇: POJ 3659 Cell Phone Network
CYCKCN
博客等级 码龄10年 17粉丝 65原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值