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. (转载)JavaWeb学习总结(五十三)——Web应用中使用JavaMail发送邮件

    博客源地址:http://www.cnblogs.com/xdp-gacl/p/4220190.html 现在很多的网站都提供有用户注册功能, 通常我们注册成功之后就会收到一封来自注册网站的邮件.邮件 ...

  2. ZOJ 3696 Alien's Organ

    泊松分布.... Alien's Organ Time Limit: 2 Seconds      Memory Limit: 65536 KB There's an alien whose name ...

  3. 【PHP升级】CentOS6.3编译安装 PHP5.4.38

    先前安装的PHP5.3.28(参考:CentOS6.3编译安装Nginx1.4.7 + MySQL5.5.25a + PHP5.3.28),现在准备升级PHP到5.4.38,有如下几个地方需要重新编译 ...

  4. Redis学习 - 配置属性:protected-mode

    根据redis的说明,protected-mode在同时存在如下两种情况时触发: 1) The server is not binding explicitly to a set of address ...

  5. JS实现图片预加载无需等待

    网站开发时经常需要在某个页面需要实现对大量图片的浏览;用javascript来实现一个图片浏览器,让用户无需等待过长的时间就能看到其他图片 网站开发时经常需要在某个页面需要实现对大量图片的浏览,如果考 ...

  6. BZOJ2007——[Noi2010]海拔

    1.题意:一个裸的最小割 2.分析:直接转成对偶图最短路就好了,水爆了!(雾) #include <queue> #include <cstdio> #include < ...

  7. linux c 笔记-1

    指令帮助: man xxx_command man 2 xxx_command man 3 xxx_command eg. 打开文件的函数open, 如果不清楚传参,则 man open man 2 ...

  8. Count Complete Tree Nodes

    Given a complete binary tree, count the number of nodes. Definition of a complete binary tree from W ...

  9. Metro下读取txt文件

    情况1:txt是Utf8格式的. 读取代码:IList<String> lines = await Windows.Storage.FileIO.ReadLinesAsync(file); ...

  10. FreeRTOS学习及移植笔记之一:开始FreeRTOS之旅

    1.必要的准备工作 工欲善其事,必先利其器,在开始学习和移植之前,相应的准备工作必不可少.所以在开始我们写要准备如下: 测试环境:我准备在STM32F103平台上移植和测试FreeRTOS系统 准备F ...