您的位置:首页 > 其它

POJ 3997 Stock Chase

2013-09-26 15:25 190 查看
Stock Chase

Time Limit: 1000MSMemory Limit: 65536K
Total Submissions: 455Accepted: 131
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.
Sample Input

1. 2

Source

anarc 2009

题目大意:有N个公司,A公司可以买B公司的股票,B公司可以买C公司的股票,如此A公司会间接持有C公司的股票,这种操作非法,所以不能传递,按照时间顺序给出T次购买请求,问有多少次非法的购买请求会被拒绝。

解题思路:运用dp的思想压缩下路径。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: