Perpetuum Mobile

题目描述

The year is 1902. Albert Einstein is working in the patent office in Bern. Many patent proposals contain egregious errors; some even violate the law of conservation of energy. To make matters worse, the majority of proposals make use of non-standard physical units that are not part of the metric system (or not even documented). All proposals are of the following form:
• Every patent proposal contains n energy converters.
• Every converter has an unknown input energy unit associated with it.
• Some energy converters can be connected: If converter a can be connected to converter b such that one energy unit associated with a is turned into c input units for b, then this is indicated by an arc  in the proposal. The output of a can be used as input for b if and only if such an arc from a to b exists.
Einstein would like to dismiss all those proposals out of hand where the energy converters can be chained up in a cycle such that more energy is fed back to a converter than is given to it as input, thereby violating the law of conservation of energy.
Einstein’s assistants know that he is born for higher things than weeding out faulty patent proposals. Hence, they take care of the most difficult cases, while the proposals given to Einstein are of a rather restricted form: Every admissible patent proposal given to Einstein does not allow for a cycle where the total product of arc weights exceeds 0.9. By contrast, every inadmissible patent proposal given to Einstein contains a cycle where the the number of arcs constituting the cycle does not exceed the number of converters defined in the proposal, and the total product of arc weights is greater or equal to 1.1.
Could you help Einstein identify the inadmissible proposals?

输入

The input consists of:
• one line with two integers n and m, where
– n (2 ≤ n ≤ 800) is the number of energy converters;
– m (0 ≤ m ≤ 4000) is the number of arcs.
• m lines each containing three numbers ai , bi , and ci , where
– ai and bi (1 ≤ ai , bi ≤ n) are integers identifying energy converters;
– ci (0 < ci ≤ 5.0) is a decimal number indicating that the converter ai can be connected to the converter b i such that one input unit associated with ai is converted to ci units associated with bi . The number ci may have up to 4 decimal places.

输出

Output a single line containing inadmissible if the proposal given to Einstein is inadmissible, admissible otherwise.

样例输入

2 2
1 2 0.5
2 1 2.3

样例输出

inadmissible

【代码】

参考博客:

https://blog.csdn.net/qq_41955236/article/details/82959245

队友代码:

 //
//
//
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC optimize("O3")
//#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
#define pi acos(-1.0)
#define nl "\n"
#define db double
#define pb push_back
#define pii pair<int,double>
#define ms(a,b) memset(a,b,sizeof(a))
#define FAST_IO ios::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL)
using namespace std;
typedef long long ll;
const ll mod = 1e9+;
ll qpow(ll x, ll y){ll s=;while(y){if(y&)s=s*x%mod;x=x*x%mod;y>>=;}return s;}
//ll qpow(ll a, ll b){ll s=1;while(b>0){if(b%2==1)s=s*a;a=a*a;b=b>>1;}return s;}
inline int read(){int x=,f=;char ch=getchar();while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}while(ch>=''&&ch<='') x=x*+ch-'',ch=getchar();return x*f;} const int N = ; struct node{
int to;
db w;
}; vector <node> G[N];
db d[N];
int vis[N]; bool dijktra(int u)
{
vis[u] = ;
for(int i=;i<G[u].size();i++)
{
node v = G[u][i];
if(d[u]+v.w < d[v.to]){
d[v.to] = d[u]+v.w;
if(vis[v.to]) return ;
if(dijktra(v.to)) return ;
}
}
vis[u] = ;
return ;
} int main()
{
int n, m;
scanf("%d%d", &n,&m);
for(int i=;i<=m;i++){
int u, v;db w;
scanf("%d%d%lf",&u,&v,&w);
//if(w >= 1.1) w = -w;
G[u].pb((node){v,-log(w)});
}
for(int i=;i<=n;i++)if(dijktra(i)){
puts("inadmissible");
return ;
}
puts("admissible");
return ;
}

