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.也就两点的情况要优于三点的情况。
代码:
cf要多做做才好。
题目的意思很是简单。
就是求一个连通诱导子图的最大点权、边权比。即
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要多做做才好。
相关文章推荐
- Codeforces Round #254 (Div. 1) A. DZY Loves Physics 智力题
- Codeforces Round #254 (Div. 2)C DZY Loves Physics(图论结论题)
- Codeforces Round #254 (Div. 2)444A - DZY Loves Physics (枚举权值求最大)
- Codeforces Round #254 (Div. 2) C (444A)DZY Loves Physics
- Codeforces444A_DZY Loves Physics
- Codeforces Round #FF (Div. 2) Problem A DZY Loves Hash
- Codeforces Round #FF (Div. 2/A)/Codeforces447A_DZY Loves Hash(哈希)
- Codeforces Round #FF (Div. 2) C. DZY Loves Sequences
- Codeforces Round #FF (Div. 2) C DZY Loves Sequences
- Codeforces Round #FF (Div. 2):C. DZY Loves Sequences
- BZOJ3570 : DZY Loves Physics I
- 【Codeforces Round #FF (Div. 2)】E. DZY Loves Fibonacci Numbers
- Codeforces Round #254 (Div. 2):A. DZY Loves Chessboard
- Codeforces Round #254 (Div. 2) B. DZY Loves Chemistry (并查集)
- Codeforces Round #FF (Div. 2) Problem B DZY Loves Strings
- Codeforces Round #FF (Div. 2) Problem C DZY Loves Sequences
- Codeforces Round #FF (Div. 2/C)/Codeforces446A_DZY Loves Sequences(DP)
- Codeforces Round #254 (Div. 1)C. DZY Loves Colors(线段树经典操作/分块)
- CF 444A(DZY Loves Physics-诱导子图的密度)
- Codeforces Round #FF (Div. 2)C - DZY Loves Sequences