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 ...
随机推荐
- softlayerFastUploadVHDtoBS
Object Storage Uploader Overview We’ve recently added the option to import customer-supplied Virtual ...
- 浅析libev的ev_signal过程
ev_signal是libev提供的对信号处理的一个模块,基本上是对sigaction函数的一个封装,并将本身是异步的信号转化为同步.ev_signal的使用十分简单: #include <ev ...
- (转)mysql分表的3种方法
原文:http://blog.51yip.com/mysql/949.html 一,先说一下为什么要分表 当一张的数据达到几百万时,你查询一次所花的时间会变多,如果有联合查询的话,我想有可能会死在那儿 ...
- 格而知之16:我所理解的Block(2)
11.那么Block到底是怎么实现的呢?试一试通过将Block 的代码转换成普通C语言代码来查看它的实现过程. 要将OC代码转换成C语言代码,可以使用clang编译的一个命令: 通过这个命令能把指定文 ...
- sql注入数据库修复方法
1.第一种情况是 需要将指定的 注入字符串全部替换掉(仅替换注入的字符串为空) declare @delStr nvarchar(500) set @delStr='<script src=ht ...
- ThinkPHP视图查询详解
ThinkPHP视图查询详解 参考http://www.jb51.net/article/51674.htm 这篇文章主要介绍了ThinkPHP视图查询,需要的朋友可以参考下 ThinkP ...
- iOS textfield限制长度,中文占2字符,英文占1字符
之前遇到一种情况,限制textfield长度,并且要适配多语言,做到,例如中文占2字符,英文占1字符,还有考虑其他语言,网上找了很多方法,不太合适,最后结合网上的方案,修改出了还比较适用. 首先,增加 ...
- c# 调用 友盟api
今天要使用友盟的推送API来给我的app进行推送信息,调试了好久,老是返回500错误,最终在友盟的技术人员支持下完成了此操作,在此多谢友盟技术和客服人员. 把发方法和注意事项贴出来供大家参考. pub ...
- #pragma section
看了别人使用了#pragma section来共享变量,今天试了下 如下添加代码 #define GLOBAL_SHARED __declspec(allocate(".Shared&quo ...
- (原)编译caffe时提示未定义的引用(undefined reference to)
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5864715.html 参考网址: https://github.com/BVLC/caffe/issu ...