Stock Chase

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1201    Accepted Submission(s): 363

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
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  3356 3358 3359 3360 3351 
 
 //250MS    496K    793 B    G++
/* 题意:
给出n个公司的联系,给出m个关系(单向图),要求不能形成环,
问要去掉多少个关系。 froyd变形:
此题解题形式类似froyd,属于图论题。
思路不难,先记录其每一次的关系,有矛盾则去掉,没矛盾加入,
并且更新图。
更新情况:
1、 g[i][a]&&g[a][b]&&g[b][j]=>g[i][j]
2、 g[i][a]&&g[a][b]=>g[i][b]
3、 g[a][b]&&g[b][i]=>g[a][i] 时间复杂度应为O(n*n*m) = =! */
#include<stdio.h>
#include<string.h>
int g[][];
int n,m;
int main(void)
{
int a,b,k=;
while(scanf("%d%d",&n,&m),m+n)
{
memset(g,,sizeof(g));
int cnt=;
while(m--){
scanf("%d%d",&a,&b);
if(g[b][a] || a==b){
cnt++;continue;
}
if(g[a][b]) continue;
g[a][b]=;
for(int i=;i<=n;i++){
if(g[i][a])
for(int j=;j<=n;j++){
if(g[b][j]) g[i][j]=;
}
}
for(int i=;i<=n;i++){
if(g[i][a]) g[i][b]=;
if(g[b][i]) g[a][i]=;
}
}
printf("%d. %d\n",k++,cnt);
}
return ;
}

hdu 3357 Stock Chase (图论froyd变形)的更多相关文章

  1. POJ 3997 Stock Chase

    Stock Chase Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 455   Accepted: 131 Descrip ...

  2. HDU 3094 树上删边 NIM变形

    基本的树上删边游戏 写过很多遍了 /** @Date : 2017-10-13 18:19:37 * @FileName: HDU 3094 树上删边 NIM变形.cpp * @Platform: W ...

  3. HDU 3357

    http://acm.hdu.edu.cn/showproblem.php?pid=3357 给出公司间的控股关系,问有多少组不合法数据,自己控股自己不合法,a控股b,b控股c,则a控股c 其实就是找 ...

  4. HDU 5934 Bomb 【图论缩点】(2016年中国大学生程序设计竞赛(杭州))

    Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  5. hdu 3357 水题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3357 #include <cstdio> #include <cmath> # ...

  6. HDU 4435 charge-station bfs图论问题

    E - charge-station Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  7. hdu 4163 Stock Prices 水

    #include<bits/stdc++.h> using namespace std; #define ll long long #define pi (4*atan(1.0)) #de ...

  8. HDU 5534 Partial Tree (完全背包变形)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5534 题意: 给你度为1 ~ n - 1节点的权值,让你构造一棵树,使其权值和最大. 思路: 一棵树上 ...

  9. HDU 5961 传递 【图论+拓扑】 (2016年中国大学生程序设计竞赛(合肥))

    传递 Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)     Problem ...

随机推荐

  1. HTTP缓存初探

    缓存的作用 用户访问一个web页面的频率远高于web页面更新的频率,因此多数时候用户从服务器获取的html.js.css以及图片等内容都是相同的,如果每次访问都从服务器获取这些静态内容即降低了页面加载 ...

  2. java后台去除JSON数组的重复值

    假设原始Json数组是这样的 原始JSONArry:[{"Value":"15153129877","Key":"09770985 ...

  3. Docker与FastDFS的安装命令及使用

    Docker特点 1)上手快 用户只需要几分钟,就可以把自己的程序“Docker 化”.Docker 依赖于“写时复制” (copy-on-write)模型,使修改应用程序也非常迅速,可以说达到“随心 ...

  4. U盘被分区后恢复方法

    一:运行cmd 二:输入diskpart,按enter. 三:输入list disk,按enter. 四:选择优U盘,输入select disk X(X代表磁盘后面的数字0.1,可磁盘的大小来判断数字 ...

  5. java服务端项目开发规范

    更新内容 2015-03-13 (请先更新svn的mybatis.xml.BaseMapper.java.Pager.java文件) 加入测试类规范 加入事物控制规范 加入mapper接口规则 ...

  6. Leecode刷题之旅-C语言/python-69x的平方根

    /* * @lc app=leetcode.cn id=69 lang=c * * [69] x 的平方根 * * https://leetcode-cn.com/problems/sqrtx/des ...

  7. python第一个程序-->hello world

    最近在网上看到一个小笑话,一个程序员的自我嘲讽:“我精通所以计算机语言的hello world!” 好了,废话不多说了,开始撸代码: 我本人用的是python3.6版本,各位可以通过官网下载自己喜欢的 ...

  8. 2.PostgreSQL安装详细步骤(windows)【转】

    感谢 Junn9527 PostgreSQL安装:一.windows下安装过程安装介质:postgresql-9.1.3-1-windows.exe(46M),安装过程非常简单,过程如下:1.开始安装 ...

  9. MVC中输入的保护验证用:HttpServerUtility.HtmlEncode

    安全说明: 上面的代码使用HttpServerUtility.HtmlEncode来保护应用程序的恶意输入 (即 JavaScript).详细信息请参阅如何: 在 Web 应用程序,通过应用 HTML ...

  10. Android开发——View绘制过程源码解析(一)

    )UNSPECIFIED:表示View可以设置成任意的大小,没有任何限制.这种情况比较少见. 2. MeasureSpec的生成过程 2.1 顶级View的MeasureSpec // desired ...