HDU 4360
题意很好理解。
由于点是可以重复到达的,但可能每次经过路径的标志不一样,所以可以设每个点有四种状态"L”,'O','V','E'。然后按这些状态进行求最短路,当然是SPFA了。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
#define LL __int64
using namespace std;
const LL inf=1ll<<58;
LL dis[1350][4];
int cnt[1350][4];
LL n1j[4];
int n,m;
int hed,tail;
int que[5350000];
bool inq[1350];
struct Edge{
int u,v,nxt;
LL c;
char t;
}edge[30000];
int tot;
int head[1350]; void addedge(int u,int v,int c,char t){
edge[tot].u=u;
edge[tot].v=v;
edge[tot].c=c;
edge[tot].t=t;
edge[tot].nxt=head[u];
head[u]=tot++;
} int isure(char c){
if(c=='L') return 0;
else if (c=='O') return 1;
else if(c=='V') return 2;
return 3;
} void spfa(){
hed=tail=0;
memset(inq,false,sizeof(inq));
inq[1]=true;
que[tail++]=1;
while(hed<tail){
int u=que[hed++]; inq[u]=false;
for(int e=head[u];e!=-1;e=edge[e].nxt){
int v=edge[e].v,nt=isure(edge[e].t);
if(dis[u][nt]+edge[e].c<=dis[v][(nt+1)%4]){
bool flag=false;
if(dis[v][(nt+1)%4]>dis[u][nt]+edge[e].c){
dis[v][(nt+1)%4]=dis[u][nt]+edge[e].c;
cnt[v][(nt+1)%4]=cnt[u][nt]+1;
flag=true;
}
else{
if(cnt[v][(nt+1)%4]<cnt[u][nt]+1){
cnt[v][(nt+1)%4]=cnt[u][nt]+1;
flag=true;
}
else continue;
}
if(flag){
if(!inq[v]){
inq[v]=true;
que[tail++]=v;
}
}
}
}
}
if(dis[n][0]==inf||cnt[n][0]==0){
printf("Binbin you disappoint Sangsang again, damn it!\n");
}
else printf("Cute Sangsang, Binbin will come with a donkey after travelling %I64d meters and finding %d LOVE strings at last.\n",dis[n][0],cnt[n][0]/4); } int main(){
int T,u,v,c; char t;
int icase=0;
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
tot=0;
memset(head,-1,sizeof(head));
n1j[0]=n1j[1]=n1j[2]=n1j[3]=inf;
for(int i=0;i<m;i++){
scanf("%d %d %d %c",&u,&v,&c,&t);
if(n==1){
int f=isure(t);
n1j[f]=min(n1j[f],(LL)c);
continue;
}
addedge(u,v,c,t);
addedge(v,u,c,t);
}
printf("Case %d: ",++icase);
LL leng=0;
for(int i=0;i<4;i++){
leng+=n1j[i];
}
if(n==1){
if(leng>=inf){ printf("Binbin you disappoint Sangsang again, damn it!\n");}
else{
printf("Cute Sangsang, Binbin will come with a donkey after travelling %I64d meters and finding 1 LOVE strings at last.\n",leng);
}
continue;
} for(int i=1;i<=n;i++){
dis[i][0]=dis[i][1]=dis[i][2]=dis[i][3]=inf;
cnt[i][0]=cnt[i][1]=cnt[i][2]=cnt[i][3]=0;
}
dis[1][0]=0;
spfa();
}
return 0;
}
HDU 4360的更多相关文章
- HDU 4360 As long as Binbin loves Sangsang spfa
题意: 给定n个点m条边的无向图 每次必须沿着LOVE走,到终点时必须是完整的LOVE,且至少走出一个LOVE, 问这样情况下最短路是多少,在一样短情况下最多的LOVE个数是多少. 有自环. #inc ...
- 8-12-COMPETITION
链接:最短路 A.HDU 2544 最短路 算是最基础的题目了吧.............我采用的是Dijkstra算法....... 代码: #include <iostream> ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
随机推荐
- Effective C++ 深入理解inline
Effective C++ 深入理解inline inline语义 inline本义是将所调用函数用自身的函数本体替换之,免受函数调用所招致的额外开销,比宏还要不易出错:但是实际上inline的受编译 ...
- 【BZOJ2149】拆迁队(斜率优化DP+CDQ分治)
题目: 一个斜率优化+CDQ好题 BZOJ2149 分析: 先吐槽一下题意:保留房子反而要给赔偿金是什么鬼哦-- 第一问是一个经典问题.直接求原序列的最长上升子序列是错误的.比如\(\{1,2,2,3 ...
- nginx入门学习
1.yum解决编译nginx所需的依赖包,之后你的nginx就不会报错了 yum install gcc patch libffi-devel python-devel zlib-devel bzip ...
- Linq学习(四)-联合查询
一.本将主要介绍 Union.Concat.Intersect.Except的使用操作 1.Union 查询昵称中带有Friend和带有Lee的用户 Linq (from a in Blog_User ...
- Android常用的Dialog对话框用法
Android的版本有很多通常开发的时候对话框大多数使用自定义或是 Google提供的V4, V7 兼容包来开发保持各个版本的对话框样式统一,所以这里使用的是V7 包里的AlertDialog. im ...
- C#入门经典 Chapter5 变量的更多内容
5.1类型转换 1.类型转换 1.1隐式转换:所有情况下可进行,编译器执行转换. 1.2显示转换 强制转换:强迫数据从一种类型转换为另一种类型. (<destinationType>)&l ...
- Burn Down Chart(2018.6.4~2018.6.10)
Burn Down Chart (2018.6.4~2018.6.10) 娄雨禛[前端部分] 曾子轩[后端部分+燃尽图] 前端 1. 娄雨禛+李鑫 1)在总工程中完成跳转,实现图片显示,并发布到Git ...
- jQuery——链式编程与隐式迭代
链式编程 1.原理:return this; 2.通常情况下,只有设置操作才能把链式编程延续下去.因为获取操作的时候,会返回获取到的相应的值,无法返回 this. 3.end():结束当前链最近的一次 ...
- (三)Python 学习第三天--GUI桌面项目
(代码参考了别人的代码,只做学习用途!!!最近因为写论文,好久没有记录,好内疚...今天学习了一个小案例,做一下) 主要使用模块:tkinter 代码如下: from tkinter import * ...
- 【sqli-labs】 less44 POST -Error based -String -Stacked Blind(POST型基于盲注的堆叠字符型注入)
盲注漏洞,登陆失败和注入失败显示的同一个页面 可以用sleep函数通过延时判断是否闭合引号成功 这个方法有一点不好的地方在于,并不能去控制延时,延时的时间取决于users表中的数据数量和sleep函数 ...