POJ(3159):Candies(最短路)

Time Limit: 1500MS Memory Limit: 131072K
Total Submissions: 37837 Accepted: 10648

Description

During the kindergarten days, flymouse was the monitor of his class. Occasionally the head-teacher brought the kids of flymouse’s class a large bag of candies and had flymouse distribute them. All the kids loved candies very much and often compared the numbers of candies they got with others. A kid A could had the idea that though it might be the case that another kid B was better than him in some aspect and therefore had a reason for deserving more candies than he did, he should never get a certain number of candies fewer than B did no matter how many candies he actually got, otherwise he would feel dissatisfied and go to the head-teacher to complain about flymouse’s biased distribution.

snoopy shared class with flymouse at that time. flymouse always compared the number of his candies with that of snoopy’s. He wanted to make the difference between the numbers as large as possible while keeping every kid satisfied. Now he had just got another bag of candies from the head-teacher, what was the largest difference he could make out of it?

Input

The input contains a single test cases. The test cases starts with a line with two integers N and M not exceeding 30 000 and 150 000 respectively. N is the number of kids in the class and the kids were numbered 1 through N. snoopy and flymouse were always numbered 1 and N. Then follow Mlines each holding three integers AB and c in order, meaning that kid A believed that kid B should never get over c candies more than he did.

Output

Output one line with only the largest difference desired. The difference is guaranteed to be finite.

Sample Input

2 2
1 2 5
2 1 4

Sample Output

5

Hint

32-bit signed integer type is capable of doing all arithmetic.

Source

POJ Monthly--2006.12.31, Sempr

题目大意:

n个人,m个信息,每行的信息是3个数字,A,B,C,表示B比A多出来的糖果不超过C个,问你,n号人最多比1号人多几个糖果。

解题思路:

Dijkstra算法(不适用于有负权边的情况):

如(1-2用Dijkstra算法得到的结果为3)

基本思想:

解决无负权边的带权有向图或无向图的单源最短路问题贪心思想,若离源点s前k-1近的点已经被确定,构成点集P那么从s到离s第k近的点t的最短路径,{s,p 1 ,p 2 …p i ,t}满足s,p 1 ,p 2 …p i ∈P。
 否则假设pi∉P,则因为边权非负,pi到t的路径≥0,则d[pi]≤d[t],pi才是第k近。将pi看作t,重复上面过程,最终一定会有找不pi的情况
 d[i]=min(d[p i ]+cost(p i ,i)),i∉P,p i ∈Pd[t]=min(d[i]) ,i∉P

 

初始令d[s]=0,d[i]=+∞,P=∅ 找到点i∉P,且d[i]最小把i添入P,对于任意j∉P,若d[i]+cost(i,j)<d[j],则更新d[j]=d[i]+cost(i,j)。

#include<cstdio>
#include<iostream>
#include<vector>
#include<cstring>
#include<queue>

using namespace std;

struct CNode{
    int k;
    int w;
    bool operator<(const CNode&C)const{
        return w > C.w;
    }
    CNode(int kk = 0,int ww = 0):k(kk),w(ww) {}
};
priority_queue<CNode> pq;
bool bUsed[30010];
vector<vector<CNode> >v;
const int inf = 1<<30;

int main(){
    int N,M,a,b,c;
    CNode p;
    scanf("%d%d",&N,&M);
    v.clear();
    v.resize(N+1);
    memset(bUsed,0,sizeof(bUsed));
    for(int i = 1;i <= M;i++){
        scanf("%d%d%d",&a,&b,&c);
        p.k = b;
        p.w = c;
        v[a].push_back(p);
    }
    pq.push(CNode(1,0));
    while(!pq.empty()){
        p = pq.top();
        pq.pop();
        if(bUsed[p.k]) //已求出最短路 
            continue;
        bUsed[p.k] = true;
        if(p.k == N)  //求1-n的距离,所以p.k等于N break;
            break;
        for(int i = 0,j = v[p.k].size();i <j;i++){ //找所有的点到顶点1的距离(例:1—2—3。3-1的权值=3-2的权值 + 2-1的权值)
            CNode q;
            q.k = v[p.k][i].k;
            if(bUsed[q.k])
                continue;
            q.w = p.w+v[p.k][i].w;  
            pq.push(q);
        }
    }
    printf("%d",p.w);
    return 0;
}

 

