(poj)3159 Candies
题目链接:http://poj.org/problem?id=3159
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 and respectively. N is the number of kids in the class and the kids were numbered through N. snoopy and flymouse were always numbered and N. Then follow M lines each holding three integers A, B 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 Sample Output
题意:flymouse是幼稚园班上的班长,一天老师给小朋友们买了一堆的糖果,由flymouse来分发。flymouse希望自己分得的糖果数尽量多于snoopy。对于其他小朋友而言,则必须自己得到的糖果不少于班上某某,给出m个这种约束关系(u,v, w)即同学u的糖果数不能比同学v的糖果数少w。问flymouse最多能多snoopy几个糖果。
方法:用spfa写,开始用队列存,提交超时了,然后用堆栈存,测试数据问题
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <math.h>
#include <vector>
using namespace std;
#define N 30010
#define ll long long
#define INF 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof(a));
vector<vector<int> >Q;
struct node
{
int v,l,next; }s[];
int Map[N],vis[N],dis[N];
int k,n,q[N];
void add(int e,int f,int l)
{
s[k].l=l;
s[k].next=Map[e];
s[k].v=f;
Map[e]=k++;
}
void spfa()
{
int t=;
met(dis,);
for(int i=;i<=n;i++)
dis[i]=INF;
q[++t]=;///用堆栈存
vis[]=;
dis[]=;
while(t)
{
int u=q[t--];
vis[u]=;
for(int i=Map[u];i!=-;i=s[i].next)
{
int v=s[i].v;
if(dis[v]>dis[u]+s[i].l)
{
dis[v]=dis[u]+s[i].l;
if(!vis[v])
{
q[++t]=v;
vis[v]=;
}
}
}
}
}
int main()
{
int m,e,f,l;
while(scanf("%d %d",&n,&m)!=EOF)
{
met(Map,-);k=;
for(int i=;i<m;i++)
{
scanf("%d %d %d",&e,&f,&l);
add(e,f,l);
}
spfa();
printf("%d\n",dis[n]);
}
return ;
}
(poj)3159 Candies的更多相关文章
- POJ——T 3159 Candies
http://poj.org/problem?id=3159 Time Limit: 1500MS Memory Limit: 131072K Total Submissions: 33328 ...
- (poj)1502 MPI Maelstrom
题目链接:http://poj.org/problem?id=1502 Description BIT has recently taken delivery of their processor A ...
- (poj)1806 Currency Exchange
题目链接:http://poj.org/problem?id=1860 Description Several currency exchange points are working in our ...
- (poj)3268 Silver Cow Party 最短路
Description One cow ≤ N ≤ ) conveniently numbered ..N ≤ X ≤ N). A total of M ( ≤ M ≤ ,) unidirection ...
- (poj)3020 Antenna Placement 匹配
题目链接 : http://poj.org/problem?id=3020 Description The Global Aerial Research Centre has been allotte ...
- (poj)1064 Cable master 二分+精度
题目链接:http://poj.org/problem?id=1064 Description Inhabitants of the Wonderland have decided to hold a ...
- (poj)1679 The Unique MST 求最小生成树是否唯一 (求次小生成树与最小生成树是否一样)
Description Given a connected undirected graph, tell if its minimum spanning tree is unique. Definit ...
- (poj)3414 Pots (输出路径的广搜)
Description You are given two pots, having the volume of A and B liters respectively. The following ...
- Intersection(poj)
Intersection Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13140 Accepted: 3424 Des ...
随机推荐
- web pack的使用事项
一开始把webpack想的很难,很复杂,哈哈. 其实写的好的东西真的是越简单,越简单的东西其实越难写. 按照How to一步一步基本就能理解,webpack怎么使用了, 后面就是如何帮程序一步一步找到 ...
- HALCON 简介
HALCON windowssolarisgccdelphilinux图像处理 ·满足您各类机器视觉应用需求的完善的开发库 ·包含匹配,识别,定位及1D,2D,3D测量等多种高级算法 ·强大,易用 ...
- RefernceError : jQuery is not define
使用ligerUI 的时候,代码没有什么错误,可是不能正常显示组件 ,火狐debug显演示样例如以下错误: 最后发现是引入文件的顺序错了,最好依照ligerui demo中的顺序引入js文件,这样就不 ...
- php安装ecshop
1.apache2.2正常 2.源码htdoc下面保存不动 3.E:\PHP 安装目录下 php5.3.28 就不支持jpeg php5.2.17 就不支持 mysql 说明就是php的问题,因为其他 ...
- DataGrid的ItemCreated和ItemDataBound以及合计平均行
DataGrid为数据绑定控件,是重量级控件,臃肿,无华不实这么一个控件定位.如果做为管理系统,那么还是可以使用的. 本文只是为了记录ItemCreated和ItemDataBound两个事件的用法. ...
- Mybatis 动态获取字段值(不需要创建javabean)
最近遇到一个这样的需求,如下: 用户可以通过自定义模板选择需要查询显示的字段,需要动态查询显示. 前提:数据库有一张表,里面有400多个字段. 要求:用户在前台可以自定义模板,一个模板可能对应x个字段 ...
- Windows环境下使用Apache+mod_wsgi部署webpy
1.安装Python和Apache. 2.安装mod_wsgi后获得wsgi.so,并将wsgi.so放到Apache的modules文件夹下. 3.安装webpy. 4.打开httpd.conf(在 ...
- centos7支持ntfs
简单搜索了一下,发现一个很好的安装步骤,简洁有效,已经试验. rpm -ivh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release- ...
- CentOS下安装福昕PDF软件
官方下载地址:http://www.foxitsoftware.cn/downloads/ tar -jxvf foxreader.tar.bz2问题:下载官方包以后解压,双击不能打开,也没有任何提示 ...
- jquery checkbox全选,全不选,反选方法,jquery checkbox全选只能操作一次
jquery checkbox全选,全不选,反选方法, jquery checkbox全选只能操作一次, jquery checkbox全选只有第一次成功 >>>>>&g ...