[POJ] 1511 Invitation Cards
Time Limit: 8000MS | Memory Limit: 262144K | |
Total Submissions: 18198 | Accepted: 5969 |
Description
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
Output
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
Source
#include<stdio.h>
#include<string.h>
#include<stdbool.h>
#include<limits.h>
int i,j,n,m,p,tot,
q[],toit[],list[],next[],cost[],dist[],
ai[],bi[],ci[];
double sum;
bool can[]; int
pre(void)
{
memset(q,,sizeof(q));
memset(toit,,sizeof(toit));
memset(next,,sizeof(next));
memset(list,,sizeof(list));
memset(cost,,sizeof(cost));
memset(can,true,sizeof(can));
memset(ai,,sizeof(ai));
memset(bi,,sizeof(bi));
memset(ci,,sizeof(ci));
sum=;tot=;
return ;
} int
add(int x,int y,int z)
{
tot++;
cost[tot]=z;
next[tot]=list[x];
list[x]=tot;
toit[tot]=y; ai[tot]=y; bi[tot]=x; ci[tot]=z;
return ;
} void
spfa(int s)
{
int i,j,head,tail,v,k;
q[]=s;
head=;tail=;
for(i=;i<=n;i++)
dist[i]=INT_MAX >> ;
dist[s]=;
can[s]=false; while(head!=tail)
{
head=head%+;
v=q[head];
k=list[v]; while(k!=)
{
if((dist[v]+cost[k])<dist[toit[k]])
{
dist[toit[k]]=dist[v]+cost[k];
if (can[toit[k]])
{
tail=tail%+;
q[tail]=toit[k];
can[toit[k]]=false;
} }
k=next[k];
}
can[v]=true;
} } int
main()
{
int x,y,z,ca;
scanf("%d\n",&p);
for(ca=;ca<=p;ca++)
{
pre();
scanf("%d%d\n",&n,&m);
for(i=;i<=m;i++)
{
scanf("%d%d%d",&x,&y,&z);
add(x,y,z);
}
spfa(); for(i=;i<=n;i++)
sum+=dist[i]; memset(q,,sizeof(q));
memset(toit,,sizeof(toit));
memset(next,,sizeof(next));
memset(list,,sizeof(list));
memset(cost,,sizeof(cost));
memset(can,true,sizeof(can));
tot=; for(i=;i<=m;i++)
add(ai[i],bi[i],ci[i]); spfa();
for(i=;i<=n;i++)
sum+=dist[i]; printf("%.f\n",sum);
}
return ;
}
[POJ] 1511 Invitation Cards的更多相关文章
- POJ 1511 Invitation Cards / UVA 721 Invitation Cards / SPOJ Invitation / UVAlive Invitation Cards / SCU 1132 Invitation Cards / ZOJ 2008 Invitation Cards / HDU 1535 (图论,最短路径)
POJ 1511 Invitation Cards / UVA 721 Invitation Cards / SPOJ Invitation / UVAlive Invitation Cards / ...
- POJ 1511 Invitation Cards(单源最短路,优先队列优化的Dijkstra)
Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 16178 Accepted: 526 ...
- DIjkstra(反向边) POJ 3268 Silver Cow Party || POJ 1511 Invitation Cards
题目传送门 1 2 题意:有向图,所有点先走到x点,在从x点返回,问其中最大的某点最短路程 分析:对图正反都跑一次最短路,开两个数组记录x到其余点的距离,这样就能求出来的最短路以及回去的最短路. PO ...
- POJ 1511 Invitation Cards (spfa的邻接表)
Invitation Cards Time Limit : 16000/8000ms (Java/Other) Memory Limit : 524288/262144K (Java/Other) ...
- POJ 1511 Invitation Cards (最短路spfa)
Invitation Cards 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/J Description In the age ...
- Poj 1511 Invitation Cards(spfa)
Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 24460 Accepted: 8091 De ...
- (简单) POJ 1511 Invitation Cards,SPFA。
Description In the age of television, not many people attend theater performances. Antique Comedians ...
- POJ 1511 Invitation Cards 链式前向星+spfa+反向建边
Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 27200 Accepted: 902 ...
- poj 1511 Invitation Cards(最短路中等题)
In the age of television, not many people attend theater performances. Antique Comedians of Malidine ...
随机推荐
- 最牛B的编码套路 【转】
原文:http://blog.csdn.net/happydeer/article/details/17023229 最近,我大量阅读了Steve Yegge的文章.其中有一篇叫“Practicing ...
- win10系统加载ahci驱动的操作方案(Win10之家)
win10系统使用的过程中很多用户会想要加载ahci驱动,但是大部分用户根本不知道怎么操作加载ahci驱动,这样的话很多用户会遇到一些问题,那如果使用的过程中想要加载ahci驱动的话我们应该怎么操作呢 ...
- java比较相等符
public class Test1 { /** * @param args */ public static void main(String[] args){ int a = 1000, b = ...
- C#使用.net.mail配置163邮箱报错:不允许使用邮箱名称。 服务器响应为:authentication is required,smtp9,DcCowABHK4UYE11W2k6fAQ--.52196S2 1448940312
client.UseDefaultCredentials = true; 要放在 client.Credentials = new NetworkCredential("用户名", ...
- PyInstaller打包Python脚本为exe
1.PyInstaller-3.1.1 百度云链接 http://pan.baidu.com/s/1jHYWin8 密码 oapl 2.安装最新版本的 pywin32-217.win32-py2 ...
- javascript定时器:setTimeout与setInterval
概述: setTimeout:在指定的延迟时间之后调用一个函数或者执行一个代码片段,只执行一次: setInterval:周期性地调用一个函数(function)或者执行一段代码,重复执行: 语法格式 ...
- dom4j解析接口使用SOAP传递的xml
xml 文件的格式类型: <?xml version="1.0" encoding="utf-8"?> <SOAP-ENV:Envelope ...
- ORACLE SEQUENCE 介绍
在oracle中sequence就是所谓的序列号,每次取的时候它会自己主动添加,一般用在须要按序列号排序的地方. 1.Create Sequence 你首先要有CREATE SEQUENCE或者C ...
- Composer 基本指令操作使用
Composer 基本指令操作使用 註: 若 composer.phar 改名為 composer, 請自行將 "php composer.phar" 替換成 "comp ...
- springmvc4+hibernate4分页查询功能
Springmvc+hibernate成为现在很多人用的框架整合,最近自己也在学习摸索,由于我们在开发项目中很多项目都用到列表分页功能,在此参考网上一些资料,以springmvc4+hibnerate ...