Invitation Cards(最短路)

28-手把手教你手写CPU-Verilog - 乘法器设计:Booth算法与Wallace树乘法器 文章摘要: 本文详细介绍了两种高效乘法器设计方法:Booth算法和Wallace树乘法器。Booth算法通过检测乘数连续1/0减少部分积,适合有符号数运算;Wallace树采用树形结构压缩部分积,显著降低延迟。文章包含算法原理、具体示例、Verilog实现代码(4位乘法器)及性能对比表,指出Booth适用于通用处理器,Wallace树更适合高性能DSP/GPU。最后强调实际设计中需根据速度、面积和功耗需求选择合适方案。 阅读详情

Description
In the age of television, not many people attend theater performances. Antique Comedians of Malidinesia are aware of this fact. They want to propagate theater and, most of all, Antique Comedies. They have printed invitation cards with all the necessary information and with the programme. A lot of students were hired to distribute these invitations among the people. Each student volunteer has assigned exactly one bus stop and he or she stays there the whole day and gives invitation to people travelling by bus. A special course was taken where students learned how to influence people and what is the difference between influencing and robbery.

The transport system is very special: all lines are unidirectional and connect exactly two stops. Buses leave the originating stop with passangers each half an hour. After reaching the destination stop they return empty to the originating stop, where they wait until the next full half an hour, e.g. X:00 or X:30, where ‘X’ denotes the hour. The fee for transport between two stops is given by special tables and is payable on the spot. The lines are planned in such a way, that each round trip (i.e. a journey starting and finishing at the same stop) passes through a Central Checkpoint Stop (CCS) where each passenger has to pass a thorough check including body scan.

All the ACM student members leave the CCS each morning. Each volunteer is to move to one predetermined stop to invite passengers. There are as many volunteers as stops. At the end of the day, all students travel back to CCS. You are to write a computer program that helps ACM to minimize the amount of money to pay every day for the transport of their employees.
Input
The input consists of N cases. The first line of the input contains only positive integer N. Then follow the cases. Each case begins with a line containing exactly two integers P and Q, 1 <= P,Q <= 1000000. P is the number of stops including CCS and Q the number of bus lines. Then there are Q lines, each describing one bus line. Each of the lines contains exactly three numbers - the originating stop, the destination stop and the price. The CCS is designated by number 1. Prices are positive integers the sum of which is smaller than 1000000000. You can also assume it is always possible to get from any stop to any other stop.
Output
For each case, print one line containing the minimum amount of money to be paid each day by ACM for the travel costs of its volunteers.
Sample Input
2
2 2
1 2 13
2 1 33
4 6
1 2 10
2 1 60
1 3 20
3 4 10
2 4 5
4 1 50
Sample Output
46
210
这题也是读了半天,就是一堆人从1出发,到其他的点,然后从其他的点再回来,最短距离。和之前那个牛聚会题目一样,两次spfa。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 1005;
int head[1000005],p,q;
bool leap[1000005];
ll d[1000005];
struct Node
{
    int u,v,w,next;
}node[1000005];
void add_edge(int u,int v,int w,int tot)
{
    node[tot].u = u;
    node[tot].v = v;
    node[tot].w = w;
    node[tot].next = head[u];
    head[u] = tot;
}
void spfa()
{
    queue<int>qe;
    qe.push(1);
    for(int i = 1;i <= p;i++)leap[i] = false;
    for(int i = 1;i <= p;i++)d[i] = inf;
    d[1] = 0;leap[1] = true;
    while(qe.size())
    {
        int u = qe.front();qe.pop();
        leap[u] = false;
        for(int i = head[u];i != -1;i = node[i].next)
        {
            int e = node[i].v;
            if(d[e] > d[u] + node[i].w)
            {
                d[e] = d[u] + node[i].w;
                if(!leap[e])
                {
                    leap[e] = true;qe.push(e);
                }
            }
        }
    }
}
int main()
{
    #ifdef LOCAL
    freopen("C:\\Users\\巍巍\\Desktop\\in.txt","r",stdin);
    //freopen("C:\\Users\\巍巍\\Desktop\\out.txt","w",stdout);
    #endif // LOCAL
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&p,&q);
        memset(head,-1,sizeof(head));
        for(int i = 1;i <= q;i++)
        {
            int u,v,w;
            scanf("%d%d%d",&u,&v,&w);
            add_edge(u,v,w,i);
        }
        spfa();
        ll ans = 0;
        for(int i = 2;i <= p;i++)
            ans += d[i];
        memset(head,-1,sizeof(head));
        for(int i = 1;i <= q;i++)
        {
            add_edge(node[i].v,node[i].u,node[i].w,i);
        }
        spfa();
        for(int i = 2;i <= p;i++)
            ans += d[i];
        printf("%lld\n",ans);
    }
    return 0;
}
ROS从入门到精通0-4:VSCode 搭建 ROS 工程环境 为了提高开发效率,可以先安装集成开发工具和使用方便的工具,本教程用VSCode搭建ROS工程环境 阅读详情

相关推荐

keil自动分配SDRAM空间设置使用

1.修改.sct文件。

qizhi321123的博客 1404

