NYIST 973 天下第一
天下第一
时间限制:1000 ms | 内存限制:65535 KB
难度:3
描述
AC_Grazy一直对江湖羡慕不已,向往着大碗吃肉大碗喝酒的豪情,但是“人在江湖漂,怎能
不挨刀",”人在江湖身不由己",如果自己的武功太差,在江湖会死的很惨,但是AC_Grazy没有
武功秘籍练不了绝世武功.有道是“山重水复疑无路,柳暗花明又一村”,在AC_Grazy家里面
竟然藏着一本书,书名竟然叫做【超级外挂】,竟然能在各种武功之间进行转化,据说是他爷
爷的爷爷的...爷爷传下来的...
闲着无事便拿来看看,只看一眼便再也停不下了,只见上面写着“纵横武林打遍天下无敌手武功心法秘籍收录”.
翻开第一篇一看竟然是【降龙十八掌】...
心法只是一个修练武功的途径,重要的是真气的多少,于是他便想利用外挂让武功之间进行转
化,来让真气无限增加,但是这个心法只能按照顺序转化,我们分别用 1号和2号来代替两种功法 当然转化会有一定的转化率f
比如1 0.5 2 便是把 1的一半真气转化给2 ,为了简化问题,我们每次都从1号秘籍开始进行转化,如果其中一个秘籍转化断了,那么以后的功法就不能转换。
输入
输入:首先输入一个数 T(T<=20)表示T组数据
然后输入两个数n(2<=n<=500)和m(1=<m<=2000)分别表
示有n种秘籍,随后的m行分别输入
秘籍u(n>=u>0) 转化率 f (0<f<=10)秘籍 v.(0<v<=n)
输出
输出:如果可以无限增加真气输出Yes否则输出No.
样例输入
2
3 3
1 2 2
2 2 3
3 2 1
4 3
1 2 2
3 2 4
4 2 3
样例输出
Yes
No
上传者
ACM_王亚龙
解题:最长路,判正圈。。。。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
struct arc{
int to,next;
double f;
arc(int x = ,double y = ,int z = -){
to = x;
f = y;
next = z;
}
};
arc e[];
int head[maxn],cnt[maxn],tot,n,m;
bool in[maxn];
double d[maxn];
void add(int u,int v,double f){
e[tot] = arc(v,f,head[u]);
head[u] = tot++;
}
bool spfa(){
memset(d,,sizeof(d));
queue<int>q;
memset(cnt,,sizeof(cnt));
memset(in,false,sizeof(in));
q.push();
d[] = ;
while(!q.empty()){
int u = q.front();
q.pop();
in[u] = false;
for(int i = head[u]; ~i; i = e[i].next){
if(d[e[i].to] < d[u]*e[i].f){
d[e[i].to] = d[u]*e[i].f;
if(!in[e[i].to]){
in[e[i].to] = true;
if(++cnt[e[i].to] > n) return true;
q.push(e[i].to);
}
}
}
}
return false;
}
int main() {
int T,u,v;
double f;
scanf("%d",&T);
while(T--){
scanf("%d %d",&n,&m);
memset(head,-,sizeof(head));
for(int i = tot = ; i < m; ++i){
scanf("%d %lf %d",&u,&f,&v);
add(u,v,f);
}
printf("%s\n",spfa()?"Yes":"No");
}
return ;
}
NYIST 973 天下第一的更多相关文章
- NYOJ 973 天下第一 (最短路)
题目链接 描述 AC_Grazy一直对江湖羡慕不已,向往着大碗吃肉大碗喝酒的豪情,但是"人在江湖漂,怎能 不挨刀","人在江湖身不由己",如果自己的武功太差,在 ...
- nyist 78 圈水池
http://acm.nyist.net/JudgeOnline/problem.php?pid=78 圈水池 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 有一个 ...
- 数论 - 简单数位推理 --- NYIST 514
Problem's Link:http://acm.nyist.net/JudgeOnline/problem.php?pid=514 Mean: 给你一个l和r,求出在这个范围内的1的个数. ana ...
- nyist 47 过河问题
http://acm.nyist.net/JudgeOnline/problem.php?pid=47 过河问题 时间限制:1000 ms | 内存限制:65535 KB 难度:5 描述 在漆 ...
- nyist 676 小明的求助
http://acm.nyist.net/JudgeOnline/problem.php?pid=676 小明的求助 时间限制:2000 ms | 内存限制:65535 KB 难度:2 描述 ...
- nyist 62 笨小熊
http://acm.nyist.net/JudgeOnline/problem.php?pid=62 笨小熊 时间限制:2000 ms | 内存限制:65535 KB 难度:2 描述 笨小熊 ...
- nyist 673 悟空的难题
http://acm.nyist.net/JudgeOnline/problem.php?pid=673 悟空的难题 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 ...
- nyist 597 完数?
http://acm.nyist.net/JudgeOnline/problem.php?pid=597 完数? 时间限制:1000 ms | 内存限制:65535 KB 难度:1 描述 一个 ...
- nyist 518 取球游戏
http://acm.nyist.net/JudgeOnline/problem.php?pid=518 取球游戏 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 今 ...
随机推荐
- BA--空调静压箱的作用
空调静压箱的主要作用有两个,一个是降低噪音:一个是提高送风距离.工作原理如下:空调出风从空调风机里面出来的时候,具有很大的风速,同时由于空调风机自身的结构原因,空调的出风并不均衡,空气在风管中相互摩擦 ...
- T4系列文章之1:认识T4
一.导读 MSDN:Code Generation and T4 Text Templates 博客园:编写T4模板进行代码生成 Oleg Sych系列文章:http://www.olegsych.c ...
- POJ--2112--Optimal Milking【Floyd+Dinic+二分答案】
链接:http://poj.org/problem?id=2112 题意:有k个挤奶器.编号1~k,c头牛,编号k+1~k+c,每一个挤奶器最多能给m头牛挤奶,给你一个k+c的邻接矩阵.要求每头牛都能 ...
- Flash的选择
算起来自己接触Flash接近4年了. 最開始的2.0,做button,做动画,做导航. 后来用3.0做动画,做相冊.做毕业设计,做课件. 然后到公司做2.0的动画,模板开发,效果设计. 似乎又回到了原 ...
- 图像算法研究---Adaboost算法具体解释
本篇文章先介绍了提升放法和AdaBoost算法.已经了解的可以直接跳过.后面给出了AdaBoost算法的两个样例.附有详细计算过程. 1.提升方法(来源于统计学习方法) 提升方法是一种经常使用的统计学 ...
- 【DataStructure】One of queue usage: Simulation System
Statements: This blog was written by me, but most of content is quoted from book[Data Structure wit ...
- log4j日志存储到数据库
一.前提条件 系统必须是使用LOG4J进行日志管理,否则方法无效. 系统必须包含commons-logging-xxx.jar,log4j-xxx.jar这两个JAR包,XXX为版本号. 二.操作步骤 ...
- 0x17 二叉堆
优先队列太好用了手写啥呀 poj1456 经过贪心专题的洗礼以后这题根本就不叫题啊...按时间大到小排每次取最大就好 #include<cstdio> #include<iostre ...
- SpringBoot项目部署
项目背景 个人博客:http://www.huangyichun.cn/blog/8 采用SpringBoot开发的个人博客,部署到腾讯云服务器上,服务器系统为ubuntu16.04, ...
- 10. Regular Expression Matching[H]正则表达式匹配
题目 Given an input string(s) and a pattern(p), implement regular expression matching with support for ...