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. tyvj1938 最优战舰

    描述 太空战队顺利地完成了它的第一次使命,这一行动的受益者陆军本部当即决定,请陆军的战士们投票选出最优战舰并报司令总部进行表彰.为防止有人利用高科技手段造假,陆军本部决定使用最原始的方法进行投票.可不 ...

  2. noip2015 运输计划

    描述 公元 2044 年,人类进入了宇宙纪元.L 国有 nn 个星球,还有 n−1n−1 条双向航道,每条航道建立在两个星球之间,这 n−1n−1 条 航道连通了 L 国的所有星球. 小 P 掌管一家 ...

  3. JSP动作元素之include

    采用include指令导入的页面输入静态导入,采用<jsp:include-/>指令属于动态导入. 语法格式如下: <jsp:include page="{relative ...

  4. 关闭Linux防火墙(iptables) 及 SELinux

    一.关闭防火墙 1.重启后永久性生效: 开启:chkconfig iptables on 关闭:chkconfig iptables off 2.即时生效,重启后失效: 开启:service ipta ...

  5. JavaScript学习总结(二)数组和对象部分

    pt学习总结(二)数组和对象部分 2016-09-16    分类:WEB开发.编程开发.首页精华暂无人评论     来源:trigkit4 分享到:更多1 对象部分 Object类型 Object  ...

  6. poj 1192

    此题亦一眼看出算法,一次AC. 没什么好讲的,就是一个普通的树形动规. 用dp[n][0]表示n号顶点不取时的最大值,dp[n][1]表示n号顶点取时的最大值. dp[n][0]=max{dp[x][ ...

  7. word20161215

    name / 名称 name mapping / 名称映射 name resolution / 名称解析 name server (NS) resource record / 名称服务器资源记录 na ...

  8. Redis Cluster搭建方法简介22211111

    Redis Cluster搭建方法简介 (2013-05-29 17:08:57) 转载▼       Redis Cluster即Redis的分布式版本,将是Redis继支持Lua脚本之后的又一重磅 ...

  9. ACM/ICPC 之 ACM计算机工厂-EK算法(POJ3436)

    题意有点难读懂 //网络流-EK算法-ACM计算机工厂-构图重点 //Time:0Ms Memory:208K #include <iostream> #include<cstrin ...

  10. xcode 常见错误报错问题!

    1:module  file '/Users/shaka/Library/Developer/Xcode/DerivedData/ModuleCache/92IKIZLYISUT/Darwin-2OA ...