HDU1535 Invitation Cards(链式前向星+堆优化dijkstra)[C++]

目录题目及翻译题面输入输出输入样例输出样例题目思路注意事项AC代码C++ 题目及翻译 题面 In the age of television, not many people attend theater performances. Antique Comedians of Malidinesia are aware of this fact. They want to propagate the...

扶她小藜 643

每天一个优秀提示词学习收藏 - 文本去AI化(四)

宝子们,今天不藏私啦!我把这段时间四处搜罗、潜心钻研出来的文本去AI化Prompt 提示词大礼包双手奉上,这可都是能让你的 AI 创作水平原地起飞的干货!走过路过不要错过,赶紧码住,开启你的 AI 创作进阶之旅吧!

2444

[最短路spfa]pku1511-Invitation Cards

http://acm.pku.edu.cn/JudgeOnline/problem?id=1511 Invitation CardsTime Limit: 8000MS Memory Limit: 262144KTotal Submissions: 5784 Accepted: 1616DescriptionIn th

幻想の天地 713

Android11,无障碍服务模拟多手势使用dispatchGesture时总是onCancelled

AccessibilityService的dispatchGesture去模拟多手势,总是onCancelled的一种解决办法

m0_49953943的博客 2102

SPARTAN6 + Verilog - FPGA step by step 从0开始学习(1)

SPARTAN6 + Verilog - FPGA step by step 从0开始学习(1)Step 1 软件安装Step 2 硬件获取Step 3 开始从头到脚建一个工程Step 3.1 新建一个工程 从0开始学习FPGA,最好的办法就是先建一个最简单的模块,并且跑起来,然后再慢慢展开。下面这个例子是要按照一定的周期点亮核心板上的一个led。 Step 1 软件安装 这个从0开始学习是用的xilinx的SPARTAN6。SPARTAN6集成开发环境用ISE,不能用Vivado,各自对应的版本不同。安装

xfacexx点点记录 5508

最短路dijkstra—Invitation Cards(POJ-1511)

题目链接:>_> 题目:Invitation Cards In the age of television, not many people attend theater performances. Antique Comedians of Malidinesia are aware of this fact. They want to propagate theater and, m...

Darge. 287

速腾聚创多激光雷达点云采集,并用RVIZ进行显示

在ubuntu20.04系统下,使用速腾聚创官方提供的软件RSView,对激光雷达的默认IP地址、MSOP 包端口号、 DIFOP包端口号和时间模式等配置进行查看和修改。使用交换机对两个激光雷达进行组网,实现多激光雷达数据采集,并用RVIZ同时显示两个雷达点云。使用wireshark对比两个雷达数据包。

abanchao的博客 5887

hdu 1535 Invitation Cards(spfa)

小记:这题还是要理解了题意就好做了

ljd4305的专栏 991

大数据知识面试题-Hadoop(2022版)

