BZOJ 1631==USACO 2007== POJ 3268 Cow Party奶牛派对
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 19226 | Accepted: 8775 |
Description
One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A total of M (1 ≤ M ≤ 100,000) unidirectional (one-way roads connects pairs of farms; road i requires Ti (1 ≤ Ti ≤ 100) units of time to traverse.
Each cow must walk to the party and, when the party is over, return to her farm. Each cow is lazy and thus picks an optimal route with the shortest time. A cow's return route might be different from her original route to the party since roads are one-way.
Of all the cows, what is the longest amount of time a cow must spend walking to the party and back?
Input
Lines 2..M+1: Line i+1 describes road i with three space-separated integers: Ai, Bi, and Ti. The described road runs from farm Ai to farm Bi, requiring Ti time units to traverse.
Output
Sample Input
4 8 2
1 2 4
1 3 2
1 4 7
2 1 1
2 3 5
3 1 2
3 4 4
4 2 3
Sample Output
10
Hint
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int map[][],w[][];
int dis[],Team[];
bool exist[];
int n,m,t; // exist 为 true 则不可进队
void SPFA(int s)
{
int head=,tail=,k=;
Team[head]=s,exist[s]=true;dis[s]=;
while(head<tail)
{
k=Team[head];
exist[k]=false;
for(int i=;i<=n;i++)
{
if((map[k][i]>)&&(dis[i]>dis[k]+map[k][i]))
{
dis[i]=map[k][i]+dis[k];
if(exist[i]==false)
{
Team[tail++]=i;
exist[i]=true;
}
}
}
head++;
}
}
int main()
{
cin>>n>>m>>t;
memset(map,0x3f,sizeof map );
memset(w,0x3f,sizeof w );
memset(dis,0x3f,sizeof dis );
for(int i=;i<=m;i++)
{
int x,y,z;
cin>>x>>y>>z;
map[x][y]=z;
w[x][y]=z;
}
SPFA(t);// 从起点开始到其他每个点找一遍最短路
for(int k=;k<=n;k++)
{
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
if(w[i][j]>w[i][k]+w[k][j])
w[i][j]=w[i][k]+w[k][j];
}
}
}
int max;
for(int i=;i<=n;i++)
{
if((i==)||(dis[i]+w[i][t]>max))
max=dis[i]+w[i][t]; }
printf("%d",max);
return ;
}
思路:一遍SPFA求出起点到其他所有点的最短路,一遍Floyed求出所有点到起点的最短路,两者相加,和最大者即为anwser...
BZOJ 1631==USACO 2007== POJ 3268 Cow Party奶牛派对的更多相关文章
- 【BZOJ】【1046】/【POJ】【3613】【USACO 2007 Nov】Cow Relays 奶牛接力跑
倍增+Floyd 题解:http://www.cnblogs.com/lmnx/archive/2012/05/03/2481217.html 神题啊= =Floyd真是博大精深…… 题目大意为求S到 ...
- BZOJ 1631 Usaco 2007 Feb. Cow Party
[题解] 最短路裸题.. 本题要求出每个点到终点走最短路来回的距离,因此我们先跑一遍最短路得出每个点到终点的最短距离,然后把边反向再跑一遍最短路,两次结果之和即是答案. #include<cst ...
- BZOJ 1641 USACO 2007 Nov. Cow Hurdles 奶牛跨栏
[题解] 弗洛伊德.更新距离的时候把$f[i][j]=min(f[i][j],f[i][k]+f[k][j])$改为$f[i][j]=min(f[i][j],max(f[i][k],f[k][j])) ...
- [BZOJ 1647][USACO 2007 Open] Fliptile 翻格子游戏
1647: [Usaco2007 Open]Fliptile 翻格子游戏 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 702 Solved: 281[ ...
- 【BZOJ】1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会(tarjan)
http://www.lydsy.com/JudgeOnline/problem.php?id=1654 请不要被这句话误导..“ 如果两只成功跳圆舞的奶牛有绳索相连,那她们可以同属一个组合.” 这句 ...
- POJ 2184 Cow Exhibition 奶牛展(01背包,变形)
题意:有只奶牛要证明奶牛不笨,所以要带一些奶牛伙伴去证明自己.牛有智商和幽默感,两者可为负的(难在这),要求所有牛的智商和之 / 幽默感之和都不为负.求两者之和的最大值. 思路:每只牛可以带或不带上, ...
- POJ 3268 Silver Cow Party 最短路
原题链接:http://poj.org/problem?id=3268 Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total ...
- 图论 ---- spfa + 链式向前星 ---- poj 3268 : Silver Cow Party
Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 12674 Accepted: 5651 ...
- POJ 3268 Silver Cow Party (最短路径)
POJ 3268 Silver Cow Party (最短路径) Description One cow from each of N farms (1 ≤ N ≤ 1000) convenientl ...
随机推荐
- h5-4 canvas
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 提升GDI画图的效率
假设我们要画一个坐标图,里面可能还需要画网络线.XY各个单位的值.曲线或直线等,可能的函数代码如下: void OnPaint () { CPaintDC dc (this); DrawXY (&am ...
- 进程间通信和同步:pipe、FIFO、消息队列、信号量、共享内存、信号
一.半双工管道(pipe) 关于管道详细介绍可参考http://www.cnblogs.com/nufangrensheng/p/3560130.html. 1.管道实现父子进程间通信实例: /* p ...
- Linux中如何使用gThumb批量调整图片大小
Linux中如何使用gThumb批量调整图片大小 导读 如果你的工作涉及到图片编辑和处理,就一定会有同时对多张图片进行批量大小调整的经历.虽然大多数图片编辑应用都能够非常容易地批量调整多张图片,但对于 ...
- html元素英文含义
常用html标签的英语全称及简单功能描述 <a>:anchor 定义锚 <abbr>:abbreviation 定义缩写 <acronym>: 定义只取消首字母的缩 ...
- ACMer
Problem Description There are at least P% and at most Q% students of HDU are ACMers, now I want to k ...
- iOS 中的XML解析代码(SAX)
1.XML解析(SAX) NSXMLParser SAX 大文件 1)打开文档 - (void)parserDidStartDocument:(NSXMLParser *)parser 2)开始查找起 ...
- iOS 全局竖屏 单个viewcontroller点击按钮支持横屏
问题描述:项目工程只支持竖屏,在播放器页面需要点击按钮进行横竖屏切换,并能根据手机的方向进行自动旋转 如图:只勾选了竖屏 解决方法:(主要是采用视图transform的原理 横屏时调整视频视图上的每个 ...
- 《算法导论》习题解答 Chapter 22.1-8(变换邻接表的数据结构)
一般散列表都与B+树进行比较,包括在信息检索中也是. 确定某条边是否存在需要O(1). 不足: (1)散列冲突. (2)哈希函数需要不断变化以适应需求. 另外:B+树.(见第18章) 与散列表相比的不 ...
- 在CentOS下安装配置MySQL
经常需要在linux环境下部署项目或安装Mysql数据库,由于记性不好,每次都是求助度娘,每次搜到的步骤都不一样,所以每次都在尝试.冒险:于是乎,把安装的重要步骤贴出,供自己以后参照. 1.首先要看看 ...