woj1009 最短路 The Legend of Valiant Emigration
title: woj1009 最短路 The Legend of Valiant Emigration
date: 2020-03-07
categories: acm
tags: [acm,最短路,woj]
SPFA,套了模板就很简单。输入处理一下。
description
The holy topic of human being,love,appears now.Firstly,I'd like to introduce a love song cited from <>
to you as follows.
The Woman
Your lips cover me with kisses;
your love is better than wine.
There is a fragrance about you;
the sound of your name recalls it.
No woman could help loving you.
Take me with you,and we'll run away.
be my king and take me to your room.
We will be happy together,
drink deep,and lose ourselves in love.
No wonder all women love you.
Women of Jerusalem,I am dark but beautiful,
dark as the desert tents of Kedar,
but beautiful as the curtains in Soloman's palace.
Don't look down on me because of my colour,
because the sun has tanned me.
My brotherw were angry with me
and made me work in the vineyard.
I had no time to care for myself.
Tell me,my love,
Where will you lead your flock to graze?
Where will they rest from the noonday sun?
Why should I need to look for you
among the flocks of the other shepherds?
The Man
Don't you know the place,loveliest of women?
Go and follow the flock;
find pasture for your goats near the tents of the shepherds.
You,my love,excite men as a mare excites the stallions of
Pharaoh's chariots.
Your hair is beautiful upon your cheeks
and falls along your neck like jewels.
But we will make for you a chain of gold with ornaments of silver.
The Woman
My king was lying on his couch,
and my perfume filled the air with fragrance.
My lover has the scent of myrrh as he lies upon my breasts.
My lover is like the wild flowers
that bloom in the vineyards at Engedi.
The Man
How beautiful you are,my love;
how your eyes shine with love!
The Woman
How handsome you are,my dearest;
how you delight me!
The green grass will be our bed;
the cedars will be the beams of our house,
and the cypress-trees the ceiling.
I am only a wild flower in Sharon,
a lily in a mountain valley.
The Man
Like a lily among thorns
is my darling among women.
The Woman
Like an apple-tree among the trees of the forest,
so is my dearest compared with other men.
I love to sit in its shadow,
and its fruit is sweet to my taste.
He brought me to his banqueting hall
and raised the banner of love over me.
Restore my strength with raisins
and refresh me with apples!
I am weak from passion.
His left hand is under my head,
and his right hand caresses me.
Promise me,women of Jerusalem;
swear by the swift deer and the gazelles
that you will not interrupt our love.
How beautiful the song is! The God is moved by the holy love between them and decides to help them run away to that place
having full-blown the green grass,the cedars,the cypress-trees and the flowers .There are many cities at that time,such as
Jerusalem,Bethlehem,Carmel,Hebron,Ziklog,Beersheba,Gath,Libnah,Ekron,Beth Horon,Shiloh,Gilgal,and so on.The two lovers
sets out from Jerusalem,and the destination is The Garden of Eden.There are roads between cities,each road has a
guard who has "pguard" power to beat and "sguard" speed to run.The two lovers can run away together,they have "plovers"
power to beat and "slovers" speed to run. They can go through the road if and only if their power "plovers" is bigger than the guard and the speed "slovers"
is bigger than the guard..The God help them calculate the cost of each road,and place a
heart-shaped elixir,associated with a letter to distinguish them,in each road.Your task is to minimize the cost
and display the letters of elixirs they will get in the way.
输入格式
There will be several test cases.The first line contains two integers n(1<=n<=100) indicates the number of cities,and m(1<=m<=4000)
indicates the number of roads between cities.The next m lines list the power and speed of the guard,the cost and the letter of the elixir
the God placed for each road.Each line has the form:
u v pguard sguard cost letter while u and v represents the edge ,pguard and sguard represents power and speed of the guard, cost represents the cost of
the road and letter represents the letter of the elixir the God placed.The last line contains
plovers slovers. The city numberd 0 represents Jerusalem,while n-1 represents The Garden of Eden.
输出格式
For each test case,you should output the letters of the elixirs they get in the way which minimize the cost.
There'll be an empty line following each test case.
样例输入
5 5
0 1 10 10 10 L
0 2 20 14 10 A
1 2 10 10 20 o
2 3 10 10 10 V
3 4 5 30 10 E
14 35
样例输出
LoVE
code
//输入n m n cities m条边
//格式 u v pguard sguard cost letter
//while u and v represents the edge ,pguard and sguard represents power and speed of the guard,
// cost represents the cost of the road and letter represents the letter of the elixir the God placed.
//0 1 10 10 10 L
//The last line contains plovers slovers.plovers要大于路上守卫的guard,slovers要大于守卫的speed
// n 1-100 m 1-4000
//There'll be at least one path to go from Jerusalem to The Garden of Eden.You can assume no two paths have the same lentgh .
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
#define INF 0x3f3f3f3f
char word[4005];
int plovers,slovers;
int n, m,edgenum;
const int maxn=105; //const 点的数
struct Edge {
int from, to, power,speed,dist;
char word;
Edge(int u, int v,int p,int s, int d,char word):from(u),to(v),power(p),speed(s),dist(d),word(word){}
};
vector<Edge> edges;
vector<int> G[maxn];
bool inq[maxn]; //是否在队列里
int d[maxn]; //s到各个点的距离
int p[maxn]; //最短路中的上一条弧
int cnt[maxn]; //入队次数 次数大于n则说明有负环
void init(int n) {
edgenum=0;
for(int i = 0; i < n; i++) G[i].clear();
edges.clear();
}
void AddEdge(int from, int to, int power,int speed,int dist,char word) {
edges.push_back(Edge(from, to, power,speed,dist,word));
edgenum = edges.size(); //错误,一开始写成m,而m又是全局变量导致下面data()的循环除了问题
G[from].push_back(edgenum-1); //边的标号
}
//拓扑排序可以判断有向图有没有环
//dfs判断图联通
bool bellman_ford(int s) { ///BF 适用于含有负边的图。如果有负边,返回false。Dijkstra算法无法判断含负权边的图的最短路.二者都适用于有向有环图
queue<int> Q;
memset(inq, 0, sizeof(inq));
memset(cnt, 0, sizeof(cnt));
for(int i = 0; i < n; i++) d[i] = INF;
d[s] = 0;
inq[s] = true;
p[s]=-1; //加了一条
Q.push(s);
while(!Q.empty()) {
int u = Q.front(); Q.pop();
inq[u] = false;
for(int i = 0; i < G[u].size(); i++) {
Edge& e = edges[G[u][i]];
if(d[u] < INF && d[e.to] > d[u] + e.dist&&plovers>e.power&&slovers>e.speed) { //模板,+条件
d[e.to] = d[u] + e.dist;
p[e.to] = G[u][i];
if(!inq[e.to]) { Q.push(e.to); inq[e.to] = true; if(++cnt[e.to] > n) return false;}
}
}
}
vector<char>ans; //也可以写一个函数递归,没必要
int tmp=p[n-1];
while(tmp!=-1){
ans.push_back(edges[tmp].word);
tmp=p[edges[tmp].from];
}
for(int i=ans.size()-1;i>-1;i--)
cout<<ans[i];
cout<<endl;
return true;
}
void data(){
init(n);
int from,to,power,speed,dist,tmp;
char word;
for(int i=0;i<m;i++){
/* 这样写有问题。读了空格
scanf("%d%d%d%d%d",&from,&to,&power,&speed,&dist);
scanf("%c",&word);
*/
/*
scanf("%d%d%d%d%d",&from,&to,&power,&speed,&dist);
getchar();scanf("%c",&word);getchar();*/ //处理最后一个字符前的空格这样可以,但是麻烦
scanf("%d %d %d %d %d %c",&from,&to,&power,&speed,&dist,&word); //注意%c不是%s 。也可以fstream
AddEdge(from,to,power,speed,dist,word);
}
cin>>plovers>>slovers;
bellman_ford(0);
}
int main(){
while(scanf("%d%d",&n,&m)==2){
data();
getchar(); //输入有空行
}
return 0;
}
woj1009 最短路 The Legend of Valiant Emigration的更多相关文章
- Kattis dragonball1 Dragon Ball I(最短路)
There is a legendary tale about Dragon Balls on Planet X: if one collects seven Dragon Balls, the Dr ...
- echarts中饼图的legend自定义icon图片(扇形为例)
效果图: 代码: 问题:// icon: "pin", // 这个字段控制形状 类型包括 circle,rect ,roundRect,triangle,diamond,pin,a ...
- bzoj1001--最大流转最短路
http://www.lydsy.com/JudgeOnline/problem.php?id=1001 思路:这应该算是经典的最大流求最小割吧.不过题目中n,m<=1000,用最大流会TLE, ...
- 【USACO 3.2】Sweet Butter(最短路)
题意 一个联通图里给定若干个点,求他们到某点距离之和的最小值. 题解 枚举到的某点,然后优先队列优化的dijkstra求最短路,把给定的点到其的最短路加起来,更新最小值.复杂度是\(O(NElogE) ...
- matlab画图函数plot()/set/legend
简单plot()/legend/XY轴范围axis 除了坐标轴信息外还可以添加其它的信息,如所画曲线的信息等:测试代码如下 x=0:pi/20:2*pi; y1=sin(x); y2=cos(x); ...
- Sicily 1031: Campus (最短路)
这是一道典型的最短路问题,直接用Dijkstra算法便可求解,主要是需要考虑输入的点是不是在已给出的地图中,具体看代码 #include<bits/stdc++.h> #define MA ...
- 最短路(Floyd)
关于最短的先记下了 Floyd算法: 1.比较精简准确的关于Floyd思想的表达:从任意节点A到任意节点B的最短路径不外乎2种可能,1是直接从A到B,2是从A经过若干个节点X到B.所以,我们假设maz ...
- bzoj1266最短路+最小割
本来写了spfa wa了 看到网上有人写Floyd过了 表示不开心 ̄へ ̄ 改成Floyd试试... 还是wa ヾ(。`Д´。)原来是建图错了(样例怎么过的) 结果T了 于是把Floyd改回spfa 还 ...
- HDU2433 BFS最短路
Travel Time Limit: 10000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
随机推荐
- 如何使用github搜索需要的开源项目
按照项目名/仓库名搜索(大小写不敏感)in:name xxx按照README搜索(大小写不敏感)in:readme xxx按照description搜索(大小写不敏感)in:description x ...
- 2021 Duilib最新入门教程(一)Duilib简介
目录 Duilib解决什么问题? 方案一.自己画界面 方案二.使用标准控件 方案三.使用Duilib框架 Duilib是什么? 先看下Duilib官方简介 再看下DirectUI 百度百科 比起介 ...
- 入门OJ:Coin
题目描述 你有n个硬币,第i硬币面值为ai,现在总队长想知道如果丢掉了某个硬币,剩下的硬币能组成多少种价值?(0价值不算) 输入格式 第一行一个整数n 第二行n个整数.,a1,a2-an. 1< ...
- [系列] Go - 基于 GORM 获取当前请求所执行的 SQL 信息
前言 为了便于精准排查问题,需要将当前的请求信息与当前执行的 SQL 信息设置对应关系记录下来,记录的 SQL 信息包括: 执行 SQL 的当前时间: 执行 SQL 的文件地址和行号: 执行 SQL ...
- 1.2V升压5V和2.4V升压5V芯片,适用于镍氢电池产品
一节镍氢电池1.2V升压5V电路芯片,两节镍氢电池2.4V升压到5V的电源芯片 PW5100具有宽范围的输入工作电压,从很低的0.7V到5V电压. PW5100输出电压固定3V,3.3V,5V可选固定 ...
- GlusterFS分布式存储系统复制集更换故障Brick操作记录
场景: GlusterFS 3节点的复制集,由于磁盘故障,其中一个复制集需要重装系统,所以需要重装glusterfs并将该节点加入glusterfs集群 一. 安装GlusterFS 首先在重装系统节 ...
- 将HDFS中指定文件的内容输出到终端。
1 import java.io.*; 2 import org.apache.hadoop.conf.Configuration; 3 import org.apache.hadoop.fs.*; ...
- 手淘架构组最新实践 | iOS基于静态库插桩的⼆进制重排启动优化 抖音研发实践:基于二进制文件重排的解决方案 APP启动速度提升超15% 编译期插桩
抖音研发实践:基于二进制文件重排的解决方案 APP启动速度提升超15% 原创 Leo 字节跳动技术团队 2019-08-09 https://mp.weixin.qq.com/s/Drmmx5JtjG ...
- HA工作机制及namenode向QJM写数据流程
HA工作机制 (配置HA高可用传送门:https://www.cnblogs.com/zhqin/p/11904317.html) HA:高可用(7*24小时不中断服务) 主要的HA是针对集群的mas ...
- LOJ10097和平委员会
POI 2001 根据宪法,Byteland民主共和国的公众和平委员会应该在国会中通过立法程序来创立. 不幸的是,由于某些党派代表之间的不和睦而使得这件事存在障碍. 此委员会必须满足下列条件: 每个党 ...