Invitation Cards

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 3129    Accepted Submission(s):
1456

Problem Description
In the age of television, not many people attend
theater performances. Antique Comedians of Malidinesia are aware of this fact.
They want to propagate theater and, most of all, Antique Comedies. They have
printed invitation cards with all the necessary information and with the
programme. A lot of students were hired to distribute these invitations among
the people. Each student volunteer has assigned exactly one bus stop and he or
she stays there the whole day and gives invitation to people travelling by bus.
A special course was taken where students learned how to influence people and
what is the difference between influencing and robbery.
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
The input consists of N cases. The first line of the
input contains only positive integer N. Then follow the cases. Each case begins
with a line containing exactly two integers P and Q, 1 <= P,Q <= 1000000.
P is the number of stops including CCS and Q the number of bus lines. Then there
are Q lines, each describing one bus line. Each of the lines contains exactly
three numbers - the originating stop, the destination stop and the price. The
CCS is designated by number 1. Prices are positive integers the sum of which is
smaller than 1000000000. You can also assume it is always possible to get from
any stop to any other stop.
 
Output
For each case, print one line containing the minimum
amount of money to be paid each day by ACM for the travel costs of its
volunteers.
 
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
 
Recommend
LL   |   We have carefully selected several similar
problems for you:  1531 1384 1596 1534 1532
 
第一次使用spfa算法,完全不知道是什么。。。看了网上的代码,明白了思路,先计算从1为起点到各点的距离之和,再重置地图,计算各点到1点的距离之和。
 
题意:有编号1~P的站点, 有Q条公交车路线,公交车路线只从一个起点站直接到达终点站,是单向的,每条路线有它自己的车费。有P个人早上从1出发,他们要到达每一个公交站点, 然后到了晚上再返回点1。 求所有人来回的最小费用之和。
 
附上代码:
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#define M 1000010
#define inf 0x3f3f3f3f
using namespace std;
struct node
{
int now,to,w;
} e[M];
int first[M],nexts[M];
int n,m,dis[M],vis[M];
void init()
{
int i,j;
for(i=; i<=m; i++)
first[i]=nexts[i]=-;
for(i=; i<m; i++)
{
scanf("%d%d%d",&e[i].now,&e[i].to,&e[i].w);
nexts[i]=first[e[i].now]; //spfa()算法
first[e[i].now]=i;
}
} void spfa(int src,int flag)
{
int i,j;
for(i=; i<=n; i++)
dis[i]=inf;
dis[src]=;
for(i=; i<=n; i++)
vis[i]=;
queue<int> q;
q.push(src);
while(!q.empty())
{
src=q.front();
q.pop();
vis[src]=;
for(i=first[src]; i!=-; i=nexts[i])
{
int to=(flag?e[i].to:e[i].now);
if(dis[to]>dis[src]+e[i].w) //每次比较更新
{
dis[to]=dis[src]+e[i].w;
if(!vis[to])
{
vis[to]=;
q.push(to);
}
}
}
}
} void set_map()
{
int i,j;
for(i=; i<=m; i++)
first[i]=nexts[i]=-;
for(i=; i<m; i++)
{
int now=e[i].now;
int to=e[i].to;
nexts[i]=first[to];
first[to]=i;
}
}
int main()
{
int T,i,j,sum;
scanf("%d",&T);
while(T--)
{
sum=;
scanf("%d%d",&n,&m);
init();
spfa(,);
for(i=; i<=n; i++) //先将1到每个车站的最小花费加起来
sum+=dis[i];
set_map(); //重置图
spfa(,);
for(i=; i<=n; i++) //将所有点到1的最小花费加起来
sum+=dis[i];
printf("%d\n",sum);
}
return ;
}

最新文章

  1. [Qcon] 百姓网开发总结
  2. 【洛谷 P1352】没有上司的舞会
  3. Spring基础—— 在 Spring Config 中使用外部属性文件
  4. 使用selenium实现右键另存为保存文件
  5. 九幽2015年Q3 WP市场份额细分报告
  6. 多文件 定义全局变量的使用 extern
  7. Q5: Remove Duplicates from Sorted Array
  8. ASP.NET MVC基于标注特性的Model验证:将ValidationAttribute应用到参数上
  9. 百度api的使用
  10. MPLS VPN随堂笔记2
  11. 【原】storm组件(架构层面)
  12. java thread yield 的设计目的是什么?
  13. 毕业设计(1)基于MicroPython的大棚监测控制系统的程序设计与模型设计
  14. Redis的7个应用场景
  15. Go 初体验 - 并发与锁.1 - sync.Mutex 与 sync.RWMutex
  16. Spring Boot学习大全(入门)
  17. Javascript高级编程学习笔记(49)—— DOM2和DOM3(1)DOM变化
  18. ASP.NET - 学习总目录
  19. linux更好看的top界面htop
  20. Oracle 创建分区表

热门文章

  1. python的pip更改源,因为我们处于局域网中
  2. 【二次元的CSS】—— 用 DIV + CSS3 画咸蛋超人(详解步骤)
  3. C++ Socket 获取本机可用端口号(QT)
  4. React高阶组件 和 Render Props
  5. JS DOM节点的增删改查
  6. day38 16-Spring的Bean的装配:注解的方式
  7. 【水滴石穿】FirstReactNativeProject
  8. Apache Camel 与 Spring Boot 集成,通过FTP定时采集、处理文件 (转)
  9. Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十二章:四元数(QUATERNIONS)
  10. 元素的高度(基于vue)