[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 ...
随机推荐
- C语言中如何获得文件大小
方法一: 获得文件大小需要用到2个函数:fseek() , ftell() fseek()函数: 原型:intfseek(FILE *stream, long offset, int fromwher ...
- FastMM内存泄露
转自:http://www.2ccc.com/article.asp?articleid=4879FastMM是非常优秀的内存管理器,但是从FastMM4Options.inc中找到合适自已程序的选项 ...
- Cmake设置环境变量
references: http://stackoverflow.com/questions/21047399/cmake-set-environment-variables-from-a-scrip ...
- spring注解方式 idea报could not autowire,eclipse却没有问题
解决办法1: 从根本上解决: File-Project Structure 页面 Facets下删掉 Spring(直接右键Delete) 这个解答是对的.并不会降低安全性!!因为创建项目的时候,都是 ...
- 黑马程序员_Java面向对象_包
7.包 7.1包(package) 对类文件进行分类管理. 给类提供多层命名空间. 写在程序文件的第一行. 类名的全称是:包名.类名. 包也是一种封装形式. 利用命令行自动生成文件夹格式:D:\jav ...
- bzoj2325 [ZJOI2011]道馆之战
Description 口袋妖怪(又名神奇宝贝或宠物小精灵)红/蓝/绿宝石中的水系道馆需要经过三个冰地才能到达馆主的面前,冰地中的每一个冰块都只能经过一次.当一个冰地上的所有冰块都被经过之后,到下一个 ...
- c#类和结构体的关系
原文地址:http://www.dnbcw.com/biancheng/c/fvhc81798.html 简介:这是c#类和结构体的关系的详细页面,介绍了和c/c++,有关的知识,谢谢大家的观看!要查 ...
- 负重前行的婚纱线上路 - i天下网商-最具深度的电商知识媒体
负重前行的婚纱线上路 - i天下网商-最具深度的电商知识媒体 负重前行的婚纱线上路
- 潘石屹的SOHO小报猝死
东莞时报多媒体数字报刊平台 潘石屹的SOHO小报猝死
- vue-cli 脚手架总结
> vue-cli 的脚手架项目模板有browserify 和 webpack , 现在自己在用的是webpack , 官网给出了两个模板: webpack-simple 和 webpack 两 ...