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. 新知识 HtMl 5

    快要毕业了,即将走向实习岗位,但是这日子过的太无聊了,昨天逃课回宿舍打开电脑想看电影但是没什么好看的,于是上床睡觉了,越躺越无聊,然后爬了起来到学习图书馆找了本HTML5的课本,学习了起来(我感觉ht ...

  2. 【HCNE题型自我考究】

      H3CNE题目归结 制定标准 组织: 802.1X协议起源于标准的无线局域网协议802.11.主要目的是为了解决有线局域网用户的接入认证问题. 426.一个包含有华为等多厂商设备的交换网络,其VL ...

  3. ThinkPHP之__construct()和__initialize()

    ThinkPHP中的__initialize()和类的构造函数__construct()网上有很多关于__initialize()的说法和用法,总感觉不对头,所以自己测试了一下.将结果和大家分享.不对 ...

  4. Python的Bottle框架中实现最基本的get和post的方法的教程

    这篇文章主要介绍了Python的Bottle框架中实现最基本的get和post的方法的教程,Bottle框架在Python开发者中的人气很高,需要的朋友可以参考下 1.GET方式: # -*- cod ...

  5. linux的date常用命令

    1.显示现在时间 date 2.显示今天日期 date +"%F" date +"%Y-%m-%d" 3.现在时间转化为时间戳 date +%s 4.指定某日期 ...

  6. 事物总线模式实例——EventBus实例详解

    事件总线模式是一种广泛运用于安卓开发之中的一种软件架构模式,而事件总线模式在安卓开发中最广泛的应用莫过于AndroidStudio提供的EventBus,所以我就EventBus来谈谈对事件总线模式的 ...

  7. ruby 操作csv

    1.读取csv 文件中读取:一次读入全部(设置headers使  CSV#shift()  以CSV::Row对象返回而不是数组:使  CSV#read()  返回 CSV::Table 对象而不是数 ...

  8. atlas+mysql部署mysql读写分离

    1.atlas 简介 Atlas是由 Qihoo 360公司Web平台部基础架构团队开发维护的一个基于MySQL协议的数据中间层项目.它在MySQL官方推出的MySQL-Proxy 0.8.2版本的基 ...

  9. C errno是否是线程安全的

    本文同时发表在https://github.com/zhangyachen/zhangyachen.github.io/issues/138 在使用多线程时,遇到了一个问题:线程例程中如果需要使用er ...

  10. R语言学习笔记(三):零碎知识点(1-10)

    1--c() c表示"连接"(concatenate). 在R中向量是连续存储的,因此不能插入或删除元素. 2--seq() seq()的特殊用法,可以用在for循环里for(i ...