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

  1. //如果a->b则能到a点的也能到b点,b点能到达的点a点以及能到a点的也能到达。
  2. //注意重复。
  3. #include<iostream>
  4. #include<cstdio>
  5. #include<cstring>
  6. #include<queue>
  7. #include<vector>
  8. using namespace std;
  9. int n,m,map[][];
  10. void update(int a,int b)
  11. {
  12. map[a][b]=;
  13. for(int i=;i<=n;i++)
  14. {
  15. if(map[i][a])
  16. {
  17. map[i][b]=;
  18. }
  19. }
  20. for(int i=;i<=n;i++)
  21. {
  22. if(map[b][i])
  23. for(int j=;j<=n;j++)
  24. {
  25. if(map[j][b])
  26. map[j][i]=;
  27. }
  28. }
  29. }
  30. int main()
  31. {
  32. int a,b,k=;
  33. while(scanf("%d%d",&n,&m)&&n&&m)
  34. {
  35. int ans=;
  36. memset(map,,sizeof(map));
  37. for(int i=;i<m;i++){
  38. scanf("%d%d",&a,&b);
  39. if(map[a][b])
  40. continue;
  41. if(map[b][a]||a==b)
  42. {
  43. ans++;
  44. continue;
  45. }
  46. update(a,b);
  47. }
  48. printf("%d. %d\n",k++,ans);
  49. }
  50. return ;
  51. }

*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. CentOS Linux系统下更改Apache默认网站目录

    引言: Apache默认的网站目录是在/var/www/html,我们现在要把网站目录更改到/home/wwwroot/web1/htdocs,操作如下 准备工作: 创建目录: cd /home mk ...

  2. Mac键盘图标与对应快捷按键标志汇总

    Mac键盘图标与对应快捷按键 ⌘--Command () win键 ⌃ --Control ctrl键 ⌥--Option (alt) ⇧--Shift ⇪--Caps Lock fn--功能键就是 ...

  3. java13

    1:登录注册案例(理解) 2:Set集合(理解) (1)Set集合的特点 无序,唯一 (2)HashSet集合(掌握) A:底层数据结构是哈希表(是一个元素为链表的数组) B:哈希表底层依赖两个方法: ...

  4. 【转】sed 简明教程

    本文转自:http://coolshell.cn/articles/9104.html awk于1977年出生,今年36岁本命年,sed比awk大2-3岁,awk就像林妹妹,sed就是宝玉哥哥了.所以 ...

  5. Angular2 管道

    1. 说明 管道用来转换模板显示的内容,应用程序中经常出现获取数据,转换数据,显示数据的逻辑.管道就是用来在转换数据阶段起作用的.主要存在两种类型的管道,pure pipe和impure pipe 2 ...

  6. centos6.3安装python2.7, pip2.7, mysql

    参考: https://github.com/h2oai/h2o-2/wiki/Installing-python-2.7-on-centos-6.3.-Follow-this-sequence-ex ...

  7. Ubuntu设置环境变量 16.04

    打开终端并输入: sudo gedit /etc/environment. 2 输入用户密码.这时输入的密码是不可见的. 3 如图,在PATH="...."的末尾处添加: :/op ...

  8. .NET LINQ 数据分组

    数据分组      分组指将数据放入组中以便每个组中的元素共享公共特性的操作.   方法 方法名 说明 C# 查询表达式语法 Visual Basic 查询表达式语法 更多信息 GroupBy 对共享 ...

  9. imageNamed和imageWithContentsOfFile区别

    在 Apple 官方帮助文档提供了两个加载图片的方法 imageNamed , 其参数为图片的名字 imageWithContentsOfFile , 其参数是图片文件的路径 下面主要是说一下他们的区 ...

  10. TFS二次开发系列:一、TFS体系结构和概念

    TFS是Team Fundation Server的简称,是微软VSTS的一部分,它是Microsoft应用程序生命周期管理(ALM)工具的核心协作平台,简单的说它是管理和开发软件项目的整个生命周期的 ...