Ultraviolet A 436-Arbitrage (II) (floyd)

Source: Internet
Author: User

Ultraviolet A 436-Arbitrage (II) (floyd)
Ultraviolet A 436-Arbitrage (II)

Question Link

Given the exchange rate of currencies in some countries, I wonder if I can make money grow through constant currency exchange.

Train of Thought: floyd. After the event is finished, check whether the connection is greater than 1.

Code:

#include 
 
  #include 
  
   #include 
   
    #include 
    
     #include 
     using namespace std;const int N = 35;int n;double g[N][N];map
      
        hash;int main() {int cas = 0;while (~scanf("%d", &n) && n) {string a, b;hash.clear();for (int i = 1; i <= n; i++) {cin >> a;hash[a] = i;}int m;double f;for (int i = 1; i <= n; i++) {for (int j = 1; j <= n; j++) {if (i == j) g[i][j] = 1.0;else g[i][j] = 0;}}scanf("%d", &m);while (m--) {cin >> a >> f >> b;int u = hash[a], v = hash[b];g[u][v] = f;}for (int k = 1; k <= n; k++) {for (int i = 1; i <= n; i++) {for (int j = 1; j <= n; j++)g[i][j] = max(g[i][j], g[i][k] * g[k][j]);}}printf("Case %d: ", ++cas);int flag = 1;for (int i = 1; i <= n; i++) {if (g[i][i] > 1.0) {printf("Yes\n");flag = 0;break;}}if (flag) printf("No\n");}return 0;}
      
    
   
  
 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.