CodeForces 444C. DZY Loves Physics(枚举+水题)
转载请注明出处: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.
The first line contains two space-separated integers n (1 ≤ n ≤ 500), .
Integer n represents the number of nodes of the graph G, m 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 a real number denoting the answer, with an absolute or relative error of at most 10 - 9.
1 0
1
0.000000000000000
2 1
1 2
1 2 1
3.000000000000000
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
2.965517241379311
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(枚举+水题)的更多相关文章
- Codeforces 444C DZY Loves Colors(线段树)
题目大意:Codeforces 444C DZY Loves Colors 题目大意:两种操作,1是改动区间上l到r上面德值为x,2是询问l到r区间总的改动值. 解题思路:线段树模板题. #inclu ...
- Codeforces 444A DZY Loves Physics(图论)
题目链接:Codeforces 444A DZY Loves Physics 题目大意:给出一张图,图中的每一个节点,每条边都有一个权值.如今有从中挑出一张子图,要求子图联通,而且被选中的随意两点.假 ...
- CF 444C DZY Loves Physics(图论结论题)
题目链接: 传送门 DZY Loves Chemistry time limit per test1 second memory limit per test256 megabytes Des ...
- @codeforces - 444A@ DZY Loves Physics
目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个 n 点 m 边的图,边有边权,点有点权. 找到一个连通 ...
- Codeforces Round #254 (Div. 1) A. DZY Loves Physics 智力题
A. DZY Loves Physics 题目连接: http://codeforces.com/contest/444/problem/A Description DZY loves Physics ...
- poj1873 The Fortified Forest 凸包+枚举 水题
/* poj1873 The Fortified Forest 凸包+枚举 水题 用小树林的木头给小树林围一个围墙 每棵树都有价值 求消耗价值最低的做法,输出被砍伐的树的编号和剩余的木料 若砍伐价值相 ...
- cf444A DZY Loves Physics
A. DZY Loves Physics time limit per test 1 second memory limit per test 256 megabytes input standard ...
- CodeForces - 445A - DZY Loves Chessboard
先上题目: A. DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input ...
- codeforces 446C DZY Loves Fibonacci Numbers(数学 or 数论+线段树)(两种方法)
In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation F1 ...
随机推荐
- 【Leetcode146】LRU Cache
问题描述: 设计一个LRU Cache . LRU cache 有两个操作函数. 1.get(key). 返回cache 中的key对应的 val 值: 2.set(key, value). 用伪代码 ...
- [转]Linux rpm 命令参数使用详解
转自:http://www.cnblogs.com/xiaochaohuashengmi/archive/2011/10/08/2203153.html RPM是RedHat Package Mana ...
- JdbcTemplate:Jdbc模板和数据库元数据
通过 Jdbc .C3P0 .Druid 的使用我们会发现即使我们做了工具的封装,但重复性的代码依旧很多.我们可以通过 JdbcTemplate 即 Jdbc 模板来使我们的代码更加简洁,逻辑更加清晰 ...
- TCP的send与recv函数小结
Send函数: 在阻塞模式下, send函数的过程是将应用程序请求发送的数据拷贝到发送缓存中发送并得到确认后再返回.但由于发送缓存的存在,表现为:如果发送缓存大小比请求发送的大小要大,那么send函数 ...
- Showplan 逻辑运算符和物理运算符参考
本文档已存档,并且将不进行维护. 运算符说明了 SQL Server 如何执行查询或数据操作语言 (DML) 语句. 查询优化器使用运算符生成查询计划,以创建在查询中指定的结果或执行在 DML 语句中 ...
- Angular——流程控制指令
基本介绍 (1)ng-repeat,类似于for循环,对数组进行遍历 (2)ng-switch on,ng-switch-when,类似于switch,case 基本使用 ng-repeat < ...
- html5——动画案例(大海)
太阳的发散效果主要是利用transform: scale(1.3),将物体变大 <!DOCTYPE html> <html lang="en"> <h ...
- Python 时间处理---------笔记
时区处理&格式化 import pytz from datetime import datetime # 设置时区 timezone = pytz.timezone('Asia/Shangha ...
- Cuder - 用C++11封装的CUDA类
以前写cuda:初始化环境,申请显存,初始化显存,launch kernel,拷贝数据,释放显存.一个页面大部分都是这些繁杂但又必须的操作,有时还会忘掉释放部分显存. 今天用C++11封装了这些CUD ...
- mysql有关时间是问题
mysql中有关时间的类型 date/datetime/time/timestamp/year date:表示日期的类型,格式为:“yyyy-MM-dd” dateTime:表示日期时间的类型,格式 ...