天下第一
时间限制: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 天下第一的更多相关文章

  1. NYOJ 973 天下第一 (最短路)

    题目链接 描述 AC_Grazy一直对江湖羡慕不已,向往着大碗吃肉大碗喝酒的豪情,但是"人在江湖漂,怎能 不挨刀","人在江湖身不由己",如果自己的武功太差,在 ...

  2. nyist 78 圈水池

    http://acm.nyist.net/JudgeOnline/problem.php?pid=78 圈水池 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 有一个 ...

  3. 数论 - 简单数位推理 --- NYIST 514

    Problem's Link:http://acm.nyist.net/JudgeOnline/problem.php?pid=514 Mean: 给你一个l和r,求出在这个范围内的1的个数. ana ...

  4. nyist 47 过河问题

    http://acm.nyist.net/JudgeOnline/problem.php?pid=47 过河问题 时间限制:1000 ms  |  内存限制:65535 KB 难度:5   描述 在漆 ...

  5. nyist 676 小明的求助

    http://acm.nyist.net/JudgeOnline/problem.php?pid=676 小明的求助 时间限制:2000 ms  |  内存限制:65535 KB 难度:2   描述 ...

  6. nyist 62 笨小熊

    http://acm.nyist.net/JudgeOnline/problem.php?pid=62 笨小熊 时间限制:2000 ms  |  内存限制:65535 KB 难度:2   描述 笨小熊 ...

  7. nyist 673 悟空的难题

    http://acm.nyist.net/JudgeOnline/problem.php?pid=673 悟空的难题 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 ...

  8. nyist 597 完数?

    http://acm.nyist.net/JudgeOnline/problem.php?pid=597 完数? 时间限制:1000 ms  |  内存限制:65535 KB 难度:1   描述 一个 ...

  9. nyist 518 取球游戏

    http://acm.nyist.net/JudgeOnline/problem.php?pid=518 取球游戏 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 今 ...

随机推荐

  1. OA项目总结3

    struts2自定义标签中  使用in  判断当前值 是否在某个集合中 该属性一方面可以获取前端页面传递过来的参数   另外一个作用就是在数据回显时把用户已经拥有的权限id存入该集合中   放在栈顶 ...

  2. java+selenium自动化遇到confirm弹窗,出现NoAlertPresentException: no alert open

    //操作js的confirm弹窗,bool控制是否点击确定,true为点击确定,false为点击取消 public static void OperaterJSOfConfirm(WebDriver ...

  3. spring boot系列--spring security (基于数据库)登录和权限控制

    先说一下AuthConfig.java Spring Security的主要配置文件之一 AuthConfig 1 @Configuration 2 @EnableWebSecurity 3 publ ...

  4. gcc 源代码分析-前端篇2

    2. 对ID及保留字的处理    在c语言中,系统预留了非常多keyword.也被称为保留字,比方表示数据类型的int,short,char,控制分支运行的if,then等. 不论什么keyword, ...

  5. CF 567D(One-Dimensional Battle Ships-二分)

    D. One-Dimensional Battle Ships time limit per test 1 second memory limit per test 256 megabytes inp ...

  6. 初识ecside

    ecside,基于jsp tag的开源列表组件.支持导出pdf.xsl.csv等文件. 主要标签<ec:table>\<ec:row>\<ec:column>. 支 ...

  7. 2015.03.13,外语,读书笔记-《Word Power Made Easy》 10 “如何讨论交谈习惯”学习笔记 SESSION 26

    1.a Spartan virtue 古斯巴达人中一位有名的Laconia国王,其言语比Vermonter(美国佛蒙特州人)还简洁.一个传说,马其顿菲利普国王(亚历山大的老爸)要进攻他们的都城,发了一 ...

  8. UVA 11825 Hackers’ Crackdown 状压DP枚举子集势

    Hackers’ Crackdown Miracle Corporations has a number of system services running in a distributed com ...

  9. UVA 294 - Divisors 因子个数

    Mathematicians love all sorts of odd properties of numbers. For instance, they consider 945 to be an ...

  10. linux执行shell脚本时提示bad interpreter:No such file or directory的解决办法

    故障现象:在终端直接cd /var正常,在shell脚本中执行则报错.原因是脚本是在windows平台下写的,换行符与Linux不同,造成脚本不能正确执行 出现bad interpreter:No s ...