*HDU3357 判环
Stock Chase
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1787 Accepted Submission(s): 579
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.
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.
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.
//如果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 判环的更多相关文章
- hdu4975 A simple Gaussian elimination problem.(正确解法 最大流+删边判环)(Updated 2014-10-16)
这题标程是错的,网上很多题解也是错的. http://acm.hdu.edu.cn/showproblem.php?pid=4975 2014 Multi-University Training Co ...
- hdu4888 Redraw Beautiful Drawings 最大流+判环
hdu4888 Redraw Beautiful Drawings Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/6553 ...
- Leetcode 166. Fraction to Recurring Decimal 弗洛伊德判环
分数转小数,要求输出循环小数 如2 3 输出0.(6) 弗洛伊德判环的原理是在一个圈里,如果一个人的速度是另一个人的两倍,那个人就能追上另一个人.代码中one就是速度1的人,而two就是速度为2的人. ...
- Leetcode 202 Happy Number 弗洛伊德判环解循环
今天先谈下弗洛伊德判环,弗洛伊德判环原来是在一个圈内有两人跑步,同时起跑,一人的速度是另一人的两倍,则那个人能在下一圈追上另一个人,弗洛伊德判环能解数字会循环出现的题,比如说判断一个链表是不是循环链表 ...
- Dwarves (有向图判环)
Dwarves 时间限制: 1 Sec 内存限制: 64 MB提交: 14 解决: 4[提交][状态][讨论版] 题目描述 Once upon a time, there arose a huge ...
- COJ 3012 LZJ的问题 (有向图判环)
传送门:http://oj.cnuschool.org.cn/oj/home/problem.htm?problemID=1042 试题描述: LZJ有一个问题想问问大家.他在写函数时有时候很头疼,如 ...
- Legal or Not(拓扑排序判环)
http://acm.hdu.edu.cn/showproblem.php?pid=3342 Legal or Not Time Limit: 2000/1000 MS (Java/Others) ...
- E - Andrew and Taxi-二分答案-topo判环
E - Andrew and Taxi 思路 :min max 明显二分答案,二分需要破坏的那些边的中机器人数量最多的那个. check 过程建边时直接忽略掉小于 mid 的边,这样去检验有无环存 ...
- HDU4514 湫湫系列故事——设计风景线 ——树的直径/树形dp+判环
中文题面,给出一个图,问能不能成环,如果可以就输出YES.否则输出该树的直径. 这里的判环我们用路径压缩的并查集就能很快的判断出来,可以在输入的同时进行判断.这题重点就是求树的直径. 树直径的性质可以 ...
随机推荐
- R语言:规划求解优化ROI
今天看到一篇文章介绍如何用excel建模对ROI 进行规划求解. 蓝鲸的网站分析笔记 成本 Cost 每次点击费用 CPC 点击量 \[clickRate = \frac{cost}{CPC}\] 转 ...
- css 基础---选择器
1.css基础 selector {property: value} eg: h1 {color:red; font-size:14px;} p { text-align: center; color ...
- Linux网络下载命令 wget 简介
wget 是一个命令行的下载工具.对于我们这些 Linux 用户来说,几乎每天都在使用它.下面为大家介绍几个有用的 wget 小技巧,可以让你更加高效而灵活的使用 wget. $ wget -r -n ...
- 微信公共服务平台开发(.Net 的实现)12-------网页授权(上 :更加深入理解OAuth2.0 )
我们首先来认识一下OAuth协议吧,这个东西很早就听说过,总觉得离我很远(我的项目用不到这些),但是最近不得不学习一下了.我在网上找了一些解释,认为解释的最好的是这样说的(出处:http://hi.b ...
- Linux串口中的超时设置
在Linux下使用串口通信时,默认的阻塞模式是不实用的.而采用select或epoll机制的非阻塞模式,写代码有比较麻烦.幸好Linux的串口自己就带有超时机制. Linux下使用termios.h中 ...
- 史上最简单,一步集成侧滑(删除)菜单,高仿QQ、IOS。
重要的话 开头说,not for the RecyclerView or ListView, for the Any ViewGroup. 本控件不依赖任何父布局,不是针对 RecyclerView. ...
- 查看cpu的信息cat /proc/cpuinfo
cat /proc/cpuinfo processor : vendor_id : GenuineIntel cpu family : model : model name : Intel(R) Co ...
- 基于命令行编译打包phonegap for android应用 分类: Android Phonegap 2015-05-10 10:33 73人阅读 评论(0) 收藏
也许你习惯了使用Eclipse编译和打包Android应用.不过,对于使用html5+js开发的phonegap应用,本文建议你抛弃Eclipse,改为使用命令行模式,绝对的快速和方便. 一直以来,E ...
- jrebel实现tomcat热部署
-noverify -javaagent:D:\jrebel.jar 注:频繁切换工程的时候,热部署可能会失效; 解决办法是:先把项目拖到tomcat下发布,然后在没有配置上面这行代码的情况下,让项目 ...
- Android Studio 之 no render target selected
今天第一次使用android studio, 莫名其妙出现 no render target selected的错误,没有设计界面, 各种百度之后在 stackoverflow.com/questio ...