您的位置:首页 > 其它

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

2014-07-08 10:07 211 查看
题目链接:点击打开链接

题目的意思很是简单。

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


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
;
    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要多做做才好。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: