Gym - 101502I- Move Between Numbers (最短路)

《Data Structure And Algorithm Analysis In C++》读书笔记一 Chapter 1 Programming:A General Overview 1.1 What is This Book About? Problem. K-Selection Problem. Input a array and choose the k-th largest. User Bubble-sort #include #include void swap(i 阅读详情
/*
建立无权图:
两数间可达就连一条边;
最后求最短路即可
*/

#include <bits/stdc++.h>
using namespace std;
const int  maxn = 250 + 10;
const int inf = 0x3f3f3f3f;
int t,n,s,e,mp[maxn][maxn],common[maxn][10],dis[maxn],vis[maxn];
string str[maxn];
void init_()
{
    memset(mp,inf,sizeof mp);
    memset(common,0,sizeof common);
    memset(dis,inf,sizeof dis);
    memset(vis,0,sizeof vis);
}
void add_edge(int x,int y)
{
    int ans = 0;
    for(int i = 0 ; i  < 10; i++)
    {
        ans += min(common[x][i],common[y][i]);
    }
    if (ans == 17)
    {
        mp[x][y] = 1;
        mp[y][x] = 1;
    }
}
void Dijkstra()
{
    dis[s] = 0;
    vis[s] = 1;
    for(int i = 1; i <= n; i++)
    {
        if(i != s &&mp[s][i] < inf)
        {
            dis[i] = mp[s][i];
        }
    }
    int min_dis,u;
    while(1)
    {
        min_dis = inf;
        for(int i= 1; i <= n ; i++)
        {
            if(!vis[i] && dis[i] < min_dis)
            {
                min_dis = dis[i];
                u = i;
            }
        }
        if(min_dis == inf)
        {
            return;
        }
        vis[u] = 1;
        for(int i = 1; i <= n; i++)
        {
            if(!vis[i] && mp[u][i] == 1 && min_dis + mp[u][i] < dis[i])
            {
                dis[i] = min_dis + mp[u][i];
            }
        }
    }
}
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        init_();
        scanf("%d%d%d",&n,&s,&e);
        for(int i =1; i <= n;i++)
        {
            cin>>str[i];
            for(int  j = 0;  j < 20 ;j++)
            {
                int num = str[i][j] - '0';
                common[i][num]++;
            }
        }
        for(int i = 1; i <= n;i++)
        {
            for(int j = 1;  j <= n;j++)
            {
                add_edge(i,j);
            }
        }
        if(mp[s][e] == 1)
        {
            printf("1\n");
            continue;
        }
        Dijkstra();
        if(dis[e] == inf)
            printf("-1\n");
        else
            printf("%d\n",dis[e]);
    }
    return 0;
}

 

Numbers函数教程 Numbers函数大全,方便实用,Mac可以告别excel。Numbers函数大全,方便实用,Mac可以告别excel。 立即下载

相关推荐

Spine动画在Unity里卡顿、闪烁、排序错乱?这些性能优化与渲染问题一次讲清

本文深入解析了Spine动画在Unity中常见的卡顿、闪烁和排序错乱问题,提供了全面的性能优化与渲染解决方案。从性能瓶颈诊断到材质合并、动态合批优化,再到层级错乱与Alpha闪烁的处理,帮助开发者提升动画表现和运行效率。特别针对Unity和Spine的协同工作进行了详细的技术探讨。

weixin_29967445的博客 389

GYM 101502I. Move Between Numbers

I. Move Between Numbers time limit per test memory limit per test input output You are given n magical numbers a*1, *a*2, …, *a**n, such that the length of each of ...

WF830830的博客 251

Win10 桌面回收站右键没有“清空回收站”选项怎么解决

Win10 桌面回收站右键没有“清空回收站” 选项怎么解决? 我之前不知道怎么捣鼓注册表(胡乱删了一些。。。) 导致想清空回收站的时候,右键却没有“清空回收站”这个选项了 以下是解决方法: 1、在桌面上新建一个txt文本文档,将以下代码拷贝进去: Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\*\shell\empty] "Com...

菜鸟的后花园 2万+

Codeforces Gym101502 I.Move Between Numbers-最短路(Dijkstra优先队列版和数组版)

I. Move Between Numbers time limit per test 2.0 s memory limit per test 256 MB input standard input output standard output You are givennmagical numbersa1, a2, ...

weixin_30847271的博客 183

Linux 命令之 locale -- 设置和显示程序运行的语言环境

文章目录命令介绍locale 设置规则使用详解(一)查看当前 locale 设置(二)查看当前系统所有可用 locale(三)设置系统的 locale 命令介绍 locale 是 Linux 系统中多语言环境的设置接口,在 Linux 中,使用 locale 命令来设置和显示程序运行的语言环境,locale 会根据计算机用户所使用的语言,所在国家或者地区,以及当地的文化传统定义一个软件运行时的语言环境。 通过 locale 来设置程序运行的不同语言环境,locale 由ANSI C提供支持。locale 的

liaowenxiong的博客 3万+

FPGA远程升级避坑指南:用AXI Quad SPI IP读写N25Q128 Flash的完整流程

本文详细介绍了FPGA远程升级过程中使用AXI Quad SPI IP读写N25Q128 Flash的完整流程,包括IP核配置、Flash操作指令集、双镜像备份设计及生产级远程升级协议。通过最佳实践和避坑策略,帮助开发者实现可靠的镜像更新方案,提升系统可靠性和可维护性。

weixin_30542079的博客 684

Gym - 101502I最短路变形(2017 JUST Programming Contest 3.0 I. Move Between Numbers)

