• [HDOJ1217]Arbitrage(floyd)


    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217

    题意:给一些汇率,问是否可以套利。

    套利就是经过一些汇率的转换,最终使得本金额比起始金额大。

    最短路跑所有的汇率情况,看看有没有使得最终的汇率是大于1的。

      1 /*
      2 ━━━━━┒ギリギリ♂ eye!
      3 ┓┏┓┏┓┃キリキリ♂ mind!
      4 ┛┗┛┗┛┃\○/
      5 ┓┏┓┏┓┃ /
      6 ┛┗┛┗┛┃ノ)
      7 ┓┏┓┏┓┃
      8 ┛┗┛┗┛┃
      9 ┓┏┓┏┓┃
     10 ┛┗┛┗┛┃
     11 ┓┏┓┏┓┃
     12 ┛┗┛┗┛┃
     13 ┓┏┓┏┓┃
     14 ┃┃┃┃┃┃
     15 ┻┻┻┻┻┻
     16 */
     17 #include <algorithm>
     18 #include <iostream>
     19 #include <iomanip>
     20 #include <cstring>
     21 #include <climits>
     22 #include <complex>
     23 #include <cassert>
     24 #include <cstdio>
     25 #include <bitset>
     26 #include <vector>
     27 #include <deque>
     28 #include <queue>
     29 #include <stack>
     30 #include <ctime>
     31 #include <set>
     32 #include <map>
     33 #include <cmath>
     34 using namespace std;
     35 #define fr first
     36 #define sc second
     37 #define cl clear
     38 #define BUG puts("here!!!")
     39 #define W(a) while(a--)
     40 #define pb(a) push_back(a)
     41 #define Rint(a) scanf("%d", &a)
     42 #define Rs(a) scanf("%s", a)
     43 #define FRead() freopen("in", "r", stdin)
     44 #define FWrite() freopen("out", "w", stdout)
     45 #define Rep(i, len) for(int i = 0; i < (len); i++)
     46 #define For(i, a, len) for(int i = (a); i < (len); i++)
     47 #define Cls(a) memset((a), 0, sizeof(a))
     48 #define Clr(a, x) memset((a), (x), sizeof(a))
     49 #define Full(a) memset((a), 0x7f7f7f, sizeof(a))
     50 #define lrt rt << 1
     51 #define rrt rt << 1 | 1
     52 #define pi 3.14159265359
     53 #define RT return
     54 #define lowbit(x) x & (-x)
     55 #define onenum(x) __builtin_popcount(x)
     56 typedef long long LL;
     57 typedef long double LD;
     58 typedef unsigned long long ULL;
     59 typedef pair<int, int> pii;
     60 typedef pair<string, int> psi;
     61 typedef pair<LL, LL> pll;
     62 typedef map<string, int> msi;
     63 typedef vector<int> vi;
     64 typedef vector<LL> vl;
     65 typedef vector<vl> vvl;
     66 typedef vector<bool> vb;
     67 
     68 const int maxn = 33;
     69 const double eps = 1e-9;
     70 map<string, int> name;
     71 double dp[maxn][maxn];
     72 int n, m;
     73 char a[81], b[81];
     74 double ex;
     75 
     76 int main() {
     77     // FRead();
     78     int _ = 1;
     79     while(~Rint(n) && n) {
     80         int cnt = 1;
     81         name.clear(); Cls(dp);
     82         For(i, 1, n+1) {
     83             Rs(a);
     84             name[a] = i;
     85             dp[i][i] = 1.0;
     86         }
     87         Rint(m);
     88         Rep(i, m) {
     89             cin >> a >> ex >> b;
     90             dp[name[a]][name[b]] = ex;
     91         }
     92         For(k, 1, n+1) {
     93             For(i, 1, n+1) {
     94                 For(j, 1, n+1) {
     95                     if(dp[i][k] * dp[k][j] > dp[i][j]) {
     96                         dp[i][j] = dp[i][k] * dp[k][j];
     97                     }
     98                 }
     99             }
    100         }
    101         bool flag = 0;
    102         For(i, 1, n+1) {
    103             if(dp[i][i] > 1) {
    104                 flag = 1;
    105                 printf("Case %d: Yes
    ", _++);
    106                 break;
    107             }
    108         }
    109         if(!flag) printf("Case %d: No
    ", _++);
    110     }
    111     RT 0;
    112 }
  • 相关阅读:
    Android数据的四种存储方式SharedPreferences、SQLite、Content Provider和File (二) —— SQLite
    理解 Continuation
    99种用Racket说I love you的方式
    Racket Cheat Sheet
    scheme 教程 #lang racket
    开始学习Scheme
    MIT Scheme 的基本使用
    CPS变换
    SECD machine
    scheme 之门
  • 原文地址:https://www.cnblogs.com/kirai/p/5873606.html
Copyright © 2020-2023  润新知