zoukankan      html  css  js  c++  java
  • hdu Stock Chase

    Stock Chase

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 159    Accepted Submission(s): 53
     
    Problem Description
    I have to admit, the solution I proposed last year for solving the bank cash crisis didn’t solve the whole economic crisis. As it turns out, companies don’t have that much cash in the first place. They have assets which are primarily shares in other companies. It is common, and acceptable, for one company to own shares in another. What complicates the issue is for two companies to own shares in each other at the same time. If you think of it for a moment, this means that each company now (indirectly) controls its own shares. New market regulation is being implemented: No company can control shares in itself, whether directly or indirectly. The Stock Market Authority is looking for a computerized solution that will help it detect any buying activity that will result in a company controlling its own shares. It is obvious why they need a program to do so, just imagine the situation where company A buying shares in B, B buying in C, and then C buying in A. While the first two purchases are acceptable. The third purchase should be rejected since it will lead to the three companies controlling shares in themselves. The program will be given all purchasing transactions in chronological order. The program should reject any transaction that could lead to one company controlling its own shares. All other transactions are accepted.
     
    Input
    Your program will be tested on one or more test cases. Each test case is specified on T + 1 lines. The first line specifies two positive numbers: (0 < N <= 234) is the number of companies and (0 < T <= 100, 000) is the number of transactions. T lines follow, each describing a buying transaction. Each transaction is specified using two numbers A and B where (0 < A,B <= N) indicating that company A wants to buy shares in company B. The last line of the input file has two zeros.
     
    Output
    For each test case, print the following line: k. R Where k is the test case number (starting at one,) R is the number of transactions that should be rejected. Note: There is a blank space before R.
     
    Sample Input
    3 6
    1 2
    1 3
    3 1
    2 1
    1 2
    2 3
    0 0
     
    Sample Output
    1. 2
     
     
    Source
    2009 ANARC
     
    Recommend
    lcy
     

    分析:用二维数组标记a,b的买卖关系,每次若a未买过b,就让所有有a股份的人拥有b所拥有的股份的所有人。

    #include<cstdio>
    #include<cstring>
    int vis[240][240];
    
    int main() {
        int n, i, T = 0, m, a, b, cnt, j;
        while (scanf("%d%d", &n, &m) != EOF && n) {
            cnt = 0;
            memset(vis,0,sizeof(vis));
            for (i = 1; i <= n; ++i)
                vis[i][i] = 1;
            while (m--) {
                scanf("%d%d", &a, &b);
                if (vis[b][a]) {
                    ++cnt;
                } else if (!vis[a][b]) {
                    for (i = 1; i <= n; ++i) {
                        if (vis[i][a]) {
                            for (j = 1; j <= n; ++j) {
                                if (vis[b][j])
                                    vis[i][j] = 1;
                            }
                        }
                    }
                }
            }
            printf("%d. %d\n", ++T, cnt);
        }
        return 0;
    }
  • 相关阅读:
    RESTful
    Node.js Express 框架
    Node.js Web 模块
    Node.js Path 模块
    JavaFX输入并显示字符串
    JavaFX手眼协调小游戏(赋源代码)
    JavaFX作业七参考
    管理运筹学(Additional Simplex Algorithm)
    JavaFX15.4 ( 创建一个簡单的计算器 ) 编写一个程序完成加法、减法、乘法和除法操作
    JavaFX移动小球
  • 原文地址:https://www.cnblogs.com/baidongtan/p/2687135.html
Copyright © 2011-2022 走看看