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. Tomcat的默认端口问题

    0x00 起因 今天看到一个226团队,进群的时候有一个问题问的就是:Tomcat的默认端口是多少? 当时我只想到了8080,等过了不久,有位管理员回复了我是三个默认端口....,马上去翻了下资料,才 ...

  2. java一周学习回顾

    快速阅读 ​ 本周在学习java过程中主要是快马观花,对java的常用框架进行相关配置 ,进行简单的调用 .包括kafka,dubbo ,zookeeper.centos配置java环境.如何打war ...

  3. LeetCode31 Next Permutation and LeetCode60 Permutation Sequence

    Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...

  4. 20165223《网络对抗技术》Exp 9 Web安全基础

    目录 -- Web安全基础 ★ 实验说明 实验目标 基础问答 实验准备 ★ 实验内容 SQL注入攻击 1. 命令注入(Command Injection) 2. 数字型注入(Numeric SQL I ...

  5. 使用 If-Then-Else 逻辑进行分支

    If-then-else 逻辑看似简单,功能却十分强大,它可以根据不同条件执行不同的操作.If-then-else 逻辑可理解为:如果某个条件为 true (IF),则执行某个操作:如果条件为 fal ...

  6. yarn 单点故障 重启 ResourceManger Restart

    http://hadoop.apache.org/docs/stable/hadoop-yarn/hadoop-yarn-site/ResourceManagerRestart.html Featur ...

  7. C# 使用Task执行异步操作

    为什么要使用 Task Task 和 Thread 区别 Task 介绍 Task 简单实现 Task 执行状态 为什么要使用 Task 线程是创建并发的底层工具,因此具有一定的局限性. 没有简单的方 ...

  8. 最简单的freemarker用法实例

          1.下载freemarker-2.3.19.jar到web项目的lib下. 2.新建freemarker引擎协助类 package com.bxsurvey.sys.process.uti ...

  9. VL10B 采购订单转DN

    传入采购订单项目建交货单 FUNCTION zmmfmXXXX. *"------------------------------------------------------------ ...

  10. Windows下免费的屏幕录制软件——EV录屏——推荐

    EV录屏,现在使用起来效果还不错. 软件地址:https://www.ieway.cn/evcapture.html