zoj 2750 Idiomatic Phrases Game
迪杰斯特拉单源最短路算法。对成语进行预处理。做出邻接矩阵即可。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn = ;
int c[maxn], len[maxn], cost[maxn][maxn], flag[maxn], e[maxn];
char s[maxn][];
int main()
{
int n, i, j, ii;
while (~scanf("%d", &n))
{
if (n == ) break;
for (i = ; i < n; i++) scanf("%d%s", &c[i], s[i]);
for (i = ; i < n; i++) len[i] = strlen(s[i]);
memset(flag, , sizeof(flag));
for (i = ; i <= n; i++) for (j = ; j <= n; j++) cost[i][j] = ;
for (i = ; i < n; i++)
{
for (j = ; j < n; j++)
{
if (i != j&&s[j][] == s[i][len[i] - ] && s[j][] == s[i][len[i] - ] && s[j][] == s[i][len[i] - ] && s[j][] == s[i][len[i] - ])
cost[i][j] = c[i];
}
}
for (i = ; i < n; i++) e[i] = cost[][i];
e[] = ; flag[] = ; int x, uu;
for (ii = ; ii < n - ; ii++)
{
int minn = ; uu = ;
for (i = ; i < n; i++)
{
if (!flag[i] && e[i] < minn)
{
x = i;
minn = e[i];
uu = ;
}
}
if (!uu) continue;
flag[x] = ;
for (i = ; i < n; i++)
if (!flag[i] && cost[x][i] != && e[x] + cost[x][i] < e[i])
e[i] = e[x] + cost[x][i];
}
if (e[n - ] != ) printf("%d\n", e[n - ]);
else printf("-1\n");
}
return ;
}
zoj 2750 Idiomatic Phrases Game的更多相关文章
- HDU - 1546 ZOJ - 2750 Idiomatic Phrases Game 成语接龙SPFA+map
Idiomatic Phrases Game Tom is playing a game called Idiomatic Phrases Game. An idiom consists of sev ...
- ZOJ 2750 Idiomatic Phrases Game(Dijkstra)
点我看题目 题意 : 给定一本字典,字典里有很多成语,要求从字典里的第一个成语开始,运用字典里的成语变到最后一个成语,变得过程就是成语接龙,后一个成语的第一个字必须有前一个成语的最后一个字相等,给定的 ...
- Idiomatic Phrases Game(图论最短路)
Idiomatic Phrases Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/O ...
- HDU 1546 Idiomatic Phrases Game 求助!help!!!
Idiomatic Phrases Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/O ...
- Idiomatic Phrases Game(最短路+注意坑点)
Tom is playing a game called Idiomatic Phrases Game. An idiom consists of several Chinese characters ...
- HDU 1546 Idiomatic Phrases Game(最短路,Dijsktra,理解题意很重要)
题目 1.注意因为要判断能不能到达,所以要在模版里面判断k有没有更新. 2.看懂题目意思和案例的解法很重要. #define _CRT_SECURE_NO_WARNINGS //题目大意:现要进行单词 ...
- hdu 1546 Idiomatic Phrases Game
http://acm.hdu.edu.cn/showproblem.php?pid=1546 #include <cstdio> #include <iostream> #in ...
- ZOJ-2750 Idiomatic Phrases Game---Dijk最短路
题目链接: https://vjudge.net/problem/ZOJ-2750 题目大意: 给定一本字典,字典里有很多成语,要求从字典里的第一个成语开始,运用字典里的成语变到最后一个成语,变得过程 ...
- 北大ACM - POJ试题分类
1.入门水题 可用于练手与增强自信 POJ-1003POJ-1004 POJ-1005 POJ-1207 POJ-3299 POJ-2159 POJ-1083POJ-3094 2.初级 2.1. 基本 ...
随机推荐
- html&css入门详解
本系列主要讲解html与css的知识点,因为是参考的英文版的<html&css design and build websites>,所以可能会有个人翻译理解上的差错,希望观者能够 ...
- C++ std::stack
std::stack template <class T, class Container = deque<T> > class stack; LIFO stack Stack ...
- <span>什么意思
<span> 在CSS定义中属于一个行内元素,在行内定义一个区域,也就是一行内可以被 <span> 划分成好几个区域,从而实现某种特定效果. <span> 本身没有 ...
- Docker集群实验环境布署--swarm【7 让docker客户端支持docker-compose】
Docker-Compose是一个部署多个容器的简单但是非常必要的工具. 登录Docker客户端的服务器(默认是安装了docker-engine的服务器),再安装compose插件 # yum i ...
- My Eclipse Security Alert
SECURITY ALERT: INTEGRITY CHECK ERROR This product did not pass the MyEclipse integrity check. This ...
- 引用Excel.dll 时找不到类型怎么办
将引用(Microsoft.Office.Interop.Excel)的属性"嵌入互操作类型"由True修改为False即可
- 关于_cmd
实际上是该方法名(@selector的名称). 比如: - (void)someCategoryMethod { NSString *string = objc_getAssociatedObject ...
- Unity3DGUI:GUILayout
显示效果,注意GUILayout控件默认垂直布局,且在水平布局模块里控件大小默认按控件内容来显示,因此对于水平滑块HorizontalSlider来说需要自定义大小避免变形
- Linux下常用的压缩与解压命令
.tar (注:tar是打包,不是压缩!) 解包: tar xvf FileName.tar 打包: tar cvf FileName.tar DirName .gz 解压1: gunzip File ...
- CodeForces 706A Beru-taxi
简单题. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #inclu ...