Stock Chase--HDOJ
来源:互联网 发布:yy主播拍的网络大电影 编辑:程序博客网 时间:2024/05/17 09:19
Stock Chase
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 374 Accepted Submission(s): 131
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
- 2
Source
2009 ANARC
Recommend
lcy
#include<iostream>#include<stdio.h>#include<algorithm>#include<string>#include<string.h>#include<math.h>#include<map>#include<set>#include<string>#define mod 1000000007using namespace std;int ans,n,t;int link[250][250];void Update(int a,int b){ link[a][b] = 1; int numa=0,numb=0,aa[250],bb[250]; for(int i=1; i<=n; ++i) { if(link[i][a])//能到a的,也能到b { link[i][b] = 1; aa[numa++] = i; } if(link[b][i])//b能到的,a也能到 { link[a][i] = 1; bb[numb++] = i; } } //能到a的点,也能到b所能到的点 for(int i=0; i<numa; ++i) { for(int j=0; j<numb; ++j) { link[aa[i]][bb[j]] = 1; } }}int main(void){// freopen("in.txt","r",stdin); int num=1; while(scanf("%d %d",&n,&t) && (n+t)) { ans = 0; memset(link,0,sizeof(link)); for(int i=0; i<t; ++i) { int a,b; scanf("%d %d",&a,&b); if(link[b][a] || a==b) { ans++; continue; } //如果link[a][b]为1的话,就没必要再执行一次了 //不加这个判断,就会超时 if(link[a][b] == 0), Update(a,b); } printf("%d. %d\n",num++,ans); } return 0;}
- Stock Chase--HDOJ
- 【DP】 HDOJ 3357 Stock Chase
- Stock Chase hdu3357 图论
- POJ 3997 Stock Chase
- HDU 3357 Stock Chase
- HDU 3357 Stock Chase
- 杭电hdu 3357 Stock Chase 图
- HDU 3357 Stock Chase(类拓扑)
- hdu 3357 Stock Chase【floyd判成环】
- POJ 3997 Stock Chase 已被翻译
- Building a Better ASP.NET 1.1 BasePage Framework --By Chase Thomas
- POJ3997Stock Chase
- zoj 1019 Illusive chase
- ZOJ1019 Illusive Chase
- poj 1071 Illusive Chase
- zoj 1019 Illusive Chase
- zoj 1019 Illusive Chase
- poj1071 && zoj1019Illusive Chase(dfs)
- 单例模式
- Linux的常用指令
- 实用Chrome插件-OneTab
- 使用J-flash arm下载程序
- tf.while_loop
- Stock Chase--HDOJ
- MySQL常见的查询语句的运用
- 使用安信可ESP8266IDE编辑工具使用最新的乐鑫RTOS固件
- Linux的SOCKET编程详解
- Lua 5.3 源码分析(十)线程的执行与中断
- java设计模式之代理模式举例
- IDEA下创建Web项目
- java服务器对json数据进行gzip压缩
- PIL 库的使用入门