hdoj1536 find the safest road(dijstra)

工业组态软件Intouch(单机版)入门{第一篇} 通俗来讲Intouch就是一个能将PLC里的信号显示在画面上的软件。 阅读详情

find the safest road

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9273    Accepted Submission(s): 3280


Problem Description
XX星球有很多城市,每个城市之间有一条或多条飞行通道,但是并不是所有的路都是很安全的,每一条路有一个安全系数s,s是在 0 和 1 间的实数(包括0,1),一条从u 到 v 的通道P 的安全度为Safe(P) = s(e1)*s(e2)…*s(ek) e1,e2,ek是P 上的边 ,现在8600 想出去旅游,面对这这么多的路,他想找一条最安全的路。但是8600 的数学不好,想请你帮忙 ^_^
 

Input
输入包括多个测试实例,每个实例包括:
第一行:n。n表示城市的个数n<=1000;
接着是一个n*n的矩阵表示两个城市之间的安全系数,(0可以理解为那两个城市之间没有直接的通道)
接着是Q个8600要旅游的路线,每行有两个数字,表示8600所在的城市和要去的城市
 

Output
如果86无法达到他的目的地,输出"What a pity!",
其他的输出这两个城市之间的最安全道路的安全系数,保留三位小数。
 

Sample Input
3 1 0.5 0.5 0.5 1 0.4 0.5 0.4 1 3 1 2 2 3 1 3
 

Sample Output
0.500 0.400 0.500


此题求安全系数最高的,就是把模板改一下,而且安全系数是权值相乘,要注意一下 
#include<stdio.h>
#define INF 0x6ffffff
#include<string.h>
#include<algorithm>
using namespace std;
double cost[1010][1010];
double dis[1010];
int used[1010];
int n;
void dijstra(int s)
{
	for(int i=1;i<=n;i++)
	{
		dis[i]=0;
		used[i]=false;
	}
	dis[s]=1;
	while(true)
	{
		int v=-1;
	for(int i=1;i<=n;i++)
	{
		if(used[i]==0&&(v==-1||dis[v]<dis[i]))//求最大的dis【v】<dis【i】 
		v=i;
	}
	if(v==-1)
	break;
	used[v]=true;
	for(int i=1;i<=n;i++)
	dis[i]=max(dis[i],dis[v]*cost[v][i]);//权值相乘 
	}
}

int main()
{
	int i,j,m,a,b;
	memset(cost,0,sizeof(cost));
	while(~scanf("%d",&n))
	{
		for(i=1;i<=n;i++)
			for(j=1;j<=n;j++)
				scanf("%lf",&cost[i][j]);
		scanf("%d",&m);
		for(i=1;i<=m;i++)
		{
			scanf("%d%d",&a,&b);//分别给出m组数据,a,b分别代表起点和终点 
			dijstra(a);
			if(dis[b]==0)//如果不通的话也就是说距离为0 
			printf("What a pity!\n");
			else
			printf("%.3lf\n",dis[b]);
		}
	}
	return 0;
}


SAP FAGLFLEXT 是 SAP 新总账的核心余额表,存储多维度的汇总余额数据。核心结论:该表按 “科目 + 会计年度 + 期间 + 维度” 存储累计余额,字段可分为基础标识 FAGLFLEXT是SAP新总账的核心余额表,采用"科目+年度+期间+维度"结构存储多维汇总数据。其字段分为基础标识(科目、年度等)、维度细分(公司代码、利润中心等15个维度)、金额数值(本外币余额)、辅助控制(状态标识)四大类,支持新总账的灵活核算。该表通过凭证自动更新,与旧总账GLT0相比显著扩展了维度核算能力,各维度需在科目主数据或Ledger配置中启用才能使用。 阅读详情

相关推荐

Speedtree学习笔记(案例)——拥有多种材质的植物如何导入使用(以草为例)

注:Speedtree无论保存还是导入模型其存储路径不可有中文。 第一步拆分草的模型 根据所需的材质去拆分(例:假若草的果实,茎秆和叶子是不同的材质那么就需拆分为三份;假若画的全部颜色及材质一样就没有必要去拆分模型) 第二步导入草的模型 在Mesh面板中依次导入草的模型——Do nothing additional right now 第三步扩大草的生长区域范围(可省略)...

L人青的博客 5722

【HDOJ1536】S-Nim(博弈)

