AC日记——爱情之路 codevs 2070
yh非常想念他的女朋友小y,于是他决定前往小y所在的那块大陆。
小y所在的大陆共有n个城市,m条双向路,每条路连接一个或两个城市。经过一条路ei需要耗费时间ti。此外,每条路均有一个特定标识,为’L’,’O’,’V’,’E’,中的某个字母。yh从1号城市出发,前往位于n号城市的小y所在处。
为了考验yh,小y规定,yh必须按照‘L’->’O’->’V’->’E’->’L’->’O’->’V’->’E’->.... 的顺序选择路,且所走的第一条路是’L’,最后一条路是’E’,每走完一个完整的’LOVE’算是通过一次考验
在不违背小y要求的前提下,yh想花费最少的时间到达小y的所在地,同在此时间内完成最多次考验。你能帮yh算出,他最少要花多久到达城市n,完成多少次考验呢?
第一行为两个整数n,m表示有n个城市,m条双向路。
第2行到第m+1行,每行有3个整数x,y,t和一个字符char,城市x,y之间有路,通过这条路花费的时间为t,这条路的特殊标志为 char。
输出1行,两个整数表示yh到达城市n花费的最少时间和该时间内通过的最多次考验数,如果不能到达则输出’HOLY SHIT!’
【样例输入1】
4 4
1 2 1 L
2 1 1 O
1 3 1 V
3 4 1 E
【样例输入2】
4 4
1 2 1 L
2 3 1 O
3 4 1 V
4 1 1 E
【样例输出1】
4 1
【样例输出2】
HOLY SHIT!
对于100%数据,1≤n≤1314,0≤M≤13520
思路:
spfa最短路;
每个点都拆成4个状态;
来,上代码:
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> #define maxn 20005
#define maxm 200005 using namespace std; struct sp {
int t,now;
}; struct EdgeType {
int v,w,e,type;
};
struct EdgeType edge[maxn<<]; int if_z,n,m,dis[][maxn],cnt,head[maxn],times[][maxn],tot; char Cget; bool if_[][maxn]; inline void in(int &now)
{
now=,if_z=,Cget=getchar();
while(Cget>''||Cget<'')
{
if(Cget=='-') if_z=-;
Cget=getchar();
}
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
now*=if_z;
return ;
} struct sp node(int t,int now)
{
sp pos_;
pos_.t=t,pos_.now=now;
return pos_;
} int main()
{
in(n),in(m);
int u,v,w,t;
while(m--)
{
in(u),in(v),in(w);cin>>Cget;
if(Cget=='L') t=;
if(Cget=='O') t=;
if(Cget=='V') t=;
if(Cget=='E') t=;
edge[++cnt].v=v,edge[cnt].e=head[u],edge[cnt].w=w,edge[cnt].type=t,head[u]=cnt;
edge[++cnt].v=u,edge[cnt].e=head[v],edge[cnt].w=w,edge[cnt].type=t,head[v]=cnt;
}
memset(dis,/,sizeof(dis));
dis[][]=,if_[][]=true;
queue<struct sp>que;que.push(node(,));
while(!que.empty())
{
sp pos=que.front();
if_[pos.t][pos.now]=false;que.pop();
int to=(pos.t%)+;
for(int i=head[pos.now];i;i=edge[i].e)
{
if(edge[i].type==to&&edge[i].w+dis[pos.t][pos.now]<dis[to][edge[i].v])
{
dis[to][edge[i].v]=dis[pos.t][pos.now]+edge[i].w;
// if(to==4) times[edge[i].v]=max(times[edge[i].v],times[pos.now]+1);
// if(to==4) times[to][edge[i].v]=max(times[to][edge[i].v],times[pos.t][pos.now]+1);
times[to][edge[i].v]=times[pos.t][pos.now]+;
if(!if_[to][edge[i].v])
{
que.push(node(to,edge[i].v));
if_[to][edge[i].v]=true;
}
}
else if(edge[i].type==to&&edge[i].w+dis[pos.t][pos.now]==dis[to][edge[i].v])
{
times[to][edge[i].v]=max(times[to][edge[i].v],times[pos.t][pos.now]+);
if(!if_[to][edge[i].v])
{
que.push(node(to,edge[i].v));
if_[to][edge[i].v]=true;
}
}
}
if(tot==) tot++,dis[][]=0x7ffffff;
}
if(dis[][n]>||times[][n]<) cout<<"HOLY SHIT!";
else cout<<dis[][n]<<" "<<times[][n]/;
cout<<endl;
return ;
}
AC日记——爱情之路 codevs 2070的更多相关文章
- AC日记——接龙游戏 codevs 1051
1051 接龙游戏 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 给出了N个单词,已经按长度排好了序.如果 ...
- AC日记——松江1843路 洛谷七月月赛
松江1843路 思路: 三分: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 100005 #define ...
- AC日记——地鼠游戏 codevs 1052
1052 地鼠游戏 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Description 王钢是一名学习成绩优异的学生,在平 ...
- AC日记——鬼谷子的钱袋 codevs 2998
2998 鬼谷子的钱袋 2006年省队选拔赛湖南 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 大师 Master 题目描述 Description 鬼谷子非常聪明,正 ...
- AC日记——舒适的路线 codevs 1001 (并查集+乱搞)
1001 舒适的路线 2006年 时间限制: 2 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 Description Z小镇是 ...
- AC日记——逃跑的拉尔夫 codevs 1026 (搜索)
1026 逃跑的拉尔夫 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 年轻的拉尔夫开玩笑地从一 ...
- AC日记——自然数和分解 codevs 2549
自然数和分解 思路: 水题: 代码: #include <bits/stdc++.h> using namespace std; ][]; int main() { cin>> ...
- AC日记——郁闷的出纳员 codevs 1286
郁闷的出纳员 思路: 设工资下限为ko,然后ko--(因为要小于工资下限): 设cur为记录工资增长,降低: 设第i个人的工资为pos: 对应的四种操作: 插入:cur-pos-ko: 增长:cur- ...
- AC日记——营业额统计 1296 codevs
1296 营业额统计 2002年 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 大师 Master 题解 查看运行结果 题目描述 Description Tiger ...
随机推荐
- 14Shell脚本—判断语句
判断语句 Shell脚本中的条件测试语法可以判断表达式是否成立,若条件成立则返回数字0,否则便返回其他随机数值. 条件测试语法的执行格式为 [ 条件表达式 ],切记,条件表达式两边均应有一个空格. 条 ...
- 使用GD库做图片水印
png图片作为水印加到其他类型图片后,背景变黑色 原因: imagecopy函数拷贝时可以保留png图像的原透明信息,而imagecopymerge却不支持图片的本身的透明拷贝. 然后直接上代码: / ...
- leetcode-11-dfs
DFS算法: explore(G, v) visited(v) = trueprevisit(v) for each edge(v, u) in E: if not visited(u): explo ...
- 牛客练习赛29 B
炎热的早上,gal男神们被迫再操场上列队,gal男神们本来想排列成x∗x的正方形,可是因为操场太小了(也可能是gal男神太大了),校长安排gal男神们站成多个4∗4的正方形(gal男神们可以正好分成n ...
- 排序 sort函数
sort函数见下表: 函数名 功能描述 sort 对给定区间所有元素进行排序 stable_sort 对给定区间所有元素进行稳定排序 partial_sort 对给定区间所有元素部分排序 partia ...
- org.hibernate.AnnotationException: No identifier specified for entity: com.example1.demo1.Entity.User错误
最近在公司带人,他们问我的问题在这里也顺便总结下. 此项目为SpringDataJpa项目. 出现的错误如下: Caused by: org.hibernate.AnnotationException ...
- base64转图片
y一个简单的工具类,附上: /** * @param imgStr 图片的base64 * @param path 将要生成的地址 * @return */ public static boolean ...
- 【bzoj1002】[FJOI2007]轮状病毒 矩阵树定理+高精度
题目描述 轮状病毒有很多变种,所有轮状病毒的变种都是从一个轮状基产生的.一个N轮状基由圆环上N个不同的基原子和圆心处一个核原子构成的,2个原子之间的边表示这2个原子之间的信息通道.如下图所示 N轮状病 ...
- 【前端学习笔记】2015-09-02~~~~ 关于filter()匹配的使用
关于filter的使用先记录以下几点: 1.filter(':even')遍历所有元素,找到index为偶数的元素.. ps: filter(':odd') odd----奇数 eve ...
- hdu 2999 sg函数(简单博弈)
Stone Game, Why are you always there? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/ ...