转载请注明出处:http://blog.csdn.net/u012860063/article/details/37509207

题目链接:http://codeforces.com/contest/445/problem/C

----------------------------------------------------------------------------------------------------------------------------------------------------------
欢迎光临天资小屋http://user.qzone.qq.com/593830943/main

----------------------------------------------------------------------------------------------------------------------------------------------------------

DZY Loves Physics



DZY loves Physics, and he enjoys calculating density.

Almost everything has density, even a graph. We define the density of a non-directed graph (nodes and edges of the graph have some values) as follows:


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

Once DZY got a graph G, now he wants to find a connected induced subgraph G' of
the graph, such that the density of G' is as large as possible.

An induced subgraph G'(V', E') of a graph G(V, E) is
a graph that satisfies:

  • ;
  • edge  if
    and only if ,
    and edge ;
  • the value of an edge in G' is the same as the value of the corresponding edge in G,
    so as the value of a node.

Help DZY to find the induced subgraph with maximum density. Note that the induced subgraph you choose must be connected.

Input

The first line contains two space-separated integers n (1 ≤ n ≤ 500), .
Integer n represents the number of nodes of the graph Gm represents
the number of edges.

The second line contains n space-separated integers xi (1 ≤ xi ≤ 106),
where xi represents
the value of the i-th node. Consider the graph nodes are numbered from 1 to n.

Each of the next m lines contains three space-separated integers ai, bi, ci (1 ≤ ai < bi ≤ n; 1 ≤ ci ≤ 103),
denoting an edge between node ai and bi with
value ci. The
graph won't contain multiple edges.

Output

Output a real number denoting the answer, with an absolute or relative error of at most 10 - 9.

Sample test(s)
input
1 0
1
output
0.000000000000000
input
2 1
1 2
1 2 1
output
3.000000000000000
input
5 6
13 56 73 98 17
1 2 56
1 3 29
1 4 42
2 3 95
2 4 88
3 4 63
output
2.965517241379311
Note

In the first sample, you can only choose an empty subgraph, or the subgraph containing only node 1.

In the second sample, choosing the whole graph is optimal.

题意:   给出一个源图, 要求寻找一个密度(点的值/边的值)最大的子图。

当然子图有三个要满足的要求!

思路:枚举每天边,及其端点的值。

为什么这就是最大密度的子图呢?

由于子图必定是由非常多边和端点所组成的。而想要最大密度的子图,必定子图中当中的一条边的密度是最大的(至少不会小于子图的总密度)。这样仅仅须要找出密度最大的边就是答案.

代码例如以下:

#include <cstdio>
#define N 517
double MAX(double a, double b)
{
return a>b?a:b;
}
int main()
{
int n, m;
int x[N];
int a, b, c;
while(~scanf("%d%d",&n,&m))
{
int i, j;
for(i = 1; i <= n; i++)
{
scanf("%d",&x[i]);
}
double max = 0, t;
for(i = 1; i <= m; i++)
{
scanf("%d%d%d",&a,&b,&c);
t =(double) (x[a]+x[b])/c;
max = MAX(max, t);
}
printf("%.15f\n",max);
}
return 0;
}

CodeForces 444C. DZY Loves Physics(枚举+水题)的更多相关文章

  1. Codeforces 444C DZY Loves Colors(线段树)

    题目大意:Codeforces 444C DZY Loves Colors 题目大意:两种操作,1是改动区间上l到r上面德值为x,2是询问l到r区间总的改动值. 解题思路:线段树模板题. #inclu ...

  2. Codeforces 444A DZY Loves Physics(图论)

    题目链接:Codeforces 444A DZY Loves Physics 题目大意:给出一张图,图中的每一个节点,每条边都有一个权值.如今有从中挑出一张子图,要求子图联通,而且被选中的随意两点.假 ...

  3. CF 444C DZY Loves Physics(图论结论题)

    题目链接: 传送门 DZY Loves Chemistry time limit per test1 second     memory limit per test256 megabytes Des ...

  4. @codeforces - 444A@ DZY Loves Physics

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个 n 点 m 边的图,边有边权,点有点权. 找到一个连通 ...

  5. Codeforces Round #254 (Div. 1) A. DZY Loves Physics 智力题

    A. DZY Loves Physics 题目连接: http://codeforces.com/contest/444/problem/A Description DZY loves Physics ...

  6. poj1873 The Fortified Forest 凸包+枚举 水题

    /* poj1873 The Fortified Forest 凸包+枚举 水题 用小树林的木头给小树林围一个围墙 每棵树都有价值 求消耗价值最低的做法,输出被砍伐的树的编号和剩余的木料 若砍伐价值相 ...

  7. cf444A DZY Loves Physics

    A. DZY Loves Physics time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. CodeForces - 445A - DZY Loves Chessboard

    先上题目: A. DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input ...

  9. codeforces 446C DZY Loves Fibonacci Numbers(数学 or 数论+线段树)(两种方法)

    In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation F1 ...

随机推荐

  1. 本地mongochef连接其他计算机上的数据库认证失败解决方法

    关闭防火墙或者在信任程序列表添加运行目录下的mongod.exe即可

  2. Active Learning主动学习

    Active Learning主动学习 我们使用一些传统的监督学习方法做分类的时候,往往是训练样本规模越大,分类的效果就越好.但是在现实生活的很多场景中,标记样本的获取是比较困难的,这需要领域内的专家 ...

  3. android黑科技系列——自动注入代码工具icodetools

    一.前言 在前面已经介绍完了 自动给apk中注入日志代码工具icodetools原理了,在那里我们曾经说过其实离真正的可使用价值有点距离,本篇就对这个工具进行一些优化,让其真正意义上开始能工作量产.当 ...

  4. dotnetnuke 头像调用 头像缩放

    public static string GetProfileImage(int userId, int width, int height)        {                     ...

  5. (转)Struts2访问Servlet的API及......

    http://blog.csdn.net/yerenyuan_pku/article/details/67315598 Struts2访问Servlet的API 前面已经对Struts2的流程已经执行 ...

  6. rxswift-self.usernameTF.rx.text.orEmpty.map

    self.usernameTF.rx.text.orEmpty.map 一堆类型转化+数据处理的操作 self.usernameTF.rx:将textfiled用Reactive封装: .text:监 ...

  7. js获取图片信息(二)-----js获取img的height、width宽高值为0

    首先,创建一个图片对象: var oImg= new Image(); oImg.src = "apple.jpg"; 然后我们打印一下图片的信息: console.log(oIm ...

  8. Boolean对象与Boolean原始值的区别

    我们先来看下面这道题: var x = new Boolean(false); if (x) {   alert('hi'); } var y = Boolean(0); if (y) {   ale ...

  9. 为Unity的新版ugui的Prefab生成预览图

    using UnityEngine;using System.Collections;using UnityEditor;using System.IO; [CustomPreview(typeof( ...

  10. oi的小转折

    2018.6.4,衡水中学oier——Yu-shi,真正的走入了外网领域. 从最开始的连scanf都不打取地址,到现在懂了好多以前不敢去看的东西,心态逐渐的成长了.也许有过特别迷茫的时候,也许将来会有 ...