Remmarguts' Date POJ - 2449

Codex入门19-数据库操作(解放双手:用自然语言写SQL、建表和数据迁移) 写 SQL 是后端开发的日常,但复杂的 JOIN、子查询、窗口函数总让人头疼。本文教你用 Codex CLI 实现:自然语言直接生成 CREATE TABLE、复杂 SQL 查询、数据库迁移脚本(Prisma/Knex/Alembic)、ORM 模型代码(SQLAlchemy/TypeORM)、甚至自动生成数据库文档。重点强调安全红线——永远不要让 AI 直接连接生产数据库。从需求描述到完整数据库层代码,一篇搞定。 阅读详情

一条通往原题的隧道(–>)

简洁题面

(其实翻译我也没看懂orz)

  • 第一行给出N(点数),M(边数)。
  • 下面的M行每行给出三个数Ai,Bi,Ti,表示从A到B有一条权值为T的单向边。
  • 最后给出S,T,K,表示求S到T的第K短路。
  • special:
    • 起点与终点相同时,S–>S (d=0) 不能算作一条路。
    • 题目会给出多组数据。
    • 即使有好几条路到T的距离都相同,它们仍被记为不同的路。

正解

A*算法
  记g[i]为起点S到i的距离,h[i](期望值)为终点T到i的最短路,用SPFA处理出来。dij从S开始处理,每次从堆中弹出h[i]+g[i]最小的点。
  当终点T被弹出第K次时,此时的g[i]即为S到T的第K短路;
下面粘代码片QwQ
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
#include<algorithm>
using namespace std;

int N,M,A,B,T,s,t,K,cnt,ans;
int h[1010],in[1010];
int first[1010],next[100010];
struct maple{
    int f,t,d;
}Rode[100010];
struct Edge{
    int num,g,h;
    bool operator <(const Edge &a)const{
    return a.h+a.g<h+g;
    }
};
void SPFA()
{
    queue<int> q;
    memset(h,63,sizeof(h));
    memset(in,0,sizeof(in));
    q.push(t);
    h[t]=0;
    in[t]=1;
    while(!q.empty())
    {
        int a=q.front();
        q.pop();
        in[a]=0;
        for(int i=first[a];i;i=next[i])
          if(h[Rode[i].t]>h[a]+Rode[i].d)
          {
             h[Rode[i].t]=h[a]+Rode[i].d;
             if(!in[Rode[i].t])
             {
                q.push(Rode[i].t);
                in[Rode[i].t]=1;
             }
          }
    }   
}
int search()
{
    if(h[s]>10000010) return -1;
    if(s==t) ++K;
    priority_queue<Edge> q;
    q.push((Edge){s,0,h[s]});
    int k=0;
    while(!q.empty())
    {
        Edge a=q.top();
        q.pop();
        if(a.num==t) 
        {
            ++k;
            if(k==K) return a.g;
        }
        for(int i=first[a.num];i;i=next[i])
          q.push((Edge){ Rode[i].t,a.g+Rode[i].d,h[Rode[i].t]});
    }
    return -1;
}
void build(int f,int t,int d)
{
    Rode[++cnt]=(maple){f,t,d};
    next[cnt]=first[f]; 
    first[f]=cnt;
}
int main()
{
    while(scanf("%d%d",&N,&M)!=EOF)
    {
        cnt=0;
        memset(first,0,sizeof(first));
        memset(next,0,sizeof(next));
        for(int i=1;i<=M;++i)
        {
            scanf("%d%d%d",&A,&B,&T);
            build(B,A,T);
        }
        scanf("%d%d%d",&s,&t,&K);
        SPFA();
        memset(first,0,sizeof(first));
        memset(next,0,sizeof(next));
        cnt=0;
        for(int i=1;i<=M;++i)
        {
            build(Rode[i].t,Rode[i].f,Rode[i].d);
        }
        ans=search();
        printf("%d\n",ans);
    }
    return 0;
} 
【SpringCloud】5、Spring Cloud Gateway网关路由规则 Spring Cloud Gateway 创建 Route 对象时, 使用 RoutePredicateFactory 创建 Predicate 对象,Predicate 对象可以赋值给 Route。 阅读详情

相关推荐

Cursor插件安装CodeX保姆级教程:从登录到调整面板布局,一步不落

本文提供Cursor编辑器安装CodeX插件的详细教程,涵盖从登录到调整面板布局的全流程。通过优化界面布局和配置参数,帮助开发者提升编码效率,特别适合需要智能代码补全的编程场景。

weixin_42648844的博客 4750

POJ-2449 Remmarguts' Date

