Stock Chase

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

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
 
题意:
 n个点,m条有向边,不能有环,不能有环,问有多少边如果加上会出现环
代码:

 //如果a->b则能到a点的也能到b点,b点能到达的点a点以及能到a点的也能到达。
//注意重复。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;
int n,m,map[][];
void update(int a,int b)
{
map[a][b]=;
for(int i=;i<=n;i++)
{
if(map[i][a])
{
map[i][b]=;
}
}
for(int i=;i<=n;i++)
{
if(map[b][i])
for(int j=;j<=n;j++)
{
if(map[j][b])
map[j][i]=;
}
}
}
int main()
{
int a,b,k=;
while(scanf("%d%d",&n,&m)&&n&&m)
{
int ans=;
memset(map,,sizeof(map));
for(int i=;i<m;i++){
scanf("%d%d",&a,&b);
if(map[a][b])
continue;
if(map[b][a]||a==b)
{
ans++;
continue;
}
update(a,b);
}
printf("%d. %d\n",k++,ans);
}
return ;
}

*HDU3357 判环的更多相关文章

  1. hdu4975 A simple Gaussian elimination problem.(正确解法 最大流+删边判环)(Updated 2014-10-16)

    这题标程是错的,网上很多题解也是错的. http://acm.hdu.edu.cn/showproblem.php?pid=4975 2014 Multi-University Training Co ...

  2. hdu4888 Redraw Beautiful Drawings 最大流+判环

    hdu4888 Redraw Beautiful Drawings Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/6553 ...

  3. Leetcode 166. Fraction to Recurring Decimal 弗洛伊德判环

    分数转小数,要求输出循环小数 如2 3 输出0.(6) 弗洛伊德判环的原理是在一个圈里,如果一个人的速度是另一个人的两倍,那个人就能追上另一个人.代码中one就是速度1的人,而two就是速度为2的人. ...

  4. Leetcode 202 Happy Number 弗洛伊德判环解循环

    今天先谈下弗洛伊德判环,弗洛伊德判环原来是在一个圈内有两人跑步,同时起跑,一人的速度是另一人的两倍,则那个人能在下一圈追上另一个人,弗洛伊德判环能解数字会循环出现的题,比如说判断一个链表是不是循环链表 ...

  5. Dwarves (有向图判环)

    Dwarves 时间限制: 1 Sec  内存限制: 64 MB提交: 14  解决: 4[提交][状态][讨论版] 题目描述 Once upon a time, there arose a huge ...

  6. COJ 3012 LZJ的问题 (有向图判环)

    传送门:http://oj.cnuschool.org.cn/oj/home/problem.htm?problemID=1042 试题描述: LZJ有一个问题想问问大家.他在写函数时有时候很头疼,如 ...

  7. Legal or Not(拓扑排序判环)

    http://acm.hdu.edu.cn/showproblem.php?pid=3342 Legal or Not Time Limit: 2000/1000 MS (Java/Others)   ...

  8. E - Andrew and Taxi-二分答案-topo判环

    E - Andrew and Taxi 思路 :min max   明显二分答案,二分需要破坏的那些边的中机器人数量最多的那个. check 过程建边时直接忽略掉小于 mid 的边,这样去检验有无环存 ...

  9. HDU4514 湫湫系列故事——设计风景线 ——树的直径/树形dp+判环

    中文题面,给出一个图,问能不能成环,如果可以就输出YES.否则输出该树的直径. 这里的判环我们用路径压缩的并查集就能很快的判断出来,可以在输入的同时进行判断.这题重点就是求树的直径. 树直径的性质可以 ...

随机推荐

  1. (zz)linux awk

    博文转载自http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2858470.html 谢谢原作者.条理很清楚,由浅入深.敲了每一行命令,正确无误. ...

  2. PHP变量作用域详解(二)

    学过C的人用PHP的时候一般会相当顺手,而且感到PHP太方便太轻松.但在变量作用域这方面却与C有不同的地方,搞不好会相当郁闷,就找不到错误所在.昨晚就与到这么一个问题,是全局变量在函数中的问题.今天搜 ...

  3. Linux进程间通信(九):数据报套接字 socket()、bind()、sendto()、recvfrom()、close()

    前一篇文章,Linux进程间通信——使用流套接字介绍了一些有关socket(套接字)的一些基本内容,并讲解了流套接字的使用,这篇文章将会给大家讲讲,数据报套接字的使用. 一.简单回顾——什么是数据报套 ...

  4. Unix/Linux进程间通信(一):概述

    序 Linux下的进程通信手段基本上是从Unix平台上的进程通信手段继承而来的.而对Unix发展做出重大贡献的两大主力AT&T的贝尔实验室及BSD(加州大学伯克利分校的伯克利软件发布中心)在进 ...

  5. Shell入门教程:流程控制(5)for 循环

    for循环的运作方式,是将 串行 的元素的元素一一取出,依序放入制定的变量中,然后重复执行含括的命令区域(在 do 与 done 之间),直到所有元素取尽为止. 其中,串行是一些字符串的组合,彼此用 ...

  6. Python自动化之django URL

    URL url(r'^detail-(?P<nid>\d+)-(?P<uid>\d+).html', views.detail) 会把(?P\d+)和(?P\d+)传到后台 需 ...

  7. springMVC学习之url重写:urlrewrite with tuckey UrlRewriteFilter

    在开发网站时地址栏的一些信息是我们不希望让客户看到,所以在开发时候就会涉及到url重写的问题. 下面介绍一种常用的url地址重写的方法. 1.利用maven下载相关jar文件,pom文件配置如下: & ...

  8. javascript 中的 bind (编辑中。。。。)

    这篇文章说的非常好!http://my.oschina.net/blogshi/blog/265415 我的体会就是,函数中的this,指的是运行时,它是被哪个对象调用的.因为javascrpit的函 ...

  9. securecrt设置 (外观,中文不乱码)

    最终效果图 这叫做先入为主,哈哈~~ 详细设置,action!!!! ############### 菜单栏:  选项---会话选项   一.终端---仿真 1.终端选择 linux 2.ANSI颜色 ...

  10. GitHub使用心得

    PHP今天算是学习结束了;版本控制也了解很久了,比较熟悉的是svn,Git一直都不太熟,也可能是它是英文的缘故,感觉很费劲,所以用的不多,但不得不说,它功能真的很强大;今天试着和朋友用Git开发一个简 ...