Codeforces Round #254 (Div. 2) C. DZY Loves Physics

题目链接:点击打开链接

题目的意思很是简单。

就是求一个连通诱导子图的最大点权、边权比。即

where v is the sum of the values of the nodes,e is the sum of the values of the edges.

说是一个结论,对于一个诱导子图中,两个结点才是最优的。

证明:

假设有三个顶点的权值为a,b,c.他们边权(a,b)=A,(b,c)=B;

那么对于两个点的情况为(a+b)/A,(b+c)/B.

假设(a+b)/A>(b+c)/B.也即(a+b)*B>(b+c)*A.

那么对于三点,(a+b+c)/(A+B).比较与(a+b)/A的大小.

同时乘以A*(A+B)再减去(a+b)*A得,cA和(a+b)*B.

因为(a+b)*B>(b+c)*A,也就(a+b)*B>cA.也就两点的情况要优于三点的情况。

代码:

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

const int N = 505;
int main(){
    int n, m;
    scanf("%d%d",&n, &m);
    double max = 0;
    double value[N];
    for(int i = 1; i <= n; i ++){
        scanf("%lf",&value[i]);
    }
    for(int i = 1; i <= m; i ++){
        int a, b;
        double c;
        scanf("%d %d %lf",&a, &b, &c);
        double k = (value[a] + value[b])/c;
        if(k > max) max = k;
    }
    printf("%.11lf\n",max);
    return 0;
}

cf要多做做才好。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值