A*第K短路算法模板题 #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 long long ll; c...

wl16wzl的博客 332

如何利用DeepSeek自动生成PLC程序?

在工业自动化领域,PLC是核心控制设备,其编程效率和质量直接影响生产线的运行效果。 然而,传统PLC编程依赖工程师手动编写代码,不仅耗时耗力,还容易出错。通过自动生成PLC程序,DeepSeek不仅大幅提升了编程效率,还优化了代码质量。 那么DeepSeek到底能否自动生成PLC程序呢? 有位电气工程师就尝试让DeepSeek设计一套五层电梯控制系统的PLC程序,下面就让我们看看吧。 技术原理:DeepSeek如何实现自动编程DeepSeek利用自然语言处理技术,将工程师输入的文本指令转换为PLC代码。例

Qinmingyue13的博客 6175

Remmarguts' Date(POJ-2449)(A*解决)

Problem Description "Good man never makes girls wait or breaks an appointment!" said the mandarin duck father. Softly touching his little ducks' head, he told them a story. "Prince Remmarguts live...

Alex_McAvoy的博客 524

S32DS IDE调试技巧:如何用Attach功能高效定位汽车电子MCU的Bootloader问题

本文详细介绍了在汽车电子MCU开发中,如何利用S32DS IDE的Attach调试模式高效定位Bootloader与应用程序的协同问题。通过对比常规调试与Attach模式的本质差异,并深入讲解工程配置、镜像合并及实战调试流程,帮助开发者在不复位、不重新下载程序的前提下,实时分析系统状态,快速解决内存映射冲突、中断向量表重定向等疑难杂症。

weixin_29168393的博客 266

MATLAB实战:利用扫频数据重构系统伯德图的关键步骤

本文详细介绍了如何利用MATLAB处理扫频数据并重构系统伯德图的完整实战流程。内容涵盖数据导入与清洗、增益与相位的精确计算、频率响应数据对象(frd)的构建、数据平滑与插值处理,以及最终生成专业伯德图并进行关键参数(如相位裕度)标注的方法。文章重点解决了从实测“黑盒子”系统数据出发,获取直观频率响应特性曲线的核心问题,为控制系统分析与设计提供了实用指南。

weixin_29098117的博客 397

Remmarguts' Date POJ - 2449

点击打开链接 K短路 存模板 #include &lt;cstdio&gt; #include &lt;queue&gt; #include &lt;cstring&gt; #include &lt;algorithm&gt; using namespace std; #define N 0x3f3f3f3f int dis[1010]; struct node1 { int v...

sunyutian1998的博客 225

CentOS 7下kkFileView 4.4.0离线部署全攻略(含LibreOffice 7.5配置避坑指南)

本文详细介绍了在CentOS 7环境下离线部署kkFileView 4.4.0的全流程,包括LibreOffice 7.5的配置避坑指南、中文字体解决方案以及企业级运维实践。通过本指南,用户可以在内网环境中快速搭建稳定可靠的文档在线预览服务,提升办公效率。

weixin_28481133的博客 288

poj2449 Remmarguts' Date

poj2449 Remmarguts’ Date

ACoder 460

【ArcGIS Pro微课1000例】0022:基于DEM进行流域分析生成流域图

填洼Fill,在进行水文分析后续操作前,首先要对DEM进行填洼,创建无凹陷点的DEM。在ArcGIS中使用的是八方向流量建模(D8算法),工具位于水文分析下的【流向】。填洼需要使用水文分析工具下的【填洼】。确定输入与输出即可。

智慧空间实验室 2750

Ansys Lumerical双层扭曲液晶偏振光栅仿真:宽角度衍射效率优化

Ansys Lumerical双层扭曲液晶偏振光栅仿真研究 摘要 本文采用Ansys Lumerical软件平台,对双层扭曲液晶偏振光栅的宽角度衍射特性进行系统仿真研究。针对6μm周期的液晶光栅结构,以1050nm、1064nm和1550nm三个近红外波段为研究对象,在±40°入射角范围内优化平均衍射效率。研究基于液晶材料的双折射特性(Δn=0.135),通过构建两层扭曲方向相反的液晶层结构,扫描0-90°单层扭曲角度和不同厚度参数,利用RCWA求解器进行严格耦合波分析~~~~~~~

huanghm88的专栏 164

POJ 2449: Remmarguts' Date

题目链接:http://poj.org/problem?id=2449 题意: 给定一个有向图, 寻找有向第K短路。 算法: 我用的是A*算法。 f[x]=g[x]+h[x]。 其中g[x]是由起点到当前节点的距离 h[x]是当前节点到终点的最短距离。 本题的边是单向的, 但是在反向SPFA处理h[x]的时候要用到反向边。 trick: s等于t的时

