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 ...
随机推荐
- Akka源码分析-官方文档说明
如果有小伙伴在看官方文档的时候,发现有些自相矛盾的地方,不要怀疑,可能是官方文档写错了或写的不清楚,毕竟它只能是把大部分情况描述清楚.开源代码一直在更新,官方文档有没有更新就不知道了,特别是那些官方不 ...
- DAO模式详解
DAO模式 数据访问层(DAO): 数据的增.删.改.查操作: 业务逻辑层(service): 业务来往的操作,需要调用数据访问层则调用数据访问层,传递数据: 表现层(UI): 呈现数据,用户交互. ...
- JavaScript中的 函数splice() 的使用。
大二接触JavaScript初期,学习函数中有一道题: 定义一个2个参数的函数.第1个参数是一个数组,第2个参数是需要删除的元素.函数功能,在第1个实参数组中查找第2个实参提供的值,找到则删除该元素( ...
- Redux 基础概念
Redux is a predictable state container for JavaScript apps.,亦即 Redux 希望能提供一个可以预测的 state 管理容器,让开发者可以可 ...
- JS高级——扩展内置对象的方法
基本概念 内置对象有很多,几个比较重要的:Math.String.Date.Array 基本使用 1.内置对象创建出来的对象使用的方法使用的其实都是内置对象的原型对象中的方法 (1)a并没有charA ...
- JS——null
变量被赋值为null,目的往往是为了销毁这个对象: var n1 = 1; n1 = null;
- 使用super实现类的继承
查看一个类继承了哪些类可以用__bases__方法查看 class People: def __init__(self,name,age,sex): self.name=name self.ag ...
- Python开发工具搭建-Pycharm
PyCharm2017. 3.X专业版 安装使用. 注册码激活 本文以 Windows系统 为例: 1.开发工具获取及下载 Anaconda(Python 的集成工具 ) 下载地址: https:// ...
- 如何在eclipse中设置断点并调试程序
eclipse导入源码后可以看见代码但并不能调试,(解决方法) 1.eclipse默认的运行环境不是jdk中的jre.将jre换成jdk: 2. 先去掉勾,apply,在打上勾,apply 参考:ht ...
- GeckoWebBrowser设置cookie
var uri = new Uri("http://www.aa.com"); //often cookies are stored on domain level, so &qu ...