POJ 3997 Stock Chase
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 455 | Accepted: 131 |
Description
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
The last line of the input file has two zeros.
Output
k. R
Where k is the test case number (starting at one,) R is the number of transactions that should be rejected.
Sample Input
3 6
1 2
1 3
3 1
2 1
1 2
2 3
0 0
Sample Output
1. 2
Source
#include <iostream>
#include <cstdio>
using namespace std; const int maxn=300;
bool dp[maxn][maxn];
int n,m,casen=0; void initial(){
for(int i=0;i<=n;i++)
for(int j=0;j<=n;j++)
dp[i][j]=false;
for(int i=0;i<=n;i++)
dp[i][i]=true;
} void computing(){
int ans=0,u,v;
while(m--){
scanf("%d%d",&u,&v);
if(dp[v][u]){
ans++;
}else if(!dp[u][v]){
dp[u][v]=true;
for(int i=1;i<=n;i++){
if(!dp[i][u]) continue;
dp[i][v]=true;
for(int j=1;j<=n;j++){
if(!dp[v][j]) continue;
dp[i][j]=true;
dp[u][j]=true;
}
}
}
}
casen++;
printf("%d. %d\n",casen,ans);
} int main(){
while(scanf("%d%d",&n,&m)!=EOF && (m||n)){
initial();
computing();
}
return 0;
}
POJ 3997 Stock Chase的更多相关文章
- POJ 3903 Stock Exchange (E - LIS 最长上升子序列)
POJ 3903 Stock Exchange (E - LIS 最长上升子序列) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action ...
- hdu 3357 Stock Chase (图论froyd变形)
Stock Chase Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- POJ 3903 Stock Exchange
Stock Exchange Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2954 Accepted: 1082 De ...
- POJ - 3903 Stock Exchange(LIS最长上升子序列问题)
E - LIS Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Descripti ...
- Poj 3903 Stock Exchange(LIS)
一.Description The world financial crisis is quite a subject. Some people are more relaxed while othe ...
- POJ 3903 Stock Exchange 最长上升子序列入门题
题目链接:http://poj.org/problem?id=3903 最长上升子序列入门题. 算法时间复杂度 O(n*logn) . 代码: #include <iostream> #i ...
- {POJ}{3903}{Stock Exchange}{nlogn 最长上升子序列}
题意:求最长上升子序列,n=100000 思路:O(N^2)铁定超时啊....利用贪心的思想去找答案.利用栈,每次输入数据检查栈,二分查找替换掉最小比他大的数据,这样得到的栈就是更优的.这个题目确实不 ...
- LIS(nlogn) POJ 3903 Stock Exchange
题目传送门 题意:LIS最长递增子序列 O(nlogn) 分析:设当前最长递增子序列为len,考虑元素a[i]; 若d[len]<a[i],则len++,并使d[len]=a[i]; 否则,在d ...
- poj 3903 Stock Exchange(最长上升子序列,模版题)
题目 #include<stdio.h> //最长上升子序列 nlogn //入口参数:数组名+数组长度,类型不限,结构体类型可以通过重载运算符实现 //数组下标从1号开始. int bs ...
随机推荐
- 可持久化Trie树
代码 ; struct PerTrie { ][ChSize]; ]; void init() { memset(next[],,])); inf[]=; id=; } int GetId(char ...
- 【HDU3371】Connect the Cities(MST基础题)
注意输入的数据分别是做什么的就好.还有,以下代码用C++交可以过,而且是500+ms,但是用g++就会TLE,很奇怪. #include <iostream> #include <c ...
- C++私有构造函数
一. 类的构造函数一般是public的,但是也可以是private的.构造函数为私有的类有这样的特点: <1>不能实例化:因为实例化时类外部无法访问其内部的私有的构造函数: <2&g ...
- Android核心基础(十)
1.音频采集 你可以使用手机进行现场录音,实现步骤如下: 第一步:在功能清单文件AndroidManifest.xml中添加音频刻录权限: <uses-permission android:na ...
- EditText 文本内容输入限制
实现InputFilter过滤器,需要覆盖一个叫filter的方法. public abstract CharSequence filter ( CharSequence source, int st ...
- [Regular Expressions] Find the Start and End of Whole Words
Regular Expression Word Boundaries allow to perform "whole word only" searches within our ...
- 同一DataTable下创建多个结构数据相同的DataView的小问题
昨天在根据经理的要求修改公司后台的时候,遇到了一个很奇怪的问题 DataView dvFocus = ]); DataView dvLook = ]); DataView dvNewUser = ]) ...
- 解决jquery和其他库的冲突
一.jquery在其他库之后导入 (1)jQuery.noConflict(); //将变量的$控制权转交给其他库. jQuery(function(){ ...
- [MSDN] GROUP BY (Transact-SQL)
来源: https://msdn.microsoft.com/zh-cn/library/ms177673(v=sql.110).aspx 按 SQL Server 中一个或多个列或表达式的值将一组选 ...
- CSS网页元素居中
1.水平居中:行内元素解决方案 只需要把行内元素包裹在一个属性display为block的父层元素中,并且把父层元素添加如下属性即可: text-align: center 适用元素:文字,链接,及其 ...