frog的小池塘 1335

网络安全与黑客攻防常见设备:前置机、跳板机、堡垒机与肉鸡

前置机、跳板机、堡垒机和肉鸡,这些看似冷僻的技术名词,实则是网络安全与黑客攻防战中的关键角色。它们有的守护着企业的数字Pltform,保卫网络安全;有的则成为黑客的跳板,游走于灰色地带。

网络技术联盟站 962

poj 2449 Remmarguts' Date

Remmarguts' Date Time Limit:4000MS Memory Limit:65536K Total Submissions:30658 Accepted:8378 Description "Good man never makes girls wait or breaks an appointm...

HJ921004的博客 202

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

POJ 2449 Remmarguts' Date

Description "Good man never makes girls wait or breaks an appointment!" said the mandarin duck father. Softly touching his little ducks' head, he told them a story.  "Prince Remmarguts lives i

超 834

深度学习工具包 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")

POJ2449 Remmarguts' Date

A*+Dijkstra=Kth-shortest-path概述这道题好久之前写的.. 因为坚持写博客有好处,而且zrt犇留的作业里也有这道题,所以还是决定了要重温下这道题的解法 http://paste.ubuntu.com/15574067/ 裸的第k短路么.. A*加反向图的单源(当估价)解。 第几次从队列里弹出点i,则就找到了点i的第几短路终止条件必要性和合理性题目出题者不会总是很善

guozizheng001的博客 549

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

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

POJ2449Remmarguts' Date(A*算法)

原题链接:http://poj.org/problem?id=2449 Remmarguts’ Date Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 42272 Accepted: 11687 Description “Good man never makes girls wait or breaks an appoin...

Shaosen的博客 347

poj 2449 Remmarguts' Date(第K短路)

poj 2449 Remmarguts’ DateDescription“Good man never makes girls wait or breaks an appointment!” said the mandarin duck father. Softly touching his little ducks’ head, he told them a story. “Prince Remm

Loi_feather的博客 499

【POJ 2449】 Remmarguts' Date

【题目链接】 http://poj.org/problem?id=2449 【算法】 A*(启发式搜索) 首先,求第k短路可以用优先队列BFS实现,当T第k次入队时,就求得了第k短路,但是,这种做法的复杂度太高 考虑使用A*算法,每个点的估价函数就是这个点到T的最短路,不妨将所有的边...

78

poj2449 Remmarguts' Date A*K短路

K短路

Elemmir的博客 1088

poj2449 Remmarguts' Date A*搜索

A*搜索主要思想:f[i] = g[i] + h[i] 。f[i] 即为所求,g[i] 表示已走过距离,h[i] 表示距离终点的距离。在优先队列中,能尽量把符合条件的方案提前,优化搜索。 对于这道题,先反向建边,求出每个点到终点的最短距离。 再正向搜索,所要记录的内容有:当前节点,已走过了距离,已走过的距离+这点到终点的距离。 每次把与这点相连的下一个点放入队列,直到第k次取出终点,便求出第

KatnissJ的博客 640

POJ 2449 Remmarguts' Date A*算法

求第K短路径。在A*算法中,求最短路径时,当从优先级队列中取到目的节点时就结束了,为了求K短路径,则不结束,继续从优先级队列中取节点,直到第K次取到目的节点就是第K短路径。为了使用A*算法,首先要得到启发函数 f(n)=g(n)+h(n), 其中f(n) 是从初始点经由节点n到目标点的估价函数,g(n) 是在状态空间中从初始节点到n节点的实际代价,g(n)可以在A*算法过程中得到,h(n)是从n到目标节点最佳路径的估计代价,也就是目标节点到其他所有节点的距离,需要通过其他算法(如Dijkstra、Spfa)

mimo9527的专栏 1323

[POJ]2449. Remmarguts' Date

这道题是求一个有向图上的第k短路。这时,可以采用A*搜索,也就是启发式搜索的办法。所谓启发式搜索,是在搜索的时候设置一个启发式函数,以此来确定搜索的顺序,,从而减少无用功。     本题中,启发函数为f(x) = distance_traveled(x) + distance_remaining(x). 前者为搜索到x点时已经走过的路程,后者为到终点还剩的路程。可以在A*搜索之前把后者先全部预处

Jerry I. Huang 726
上一篇: 线段树练习5
下一篇: 玉蟾宫(单调栈+悬线法) codevs 2491
Loi_Mapleleaf
博客等级 码龄10年 17粉丝 72原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值