【判环】Perpetuum Mobile的更多相关文章

  1. hdu4975 A simple Gaussian elimination problem.(正确解法 最大流+删边判环)(Updated 2014-10-16)

    这题标程是错的,网上很多题解也是错的. http://acm.hdu.edu.cn/showproblem.php?pid=4975 2014 Multi-University Training Co ...

  2. hdu4888 Redraw Beautiful Drawings 最大流+判环

    hdu4888 Redraw Beautiful Drawings Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/6553 ...

  3. Leetcode 166. Fraction to Recurring Decimal 弗洛伊德判环

    分数转小数,要求输出循环小数 如2 3 输出0.(6) 弗洛伊德判环的原理是在一个圈里,如果一个人的速度是另一个人的两倍,那个人就能追上另一个人.代码中one就是速度1的人,而two就是速度为2的人. ...

  4. Leetcode 202 Happy Number 弗洛伊德判环解循环

    今天先谈下弗洛伊德判环,弗洛伊德判环原来是在一个圈内有两人跑步,同时起跑,一人的速度是另一人的两倍,则那个人能在下一圈追上另一个人,弗洛伊德判环能解数字会循环出现的题,比如说判断一个链表是不是循环链表 ...

  5. Codeforces Gym 100187K K. Perpetuum Mobile 构造

    K. Perpetuum Mobile Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/pro ...

  6. Dwarves (有向图判环)

    Dwarves 时间限制: 1 Sec  内存限制: 64 MB提交: 14  解决: 4[提交][状态][讨论版] 题目描述 Once upon a time, there arose a huge ...

  7. COJ 3012 LZJ的问题 (有向图判环)

    传送门:http://oj.cnuschool.org.cn/oj/home/problem.htm?problemID=1042 试题描述: LZJ有一个问题想问问大家.他在写函数时有时候很头疼,如 ...

  8. 比赛F-F Perpetuum Mobile

    比赛F-F     Perpetuum Mobile 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86640#problem/ ...

  9. K. Perpetuum Mobile

    The world famous scientist Innokentiy almost finished the creation of perpetuum mobile. Its main par ...

随机推荐

  1. Java生成不重复的随机数组的方法

    一.JAVA中生成随机数的方式 1.在j2se中使用Math.random()令系统随机选取一个01之间的double类型小数,将其乘以一个数,比如25,就能得到一个025范围内的随机数,这个在j2m ...

  2. Linux用户组

    1.介绍 类似于角色,系统可以对有共性的多个用户进行统一的管理 2.增加组 groupadd  组名 3.删除组 groupdel  组名 4.增加用户时直接为用户指定组 useradd  -g  用 ...

  3. mysql存储引擎介绍,索引

    区别: MyISAM类型不支持事务处理等高级处理,而InnoDB类型支持.MyISAM类型的表强调的是性能,其执行数度比InnoDB类型更快,但是不提供事务支持,而InnoDB提供事务支持已经外部键等 ...

  4. MAC将根目录文件夹的权限赋给用户

    https://my.oschina.net/liujiest/blog/762004 1.sudu -i进入root模式(需输入密码) 2.chown -R 用户名 /文件夹名 sudo -i Pa ...

  5. php Class 'ZipArchive' not found怎么解决?

      情况1: 服务器php zip模块没有安装 情况2: Php.ini 中Php zlip扩展没有开   文章来源:外星人来地球 欢迎关注,有问题一起学习欢迎留言.评论

  6. php - thinkphp3.2-phpQrcode生成二维码

    import('/Doctor.Logic.phpqrcode',APP_PATH,'.php');// import('@.Doctor.Logic');$value = 'http://www.c ...

  7. xgboost 源码学习

    官方代码结构解析,README.MD XGboost 回归时,损失函数式平方误差损失 分类时,是对数自燃损失: Coding Guide ====== This file is intended to ...

  8. JMeter_控制器执行效果_给自己挖过的坑

    线程及循环设置: 数据文件中放在“循环控制器”中的执行效果:每条数据执行5次,取够50条数据时停止 简单逻辑控制器按下面的目录创建后,执行结果效果同上面循环控制器的执行效果 本来想规整下目录结构,结果 ...

  9. 数据库连接池配置(案例及排查指南) 原创: 有赞技术 有赞coder 4天前

    数据库连接池配置(案例及排查指南) 原创: 有赞技术 有赞coder 4天前

  10. iptables+ipset自动封闭和解封频繁访问web服务的恶意IP

    转载于互联网     iptables直接针对ip进行封禁,在ip数量不大的时候是没什么问题的,但当有大量ip的时候性能会严重下降,iptables是O(N)的性能.而ipset就像一个集合,把需要封 ...