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. linux运维、架构之路-shell编程(二)

    一.流程控制语句 1.if语句 ①if单分支:一个条件一个结果 1 2 3 4 if 条件   then      命令 fi ②if双分支:一个条件两个结果 1 2 3 4 5 6 if 条件    ...

  2. sax技术解析xml下jaxp解析器详细代码

    *解析xml的两种技术dom和sax dom:根据xml的层级结构在内存中分配一个树形结构,把xml标签,属性,文本封装成对象. sax方式:事件驱动,边读边解析. 在javax.xml.parser ...

  3. 【c学习-13】

    /*库函数 1:数学函数库:math.h abs():绝对值; acos(),asin(),atan():cos,sin,tan的倒数 exp():指数的次幂 pow(x,y):x的y次幂 log() ...

  4. HBase学习(三):数据模型

    和传统的关系型数据库类似,HBase以表(Table)的方式组织数据.HBase的表由行(Row)和列(Column)共同构成,与关系型数据库不同的是HBase有一个列族(ColumnFamily)的 ...

  5. CentOS6.9重新安装python2.6.6和yum

    CentOS6.9重新安装python2.6.6和yum 本文转载自昔日暖阳,原文地址:http://www.osheep.cn/4801.html 最近为了部署一个Python应用到腾讯云服务器,强 ...

  6. POJ1236_A - Network of Schools _强连通分量::Tarjan算法

    Time Limit: 1000MS   Memory Limit: 10000K Description A number of schools are connected to a compute ...

  7. 线程基础三 使用C#中的lock关键词

    C#中lock关键字主要是为确保当一个线程使用某些资源时,同时无法其他线程无法使用该资源.下面我们看看下面的小例子. static void Main(string[] args) { var c = ...

  8. abap<itab>refresh,clear,free

    在ABAP开发过程中,clear,refresh,free都有用来清空内表的作用,但用法还是有区别的. clear itab,清空内表行以及工作区,但保存内存区. clear itab[],清空内表行 ...

  9. windows下subversion服务器搭建

    一.下载subversion服务器端和客户端软件 1.subversion下载地址:http://subversion.tigris.org/ 2.svn比较流行的客户端Tortoisesvn下载地址 ...

  10. oracle查询优化,存储过程select表循环插入另一个表,以及索引重建

    查询语句pl/sql中用F5优化语句 ORACLE的explain plan工具的作用只有一个,获取语句的执行计划1.语句本身并不执行,ORACLE根据优化器产生理论上的执行计划2.语句的分析结果存放 ...