题目链接:http://codeforces.com/gym/101502/problem/I 题目: I. Move Between Numbers You are given n magical numbers a1, a2, …, an, such that the lengt...

行云出岫 791

双通道中频信号数字下变频及相位差估计(FPGA)

双通道中频信号数字下变频及相位差估计实验 一、上框图(通俗易懂) 二、实验要求 1、 用点频信号模拟中频信号:中频信号由DDS1和DDS2产生。具体产生方法见第2点。 2、 DDS1和 DDS2:调用IPcore里的数字信号处理中的NCO模块,工作时钟为100MHz,数据率即为100MHz,DDS1和DDS2的频率为:(学号后三位+500)Khz+f0(可设为20MHz);输出为16位;DDS1...

qq_39809425的博客 6955

I. Move Between Numbers

题目:http://codeforces.com/gym/101502/problem/I I. Move Between Numbers time limit per test 2.0 s memory limit per test 256 MB input standard input output standard output You are giv...

weixin_30538029的博客 136

Aspice的理解

ASPICE 是由汽车行业的主要公司和组织合作开发的,包括德国汽车工业联合会(VDA)和国际汽车工作组(Automotive SIG)。其目标是通过标准化的软件开发流程,提高汽车电子系统的软件质量和可靠性。

hkj8808的博客 2025

把冷门数据从内存里请出去:ABAP 环境下玩转 SAP HANA Native Storage Extension (NSE) 的开发者实战笔记

摘要:SAP HANA NSE技术为ABAP系统提供了一种经济高效的温数据管理方案。文章首先指出企业数据存在"温度分层"现象,高频访问的热数据需常驻内存,而低频温数据更适合存储在磁盘或闪存。NSE通过混合列存架构,将不常访问的数据移至磁盘但仍保持数据库内统一管理,显著降低内存成本。 关键实施要点包括:在ADT技术设置中将Load Unit设为"Page Enforced"以启用NSE;理解buffer cache作为数据"抽屉"的工作原理;掌握选表

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 170

2017 JUST Programming Contest 3.0 I. Move Between Numbers

I. Move Between Numbers time limit per test 2.0 s memory limit per test 256 MB input standard input output standard output You are given n magical numbers a1, a2, ..., a

Bryce1010's Blog 895

把 ABAP ALE Change Pointers 讲透:从 CDHDR/CDPOS 到 BDCP2,再到 RBDMIDOC 的自动分发链路

摘要:SAP ALE Change Pointers机制在系统集成中实现业务变更与数据分发的解耦。它记录业务对象变更(如SAP主数据修改),但不立即发送,而是由后续分发逻辑决定发送时机和方式。该机制包含两层:Change Documents记录审计级变更明细,Change Pointers标记需分发的关键变更。配置核心包括全局开关、消息类型激活和字段选择。典型应用如零售价格条件变更自动推送至POS系统,通过BDCP2表存储待处理队列,由RBDMIDOC程序定时评估生成IDoc。运维需关注定期清理和性能优化,

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 226

C++语言中std::array的神奇用法总结,你需要知道!

此文转载自:https://my.oschina.net/u/4526289/blog/4760178 大咖揭秘Java人都栽在了哪?点击免费领取《大厂面试清单》,攻克面试难关~>>> 摘要:在这篇文章里,将从各个角度介绍下std::array的用法,希望能带来一些启发。 td::array是在C++11标准中增加的STL容器,它的设计目的是提供与原生数组类似...

Python研究所 3068

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

move std 函数 示例_【译】Rust中的Move、Copy和Clone

“原文链接: https://hashrust.com/blog/moves-copies-and-clones-in-rust/原文标题: Moves, copies and clones in Rust公众号: Rust 碎碎念简介(Introduction)move 和 copy 是 Rust 中的基础概念。这对于来自 Ruby、Python 或 C#等垃圾回收语言的程序员来说可能...

weixin_28955231的博客 565

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

Gym - 101502F- Building Numbers (规律以及前缀和)

题目链接:http://codeforces.com/gym/101502/problem/F 题目: In this problem, you can build a new number starting from 1, by performing the following operations as much as you need: Add 1 to the current num...

行云出岫 842

Gym - 101502F - Building Numbers

/* 对于每个数,求出所需步骤数; 偶数除2,奇数减一; 最后利用前缀和求解 */ #include &lt;iostream&gt; #include &lt;stdio.h&gt; using namespace std; int t,n,q; long long a[100000+5]; int main() { scanf("%d",&amp;t); wh...

刘二狗的博客 310

F - Building Numbers Gym - 101502F

In this problem, you can build a new number starting from 1, by performing the following operations as much as you need: Add 1 to the current number. Add the current number to itself (i.e. multiply ...

小乔美哒哒 308

Gym - 101810 I. Split the Number(拆分差最小)

I. Split the Number time limit per test 1.0 s memory limit per test 256 MB input standard input output standard output You are given an integer x. Your task is to split the number x into exac...

碳酸钙的01妖精的博客 403

gym100812G(想法题,最短路变形,好题)

题目链接 G. Short Path time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output In my opinion, people are divided int

fouzhe的博客 738

心动C++情牵汉洛塔

/*---------------------------------------------------------------------- * Project: Hanoi.cpp * Name: zwp * Date: 2013.4 *----------------------------------------------------------------------*/

封尘浪 1144
上一篇: Gym - 101502F - Building Numbers
下一篇: Gym - 101502J - Boxes Game(dp && 博弈)
Healer66
博客等级 码龄9年 331粉丝 267原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值