HDOJ 1217 Floyed Template


 1 #include <iostream>
2 #include <stdio.h>
3 #include <string.h>
4 #include <cstring>
5 #include<map>
6 using namespace std;
7
8 map<string,int>name;
9 const int INF = 1000000;
10 const int MAXSIZE = 1005;
11 const int MAXN = 30;
12 double g[MAXN][MAXN];
13
14 //dis[][]记录任意两点间的最短路径,初始的dis[][]记录直接路径
15 void floyed(double dis[][MAXN],int n){//节点从1~n编号
16 int i,j,k;
17 for(k = 1; k <= n; k++)
18 for(i = 1; i <= n; i++)
19 for(j = 1; j <= n; j++)
20 if(dis[i][j] < dis[i][k] * dis[k][j])
21 dis[i][j] = dis[i][k] * dis[k][j];
22 }
23 int main(){
24 int n,i,m,j;
25 string str1,str2;
26 double r;
27 int iCase = 0;
28 while(scanf("%d",&n),n){
29 iCase++;
30 for(i = 1; i <= n; i++){
31 cin>>str1;
32 name[str1] = i;
33 }
34 for(i = 1; i <= n; i++)
35 for(j = 1; j <= n; j++){
36 if(i == j) g[i][j] = 1;
37 else g[i][j] = 0;
38 }
39 scanf("%d",&m);
40 while(m--){
41 cin>>str1>>r>>str2;
42 g[name[str1]][name[str2]] = r;
43 }
44
45 floyed(g,n);
46
47 bool flag = false;
48 for(i = 1; i <= n; i++){
49 if(g[i][i] > 1){
50 flag = true;
51 break;
52 }
53 }
54 if(flag) printf("Case %d: Yes\n",iCase);
55 else printf("Case %d: No\n",iCase);
56 }
57 return 0;
58 }

HDOJ 1217 Floyed Template,码迷,mamicode.com

时间: 2024-10-25 12:29:56

HDOJ 1217 Floyed Template的相关文章

HDOJ 1217 Arbitrage(拟最短路,floyd算法)

Arbitrage Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5679    Accepted Submission(s): 2630 Problem Description Arbitrage is the use of discrepancies in currency exchange rates to transform

HDOJ 1217 Floyd

1 #include <iostream> 2 #include <string> 3 #include <map> 4 5 using namespace std; 6 7 map<string, int> edge; 8 double matrix[30][30]; 9 10 bool floyd_Arbitrage(int n){ 11 for (int k = 0; k < n; k++) 12 for (int i = 0; i < n

[ACM] hdu 1217 Arbitrage (bellman_ford最短路,判断是否有正权回路或Floyed)

Arbitrage Problem Description Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a currency into more than one unit of the same currency. For example, suppose that 1 US Dollar buys 0.5 British pound, 1 British p

[ACM] hdu 1217 Arbitrage (bellman_ford最短路,推断是否有正权回路或Floyed)

Arbitrage Problem Description Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a currency into more than one unit of the same currency. For example, suppose that 1 US Dollar buys 0.5 British pound, 1 British p

HDOJ多校联合第五场

1001 题意:求逆序对,然后交换k次相邻的两个数,使得剩下的逆序对最少. 分析:题目用到的结论是:数组中存在一对逆序对,那么可以通过交换相邻两个数使得逆序对减少1,交换k次,可以最多减少k个. 嘉定ai>aj,i < j,如果ai,aj相邻的,那么显然可以通过交换减少1:不相邻的情况, 考虑ak,k = j-1; #11:ak > aj,那么ak,aj构成逆序对,交换后逆序对减少1: #12:ak<=aj,那么ai,ak构成逆序对,问题转化为更小规模,可以通过同样的方法进一步分析

HDOJ 4893 Wow! Such Sequence!

题意是这样的,给定一个n个元素的数组,初始值为0,3种操作: 1 k d将第k个数增加d: 2 l r 询问区间l...r范围内数之和: 3 l r 表示将区间l...r内的数变成离他最近的斐波那契数,要求尽量小. 线段树操作题目,其中对于第三种操作用一个懒惰标记一下,表示l...r内的数是不是已经变成斐波那契数,如果是的话,求和就是其相应数的斐波那契数之和. 代码: 1 //Template updates date: 20140718 2 #include <bits/stdc++.h>

【HDOJ】【3506】Monkey Party

DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 1 //HDOJ 3506 2 #include<cmath> 3 #include<vector> 4 #include<cstdio> 5 #include<cstring> 6 #include<cstdlib> 7 #include<iostream> 8 #include<algorithm> 9 #define rep(i,n) for(int i=0;i

【HDOJ】【3555】Bomb

数位DP cxlove基础数位DP第二题 与上题基本相同(其实除了变成long long以外其实更简单了……) 1 //HDOJ 3555 2 #include<cmath> 3 #include<vector> 4 #include<cstdio> 5 #include<cstring> 6 #include<cstdlib> 7 #include<iostream> 8 #include<algorithm> 9 #d

【HDOJ】【3515】

DP/单调队列优化 呃……环形链求最大k子段和. 首先拆环为链求前缀和…… 然后单调队列吧<_<,裸题没啥好说的…… WA:为毛手写队列就会挂,必须用STL的deque? 1 //HDOJ 3415 2 #include<queue> 3 #include<cmath> 4 #include<vector> 5 #include<cstdio> 6 #include<cstring> 7 #include<cstdlib>