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 ;
}

最新文章

  1. 安装R语言扩展包vegan
  2. 【BZOJ】3670: [Noi2014]动物园
  3. TOGAF:企业信息化复杂吗?
  4. 如何安装nodejs
  5. Ubuntu安装Osmocom-BB一只猿多频点WEB脚本
  6. 【Spring-AOP-学习笔记-7】@Around增强处理简单示例
  7. useradd adduser linux创建用户、设置密码、修改用户、删除用户
  8. 沃森Mysql数据库修复工具
  9. android touchEvent事件学习
  10. .Net下的分库分表帮助类——用分库的思想来分表
  11. 【Unity编程】Unity中的欧拉旋转
  12. 【转】java事件监听机制
  13. 常用的redis命令
  14. symfony简单的博客练习,熟悉具体开发流程
  15. 用agular2做文件上传功能杂记-遁地龙卷风
  16. face detection[SSH]
  17. vue-用Vue-cli从零开始搭建一个Vue项目
  18. 【Python】UI自动化-1
  19. QGis C++ 开发之图层分类显示
  20. Jenkins报表 代码 指标分析

热门文章

  1. Result window is too large, from + size must be less than or equal to [10000]
  2. HNOI2009有趣的数列
  3. qt 2D绘图技巧
  4. vue-resource在vuecli3中请求headers修改
  5. BitmapFactory: inSampleSize 的一些思考
  6. PorterDuffXfermode的模式取值
  7. java 利用poi 实现excel合并单元格后出现边框有的消失的解决方法
  8. c# 调用mysql数据库验证用户名和密码
  9. Mac 高效 软件
  10. 02. oc语言是动态语言