hdu3357Stock Chase (暴搜)
来源:互联网 发布:自适应网址导航源码 编辑:程序博客网 时间:2024/06/15 02:32
Stock Chase
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 31 Accepted Submission(s) : 13
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.
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
1 2
1 3
3 1
2 1
1 2
2 3
0 0
本题有点巧妙,用了类似于floyd的暴搜,将两两存在路径的点都连起来
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<queue>#define MAXN 250using namespace std;int n,m;int map[MAXN][MAXN];void update(int a,int b) //将所有边都化简,找出所有的捷径,并连接(d->a->b->c,连接a->c,d->b,d->c){map[a][b]=1;for(int i=1;i<=n;i++) //先将所有能到b的点连起来if(map[i][a]) map[i][b]=1;for(int i=1;i<=n;i++){if(map[b][i]) //将所有b能到的点和所有能到b的点相连{for(int j=1;j<=n;j++){if(map[j][b])map[j][i]=1;}}}}int main(){int i,a,b,ans,t;t=0;while(scanf("%d%d",&n,&m),n+m){t++;ans=0;memset(map,0,sizeof(map));for(i=1;i<=m;i++){scanf("%d%d",&a,&b);if(a==b)ans++;else if(map[b][a])ans++;else if(map[a][b]==0) update(a,b);}cout<<t<<". "<<ans<<endl;}return 0;}
阅读全文
0 0
- hdu3357Stock Chase (暴搜)
- POJ3997Stock Chase
- zoj 1019 Illusive chase
- ZOJ1019 Illusive Chase
- poj 1071 Illusive Chase
- zoj 1019 Illusive Chase
- Stock Chase hdu3357 图论
- zoj 1019 Illusive Chase
- POJ 3997 Stock Chase
- poj1071 && zoj1019Illusive Chase(dfs)
- zoj 1019 Illusive Chase
- HDU 3357 Stock Chase
- hdu 1364 Illusive Chase
- HDU 3357 Stock Chase
- how to chase a girl
- zoj 1019 Illusive Chase --- dfs
- POJ1071 Illusive Chase(DFS)
- 【DP】 HDOJ 3357 Stock Chase
- 【二分图】poj 2239 Selecting Courses
- 秦九昭算法
- [模板]线性基
- Caused by: org.hibernate.PropertyNotFoundException:
- 实现一个栈Stack,要求实现Push(入栈)、Pop(出栈)、Min(返回最小值的操作)的时间复杂度为O(1)
- hdu3357Stock Chase (暴搜)
- 同济大学Openwrt路由器 ipv6教程(新手导向)
- httpclient连接池在ES Restful API请求中的应用
- leetcode经典组合类问题,采用dfs思想
- 【转】多个类定义attr属性重复的问题:Attribute "xxx" has already been defined
- VMWARE 简单的操作
- Ubuntu16.04下安装OpenCV-3.2.0
- python求解LeetCode题目,找出数组中的Majority element元素
- 快速排序总结