大致题意: 给你一个a数组 每次可以取a[i]个,q次询问,每次询问 共有m堆,因为sg函数是一堆的,所以将每堆的sg值异或就是答案。 #include <bits/stdc++.h> using namespace std; const int maxn = 10000 + 10; int s[110]; int sg[maxn]; bool Hash[maxn]; /

落寞是岁月的痕迹 735

5分钟搞定PaddleOCR PP-OCRv5环境搭建:从安装到第一个识别Demo

本文提供了一份详细的PaddleOCR PP-OCRv5环境搭建与快速入门指南。通过清晰的步骤,指导读者在5分钟内完成从创建Python虚拟环境、安装PaddlePaddle框架和PaddleOCR库,到编写并运行第一个OCR识别Demo的全过程,帮助开发者快速体验最新的PP-OCRv5模型的文字识别能力。

sprite的博客 1268

HDU 1596 find the safest road

find the safest roadTime Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1533    Accepte

Dwylkz 794

SAP-PM设备模块-PM主数据之功能位置

SAP-PM模块学习

TRUIXIANG的博客 5137

Autowired的使用介绍

我们都知道在spring中@Autowired注解,是用来自动装配对象的。@Service@Autowired没错,这样是能够装配成功的,因为默认情况下spring是按照类型装配的,也就是我们所说的byType方式。此外,@Autowired注解的required。

白话机器学习 1350

HDOJ 1536 SG函数的基本应用

从题意来看,是基本的SG函数应用,把刚学的set用进去优化,发现不行... TLE... 再看看SG的原理,网上大部分都是采用递归,而那些题解报告都是一把抄,嗤之以鼻.. 下面是直接TLE的代码: /********************* S-Nim Sevenster 2012.08.26 12:55 *********************/ #include #includ

Bysen32 870

APM水下机器人实战:从零搭建高精度自主航行系统

本文详细介绍了如何基于开源APM飞控及其水下分支ArduSub,从零搭建高精度自主水下航行器。核心在于集成双天线RTK模块实现厘米级定位与精确航向,并配合MAVROS与ROS构建自主控制系统。文章涵盖了硬件选型、软件配置、自主逻辑开发及水池调试的全流程实战经验,为水下机器人爱好者与研究者提供了一套完整的自主航行系统解决方案。

app77的博客 512

HDOJ-1536 S-Nim

当我们面对由 n 个游戏组合成的一个游戏时,只需对于每个游戏找出求它的每个局面的 SG 值的方法,就可以把这些 SG 值全部看成 Nim 的 石子堆#include <iostream> #include <algorithm> #include <cstring> #include <cmath> #include <vector> #include <cstdio> #define maxn 1

L. 459

安装Tailscale

如果返回 /usr/bin/tailscale 或类似路径,说明已安装但 sudo 可能找不到它。如果 which tailscale 没有输出,说明安装失败,重新执行安装步骤。Tailscale 的后台服务 tailscaled 必须运行。检查 tailscaled 服务是否运行。检查 tailscale 命令是否存在。

FairLikeSnow的博客 1478

两相变频交错PFC实战:从论文理论到PSIM仿真的完整避坑指南

本文详细解析了两相变频交错PFC技术从理论到PSIM仿真的完整实现过程,特别针对CRM模式下的BOOST PFC设计挑战提供实用解决方案。涵盖周期值比较法与RS触发器法的对比实施、PSIM仿真中的过零处理与收敛性优化等核心问题,并给出硬件实现的进阶建议,助力工程师高效完成高功率密度PFC设计。

weixin_30632089的博客 422

HDOJ 1536 S-NIM

S-NIM:在NIM游戏的基础上加入了S值,限制REMOVE BEADS的数量。其实只要用SG函数就可以解出来了。#include#include#includeusing namespace std;int k; //enable的个数int enable[100]; //规定可以取走的数int SG[10001]; //存放SG值int SG_v

互联网产品管理、交互、设计、开发、用户体验专栏 871

matplotlib保存图片设置分辨率总是96dpi,好烦躁,教你一招轻松解决

matplotlib保存图片设置分辨率总是96dpi,好烦躁,教你一招轻松解决 目录 matplotlib保存图片设置分辨率总是96dpi,好烦躁,教你一招轻松解决 #使用plt.savefig("cm.png",dpi = 300)为什么不管用 #plt.rcParams也不管用 #解决方案 在做论文的过程中,许多期刊或者会议对图片的分辨率有明确的要求,例如,dpi=300。 之前画曲线图都是采取保存方式为savefig(dpi=300),然后查看保存图片的属性信息,然而你看到的现象是

data+scenario+science+insight 8800

HDOJ 1536 S-Nim SG函数求法

Arthur and his sister Caroll have been playing a game called Nim for some time now. Nim is played as follows: The starting position has a number of heaps, all containing some, not necessarily equal, number of beads. The players take turns chosing a

kdwycz的刷题空间 1640

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

IEM模型,地表粗糙度模拟

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

floyed变形求最长路 HDU 1596 find thesafest road

find thesafest roadTimeLimit: 10000/5000 MS (Java/Others)    Memory Limit:32768/32768 K (Java/Others)Total Submission(s): 16072    Accepted Submission(s): 5575ProblemDescriptionXX星球有很多城市,每个城市之间有一条或多条飞...

pxlsdz的博客 518

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

HDU1596 find the safest road(最短路变形,Dijkstra)

题目: find the safest road Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 12964    Accepted Submission(s): 4625 Problem Descripti

riba2534的博客 754

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

HDOJ 1536 S-Nim

首先,S-Nim是经典的博弈类的题目可以用Sprague-Grundy函数进行解决,关于Sprague-Grundy函数的方法,见链接文章:Sprague-Grundy函数 其次,关于Sprague-Grundy函数的SG值。S-Nim类的游戏转化为Nim游戏,并将每个点当做一堆石子,该点的SG值当做该堆的石子数。但是为什么SG值有什么意义?为...

weixin_30571465的博客 161

HDU-1596-find the safest road

HDU-1596-find the safest road http://acm.hdu.edu.cn/showproblem.php?pid=1596 SPFA算法 #include&lt;iostream&gt; #include&lt;cstdio&gt; #include&lt;cstring&gt; using namespace std; int n,m,st,ed,fron...

java开发指南博客 【转载】 180

HDOJ 1536 S-Nim 博弈 SG函数

//HDOJ 1536 S-Nim SG函数 /* 题意: 有n堆石子,每次只能取走 一个给定集合S中出现的元素 的石子,问先手胜负态 思路:sg函数 */ #include&lt;stdio.h&gt; #include&lt;string.h&gt; #include&lt;stdlib.h&gt; #define N 105 #define M 10005 int k,n,m; in...

爱.NET 170

hdu 1536、hdu 1944 S-Nim(博弈SG函数)

题意:多组测试数据 ,输入 k个集合S的元素,m种情况,m种(L堆,每堆hi个)。             若存在移动某堆能到达一个必败点,则该点为必胜点,输出W             必败点指无论怎么移动都只能到达必胜点,输出L。 思路:SG函数             每堆看做一个子游戏,SG函数通过递归得到每种堆数的g(); SG函数 定义: 对于一个递增有界的图G(X, F

4452

hdoj 1536 题目大意 SG函数 博弈

Hdoj 1536   Problem Description   Arthur and his sister Caroll have been playing a game called Nim for some time now. Nim is played as follows:       The starting position has a number of heaps...

wangmengfuu的博客 316

HDOJ1536 S-nim

题意:典型的SG值问题,给n个堆,m个数字,每次只能从一个堆取m个数字之一。 分析:照着做就完事了,但是我不清楚为什么在这题迭代没有递归块?what? #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int k, a[100], f[10001]; ...

timeruler的博客 235

杭电find the safest road(最短路径,dijkstra,floyd)

find the safest road Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 9502    Accepted Submission(s): 3360 Problem Description

Eric_keke的专栏 1201

HDOJ--1596--find the safest road

find the safest road Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 9438    Accepted Submission(s): 3338 Problem Description XX星球有很多城

粥同学的学习笔记 929

hdu1596 find the safest road(dijkstra求最短路)

find the safest road                                                                           Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem

酱油拌面 418

5分钟搞定Unity材质:从纯色方块到写实木纹,手把手教你用内置资源快速提升3D场景质感

本文详细介绍了如何在Unity3D中快速创建和优化材质,从纯色方块到写实木纹,通过调整Standard Shader的核心参数如Albedo、Metallic和Smoothness,提升3D场景的质感。文章还提供了三种常见材质的参数模板和高级技巧,帮助开发者高效使用内置资源和免费纹理包。

weixin_30580341的博客 467
上一篇: hdoj2066 一个人的旅行(dijstra——floyd)
下一篇: hdoj2680 Choose the best route(dijstra)
JINKELA_
博客等级 码龄11年 75粉丝 178原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值