已标记关键词 清除标记
相关推荐
<p>本套课程适用于有一定的<span style="color: #e03e2d;">iOS、Android、Flutter</span>开发基础。</p> <p>学完本次课程,能够让大家对Flutter如何调用移动端原生页面有一个清晰的认识;在纯Flutter开发过程中遇到需要调用原生功能的时候,能够快速定制属于自己或者公司的私有插件- Plugin。</p> <p>课程一共氛围两部分:</p> <p>1、Flutter插件跟iOS的交互部分:包括调用iOS原生页面、如何使用iOS的<span style="color: #e03e2d;">framework二进制</span>、<span style="color: #e03e2d;">bundle资源文件</span>、依赖的cocoapods资源;</p> <p>2、Flutter插件跟安卓的交互部分:包括调用Android原生页面、如何接收原生页面的回调、如何使用aar文件、依赖的其他资源。</p> <p>最终能够帮助大家定制私有插件;提升工作技能。</p> <p><span style="color: #e03e2d;">备注:课程中使用环境</span></p> <p style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: 'Andale Mono'; color: #2fff12; background-color: rgba(0, 0, 0, 0.9);"><span style="font-variant-ligatures: no-common-ligatures; color: #2fb41d;">[✓]</span><span style="font-variant-ligatures: no-common-ligatures;"> Flutter (Channel stable, 1.22.5, on macOS 11.0.1 20B29 darwin-arm, locale zh-Hans-CN)</span></p> <p style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: 'Andale Mono'; color: #2fff12; background-color: rgba(0, 0, 0, 0.9); min-height: 14px;"><span style="font-variant-ligatures: no-common-ligatures;"> </span></p> <p style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: 'Andale Mono'; color: #2fff12; background-color: rgba(0, 0, 0, 0.9);"><span style="font-variant-ligatures: no-common-ligatures; color: #9fa01c;">[!]</span><span style="font-variant-ligatures: no-common-ligatures;"> Android toolchain - develop for Android devices (Android SDK version 30.0.3)</span></p> <p style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: 'Andale Mono'; color: #00ff00; background-color: rgba(0, 0, 0, 0.9);"><span style="font-variant-ligatures: no-common-ligatures;">    </span><span style="font-variant-ligatures: no-common-ligatures; color: #9fa01c;">!</span><span style="font-variant-ligatures: no-common-ligatures;"> Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses</span></p> <p style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: 'Andale Mono'; color: #2fff12; background-color: rgba(0, 0, 0, 0.9);"><span style="font-variant-ligatures: no-common-ligatures; color: #2fb41d;">[✓]</span><span style="font-variant-ligatures: no-common-ligatures;"> Xcode - develop for iOS and macOS (Xcode 12.2)</span></p> <p style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: 'Andale Mono'; color: #2fff12; background-color: rgba(0, 0, 0, 0.9);"><span style="font-variant-ligatures: no-common-ligatures; color: #9fa01c;">[!]</span><span style="font-variant-ligatures: no-common-ligatures;"> Android Studio (version 4.1)</span></p> <p style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: 'Andale Mono'; color: #2fff12; background-color: rgba(0, 0, 0, 0.9);"><span style="font-variant-ligatures: no-common-ligatures; color: #2fb41d;">[✓]</span><span style="font-variant-ligatures: no-common-ligatures;"> IntelliJ IDEA Community Edition (version 2020.3)</span></p> <p style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: 'Andale Mono'; color: #2fff12; background-color: rgba(0, 0, 0, 0.9);"><span style="font-variant-ligatures: no-common-ligatures; color: #2fb41d;">[✓]</span><span style="font-variant-ligatures: no-common-ligatures;"> Connected device (1 available)</span></p> <p style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: 'Andale Mono'; color: #2fff12; background-color: rgba(0, 0, 0, 0.9); min-height: 14px;"> </p> <p style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: 'Andale Mono'; color: #2fff12; background-color: rgba(0, 0, 0, 0.9);"> </p>
<p style="word-break: break-all; margin: 0px; padding: 0px; overflow-wrap: break-word; color: #666666; font-family: Verdana, 'Microsoft YaHei', 宋体; font-size: 14px; background-color: #ffffff;"><strong style="word-break: break-all;">本课程为Django第六季课程:</strong>后台管理的项目实战, 本项目主要实现基本的学生管理,包含的主要知识点有:virtualenv虚拟环境、pip下载包、多app项目开发、templates模板的继承、font-awesome图标的使用、原生SQL语句和数据库交互、ORM模型和数据库交互、LayUI页面布局、jQuery实现用户交互、Ajax的异步请求、页面的块状展示数据、表格展示数据、表格的分页、数据的增改删改、Layer弹出层使用、表单的验证等等知识点。</p> <p style="word-break: break-all; margin: 0px; padding: 0px; overflow-wrap: break-word; color: #666666; font-family: Verdana, 'Microsoft YaHei', 宋体; font-size: 14px; background-color: #ffffff;"> </p> <p style="word-break: break-all; margin: 0px; padding: 0px; overflow-wrap: break-word; color: #666666; font-family: Verdana, 'Microsoft YaHei', 宋体; font-size: 14px; background-color: #ffffff;">本案例完整的演示了项目实现过程,虽然不复杂,但涉及的内容非常多,特别是前后端交互的时候,有诸多的坑等着你去踩,好在王老师全程代码呈现,带着大家一起填坑,大大提高学习效率的同时,也培养了大家良好的代码习惯,希望大家一致跟着王老师学习Python开发。</p> <p style="word-break: break-all; margin: 0px; padding: 0px; overflow-wrap: break-word; color: #666666; font-family: Verdana, 'Microsoft YaHei', 宋体; font-size: 14px; background-color: #ffffff;"> </p> <p style="word-break: break-all; margin: 0px; padding: 0px; overflow-wrap: break-word; color: #666666; font-family: Verdana, 'Microsoft YaHei', 宋体; font-size: 14px; background-color: #ffffff;"> </p> <p style="word-break: break-all; margin: 0px; padding: 0px; overflow-wrap: break-word; color: #666666; font-family: Verdana, 'Microsoft YaHei', 宋体; font-size: 14px; background-color: #ffffff;"> </p> <p style="word-break: break-all; margin: 0px; padding: 0px; overflow-wrap: break-word; color: #666666; font-family: Verdana, 'Microsoft YaHei', 宋体; font-size: 14px; background-color: #ffffff;"><span style="word-break: break-all;"><span style="word-break: break-all; color: #ff0000;"><strong style="word-break: break-all;">课程目标:</strong></span><br style="word-break: break-all;" /><span style="word-break: break-all;">本系列课程是从零基础开始并深入讲解Django,最终学会使用Django框架开发企业级的项目。课程知识点详细,项目实战贴近企业需求。本系列课程除了非常详细的讲解Django框架本身的知识点以外,还讲解了web开发中所需要用到的技术,学完本系列课程后,您将独立做出一个具有后台管理系统,并且前端非常优美实用的网站。对于从事一份Python Web开发相关的工作简直轻而易举。</span></span></p> <p style="word-break: break-all; margin: 0px; padding: 0px; overflow-wrap: break-word; color: #666666; font-family: Verdana, 'Microsoft YaHei', 宋体; font-size: 14px; background-color: #ffffff;"> </p> <p style="word-break: break-all; margin: 0px; padding: 0px; overflow-wrap: break-word; color: #666666; font-family: Verdana, 'Microsoft YaHei', 宋体; font-size: 14px; background-color: #ffffff;"> </p> <p style="word-break: break-all; margin: 0px; padding: 0px; overflow-wrap: break-word; color: #666666; font-family: Verdana, 'Microsoft YaHei', 宋体; font-size: 14px; background-color: #ffffff;"><span style="word-break: break-all;"><span style="word-break: break-all;"><img src="https://img-bss.csdnimg.cn/202102061554519299.png" alt="" /></span></span></p>
<p> <img src="https://img-bss.csdn.net/201909231423115500.png" alt="" /> </p> <p> <img src="https://img-bss.csdn.net/201909231423337403.png" alt="" /> </p> <p> <img src="https://img-bss.csdn.net/201909231423434581.png" alt="" /> </p> <p> <img src="https://img-bss.csdn.net/201909231424065321.png" alt="" /><img src="https://img-bss.csdn.net/201909231424244483.png" alt="" /> </p> <p> <br /> </p> <p> <br /> </p> <div style="color:#444444;"> 适用人群 <p style="color:#666666;"> Java开发人员,Vue开发人员,前后端分离开发人员,权限管理和配置开发人员 </p> </div> <div style="color:#444444;"> 课程概述 <div style="color:#666666;"> 【讲师介绍】<br />       现某知名大型互联网公司资深架构师,技术总监,职业规划师,首席面试官,曾在某上市培训机构,高校任教多年。<br />      Array(Array老师)10多年互联网公司实战经验,知名的大型互联网公司的架构师,高管等职,在企业长期从事于技术的源码阅读和新技术的研究;擅长于职业规划,面试辅导,从事面试官多年 <br /> 技术选型<br /> 开发环境:Eclipse/Idea ,JDK 1.8以上 <br /> 后端技术<br /> 核心框架:SpringBoot2.x框架系列(同样适用Springcloud F版本以后的版本),如下(节选):    <br /> 持久层框架:MyBatis 3.x + Mybatis-plus 3.x<br /> 日志管理:SLF4J 1.7 + Log4j2 2.7<br /> 工具类:Apache Commons、Jackson 、fastjson、Gson<br /> 权限验证<br /> 前端技术  <br /> Vue  <br /> Vue-cli<br /> ElementUI ---https://element.eleme.io/<br /> JSX (JavaScript Xml)<br /> 前台的权限验证和路由设置<br /> 开发模式  <br />      前后端分离的开发<br /> 数据库 <br />       Mysql5<br /> IDE<br />     Intellij Idea<br /> 【课程收益】<br /> 学完课程能独立完成springboot2+vue+elementUI的整合项目开发(前后端分离) <br /> 学完课程能Shiro的权限控制,按钮级别的权限控制 <br /> 学完课程能独立后端开发和独立前端开发Vue <br /> 学完课程能快速的掌握目前互联网用的前沿的框架和技术实战 </div> </div>
<p class="MsoNormal"> <span style="font-family:'微软雅黑',sans-serif;">YOLO</span><span style="font-family:'微软雅黑',sans-serif;">系列是基于深度学习的端到端实时目标检测方法。 <span>PyTorch</span>版的<span>YOLOv5</span>轻量而性能高,更加灵活和便利。</span><span style="font-family:微软雅黑, sans-serif;"> </span> </p> <p class="MsoNormal"> <span style="font-family:'微软雅黑',sans-serif;">本课程将手把手地教大家使用<span>labelImg</span>标注和使用<span>YOLOv5</span>训练自己的数据集。课程实战分为两个项目:单目标检测(足球目标检测)和多目标检测(足球和梅西同时检测)。</span><span style="font-family:微软雅黑, sans-serif;"> </span> </p> <p class="MsoNormal"> <span style="font-family:'微软雅黑',sans-serif;">本课程的<span>YOLOv5</span>使用<span>ultralytics/yolov5</span>,在<span style="color:#e03e2d;"><strong><span>Windows</span></strong></span>系统上做项目演示。包括:安装<span>YOLOv5</span>、标注自己的数据集、准备自己的数据集、修改配置文件、训练自己的数据集、测试训练出的网络模型和性能统计。</span><span style="font-family:微软雅黑, sans-serif;"> </span> </p> <p class="MsoNormal"> <span style="font-family:微软雅黑, sans-serif;">希望学习Ubuntu上演示的同学,请前往 </span><span style="font-family:微软雅黑, sans-serif;">《</span><span style="font-family:微软雅黑, sans-serif;">YOLOv5(PyTorch)</span><span style="font-family:微软雅黑, sans-serif;">实战:训练自己的数据集(Ubuntu)》课程链接:https://edu.csdn.net/course/detail/30793</span><span style="font-family:宋体;"><span style="font-size:14px;"> </span></span> </p> <p style="margin-left:0cm;">   </p> <p style="margin-left:0cm;"> 本人推出了有关YOLOv5目标检测的系列课程。请持续关注该系列的其它视频课程,包括: </p> <p> 《YOLOv5(PyTorch)目标检测实战:训练自己的数据集》 </p> <p> Ubuntu系统 <strong><a href="https://edu.csdn.net/course/detail/30793"><span style="color:#7c79e5;">https://edu.csdn.net/course/detail/30793</span></a></strong> </p> <p> Windows系统 <strong><a href="https://edu.csdn.net/course/detail/30923"><span style="color:#7c79e5;">https://edu.csdn.net/course/detail/30923</span></a></strong> </p> <p> 《YOLOv5(PyTorch)目标检测:原理与源码解析》<strong><a href="https://edu.csdn.net/course/detail/31428"><span style="color:#7c79e5;">https://edu.csdn.net/course/detail/31428</span></a></strong> </p> <p> 《YOLOv5(PyTorch)目标检测实战:Flask Web部署》<strong><a href="https://edu.csdn.net/course/detail/31087"><span style="color:#7c79e5;">https://edu.csdn.net/course/detail/31087</span></a></strong> </p> <p> 《YOLOv5(PyTorch)目标检测实战:TensorRT加速部署》<strong><a href="https://edu.csdn.net/course/detail/32303"><span style="color:#7c79e5;">https://edu.csdn.net/course/detail/32303</span></a></strong> </p> <p> <img src="https://img-bss.csdnimg.cn/202010090636458614.jpg" alt="课程内容" width="880" height="356" /> </p> <p> <img src="https://img-bss.csdnimg.cn/202010090637068681.jpg" alt="技巧" width="880" height="706" /> </p> <p> <img src="https://img-bss.csdnimg.cn/202010090637267536.jpg" alt="功能" width="880" height="913" /> </p>
<p> <span style="color:#E53333;font-size:24px;"><strong>主要内容</strong></span> </p> <p> 掌握MyBatis的常用配置,MyBatis的Mapper映射文件的编写,包含select, update, insert和delete,MyBatis映射文件 </p> 之parameters和@Param注解,MyBatis映射文件的resultMap的使用,MyBatis映射之association(一对一)配置与使用,<br /> MyBatis映射之collection(一对多)配置与使用,MyBatis映射之association与collection的复杂使用(一对一与一对多同时使用<br /> ),MyBatis动态SQL之if,choose, when, otherwise,where,set,foreach,分页查询,主键回填,日志配置等技术;掌握<br /> SpringMVC的项目整合配置,@Controller,@RequestMapping,@Resource,@PathVariable,@ResponseBody,<br /> @ModelAttribute,@CookieValue,@Transactional等注解的使用,json数据传值,国际化,拦截器,权限控制,生成日志,文<br /> 件上传下载,日期格式转换等。<br /> <br /> <span style="font-size:24px;color:#E53333;"><strong>开发技术:</strong></span>java,jsp,mysql,MyBatis,jquery,ajax,json,springmvc<br /> <span style="font-size:24px;color:#E53333;"><strong>运行环境</strong>:</span>jdk1.7及以上版本,tomcat7.0及以上版本,mysql5.5及以上版本<br /> <p> <span style="font-size:24px;color:#E53333;"><strong>开发工具: </strong></span>本项目开发工具是Eclipse,也支持myEclipse,Intellij Idea等其他版本开发工具 </p> <p> <span style="font-size:24px;color:#E53333;"><strong>适用人群:</strong></span> </p> <p> 零基础开始讲解MyBatis,SpringMVC,通过项目实战达到精通各种技术的能力,包括权限控制 </p> <div> <br /> </div> <br /> <br />
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页