zoukankan      html  css  js  c++  java
  • 【判环】Perpetuum Mobile

    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

    队友代码:

     1 //
     2 //
     3 //
     4 //#pragma GCC optimize("Ofast,no-stack-protector")
     5 //#pragma GCC optimize("O3")
     6 //#pragma GCC optimize(2)
     7 #include <bits/stdc++.h>
     8 #define inf 0x3f3f3f3f
     9 #define linf 0x3f3f3f3f3f3f3f3fll
    10 #define pi acos(-1.0)
    11 #define nl "
    "
    12 #define db double
    13 #define pb push_back
    14 #define pii pair<int,double>
    15 #define ms(a,b) memset(a,b,sizeof(a))
    16 #define FAST_IO ios::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL)
    17 using namespace std;
    18 typedef long long ll;
    19 const ll mod = 1e9+7;
    20 ll qpow(ll x, ll y){ll s=1;while(y){if(y&1)s=s*x%mod;x=x*x%mod;y>>=1;}return s;}
    21 //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;}
    22 inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();return x*f;}
    23  
    24 const int N = 888;
    25  
    26 struct node{
    27     int to;
    28     db w;
    29 };
    30  
    31 vector <node> G[N];
    32 db d[N];
    33 int vis[N];
    34  
    35 bool dijktra(int u)
    36 {
    37     vis[u] = 1;
    38     for(int i=0;i<G[u].size();i++)
    39     {
    40         node v = G[u][i];
    41         if(d[u]+v.w < d[v.to]){
    42             d[v.to] = d[u]+v.w;
    43             if(vis[v.to]) return 1;
    44             if(dijktra(v.to)) return 1;
    45         }
    46     }
    47     vis[u] = 0;
    48     return 0;
    49 }
    50  
    51 int main()
    52 {
    53     int n, m;
    54     scanf("%d%d", &n,&m);
    55     for(int i=1;i<=m;i++){
    56         int u, v;db w;
    57         scanf("%d%d%lf",&u,&v,&w);
    58         //if(w >= 1.1) w = -w;
    59         G[u].pb((node){v,-log(w)});
    60     }
    61     for(int i=1;i<=n;i++)if(dijktra(i)){
    62         puts("inadmissible");
    63         return 0;
    64     }
    65     puts("admissible");
    66     return 0;
    67 }
    View Code
  • 相关阅读:
    方法重载的小demo
    面向对象的小demo
    直接选择排序
    冒泡排序
    杨辉三角用java实现
    从键盘输入成绩,找出最高分,并输出学生成绩等级。成绩>=最高分-10,为A,成绩>=最高分-20,为B,成绩>=最高分-30,为C,其余等级为D
    井号的含义
    svg snap 笔记
    jQuery 插件格式 规范
    工作遇到问题
  • 原文地址:https://www.cnblogs.com/Osea/p/11397615.html
Copyright © 2011-2022 走看看