序列号 内容 链接 1 大数据知识面试题-通用(2022版) 待续… 2 大数据知识面试题-Hadoop(2022版) 待续… 3 大数据知识面试题-MapReduce和yarn(2022版) 待续… 4 大数据知识面试题-Zookeepr (2022版) 待续… 5 大数据知识面试题-Hive (2022版) 待续… 6 大数据知识面试题-Flume(2022版) 待续… 7 大数据知识面试题-Hbase(2022版) 待续… 8 大数据知识面试题-sqoop(....

拉格朗日的学习笔记 1万+

【2022网易雷火】游戏研发笔试-AC代码及题目分享

3个小时,4道题目,雷火的题目不在于难,更在于对细节的把控和写大模拟的耐心,花了一个半小时,AC了3.85,直接交卷退了。第一题AC,第二题AC,第三题85%,第四题AC。下面分享一下大致的题意和对应的代码,就不多说了,最近很累(代码可能会有贴错的情况,如有望指正,感谢~)。 T1-小Y抽奖 题意 n行m列个奖励格子,每次抽奖消耗一个道具。每个格子奖励的数量有限且各不相司。每个格子被抽到一次,剩余的奖励数量-1。剩余的奖励数量为0时,则不会再抽到该格子。小Y抽了好多次,但一直没有抽到最想要的..

米莱虾 9265

HDU - 1535 Invitation Cards

题目: In the age of television, not many people attend theater performances. Antique Comedians of Malidinesia are aware of this fact. They want to propagate theater and, most of all, Antique Comedies. T...

qq_41998938的博客 192

小论文/大论文必备| YOLO26热力图可视化,支持8种常用热力图方法:GradCAM,GradCAMPlusPlus,XGradCAM,EigenCAM,HiResCAM等,助力小论文和大论文加分

本文介绍了如何为YOLO26模型添加热力图可视化功能,包括完整代码和使用教程。热力图能增强模型的可解释性,适用于论文中的实验对比和结果展示。文章提供了详细的代码实现,包含图像处理、热力图生成和结果可视化等功能,并指导用户如何创建Python文件、粘贴代码以及调整参数生成最佳热力图。通过设置不同层号,用户可以灵活控制热力图效果,最终结果将保存在指定文件夹中。

Ai缝合怪、助力小伙伴高效发论文 490

【题解】Invitation Cards POJ - 1511 ⭐⭐⭐ 【多源到单点最短路】

Invitation Cards POJ - 1511 B208的小姐姐们想去学校各地宣传ACM,但是让小姐姐们跑太远的路总是不太好的,因此麻烦G学长帮小姐姐们计算一下,小姐姐们到各地宣传再回到B208的最短路径总和是多少。 已知:学校一共有n个宣传点,B208是标号为1的点。剩下n-1个点每个点各派1位小姐姐,询问每个小姐姐到达宣传点再回到B208的最短路径和是多少。 Input 输入由T个案例...

Suprit's blog 732

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

HDU - 1535 Invitation Cards (最短路dijkstra)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1535点击打开链接 Invitation Cards Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 4465    Acce

xuejye的博客 368

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

POJ1511 Invitation Cards SPFS最短路算法

http://poj.org/problem?id=1511 题意:给出n个点和m条有向边,问从1号点到各点和从这些点回来的总路程最小值。 先以1为源点进行spfs计算各点最短路径,再将所有边反向(可以直接建立两个图),再次以1为源点进行spfs计算最短路径,将所有路径长度相加。 //Memory: 24664KTime : 2016MS #include&lt;iostream...

Yerkeys的博客 272

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

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

pwndbg安装与实战指南:提升GDB漏洞挖掘效率

在软件安全与逆向工程领域,调试器是分析程序行为、定位漏洞的核心工具。GDB作为Linux环境下的标准调试器,其原生命令行界面在分析复杂内存漏洞时信息分散,操作繁琐。pwndbg作为一款强大的GDB增强插件,通过Python深度集成,从根本上优化了调试体验。其技术价值在于将堆可视化、内存布局高亮、ROP gadget搜索等逆向工程常用功能,整合到一个信息密集的视图中,实现了调试信息的上下文集中展示。这显著提升了在分析缓冲区溢出、堆漏洞等安全问题时的工作效率。应用场景广泛覆盖CTF竞赛、漏洞研究、恶意代码分析等

weixin_33894640的博客 302

Invitation Cards——正反最短路

poj 1511: Invitation Cards 题意:点1到其他点的最短距离+其他点到点1的最短距离 的总和。 1.双向建图 正向建图是1到其他点的距离,反向建图则是其他点到1的距离。 2.数据比较多利用邻接表存图。 3.大量数据输入利用scanf 4.正反跑两边最短路模板即可。 spfa #define __ ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #include<iostream> #include&

睡醒继续做梦的博客 265

HDU 1535 Invitation Cards(最短路)

题目读了半天,发现是从1到 2 ~n个点再从 2 ~n个点回到1的最短路。。 所以正向反向分别建图,跑最短路就好了。 #include <algorithm> #include <queue> #include <cstring> #include <iostream> using namespace std; typ...

banmen2664的博客 188

poj 1511 Invitation Cards(最短路)

题目链接 Invitation Cards Time Limit: 8000MS   Memory Limit: 262144K Total Submissions: 25583   Accepted: 8472 Description In the age of television, not many people at

fouzhe的博客 350

Invitation Cards(链式前向星存图+最短路)

原题链接https://vjudge.net/contest/356222#problem/J 题意为有n个点,给出单向路径,求1到每个点的最短路以及回到1的最短路。 根据题意可以知道,n的值<=1000000,此时二维数组显然不能用来存图了,在这里使用链式前向星存图。 链式前向星存图: struct node { long long v;//终点 long long w;//权值 l...

yeyuluo的博客 426

SDUT- Invitation Cards(最短路 spfa)

In the age of television, not many people attend theater performances. Antique Comedians of Malidinesia are aware of this fact. They want to propagate theater and, most of all, Antique Comedies. They ...

qq_43588832的博客 174

hdu 1535 Invitation Cards(最短路)

题意:给出n个点的有向图,要求求出从源点1到各个点的最短路的和与从各个点到1的最短路的和。 思路:这题还蛮巧妙的,从源点到各个点的最短路好求,至于其它点到源点的最短路可以反向建图,然后再从源点开始做个最短路就行了,这样就相当于从源点“倒着走”走到所有点。   代码: #include #include #include #include #include #include #include

绝望的乐园 808

【图论】【最短路】 pku1511 Invitation Cards

【题目】:Invitation Cards【类型】:图论【难度】:中等【来源】:pku1511【关键字】:SPFA【题目大意】:给N个点的路径信息,给定一个点作为起点,求该点到每个点再回来总路程最小值。 --------------------------------------------------------------------------------------

mofixroot的专栏 603

(最短路)Invitation Cards

In the age of television, not many people attend theater performances. Antique Comedians of Malidinesia are aware of this fact. They want to propagate theater and, most of all, Antique Comedies. They ...

zufe_cst的博客 320

HDOJ 1535 Invitation Cards 【最短路 SPFA】

Invitation Cards Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 2804    Accepted Submission(s): 1328 Problem Description In the a

jianjun的专栏 561
上一篇: Arbitrage(bellman-Ford)
下一篇: Foul Play(决策+递归)
Techay
博客等级 码龄11年 11粉丝 174原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值