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 ...
随机推荐
- Jquery 实现列表的显示和隐藏
本人github源码下载地址:https://github.com/liuyanpeng521/ListChange.git
- Android Studio 关于build.gradle配置问题
当导入一个Android Project时,会出现很多版本的问题,导入前先删除 .idea文件 .gradle文件 ,gradle文件(与.gradle区分,导入时Android Studio会提示重 ...
- Android开发之ThreadLocal原理深入理解
[Android]ThreadLocal的定义和用途 ThreadLocal用于实现在不同的线程中存储线程私有数据的类.在多线程的环境中,当多个线程需要对某个变量进行频繁操作,同时各个线程间不需要同步 ...
- JS——缓慢动画封装案例
手风琴 1.排他思想 2.ul宽度需要大一点,防止li撑开跑下去 3.一个变大其他所有变小,变小不能太小,不然会出现空白 <!DOCTYPE html> <html lang=&qu ...
- Java编译器、JVM、解释器
Java虚拟机(JVM)是可运行Java代码的假想计算机.只要根据JVM规格描述将解释器移植到特定的计算机上,就能保证经过编译的任何Java代码能够在该系统上运行.本文首先简要介绍从Java文件的编译 ...
- dubbo之延迟暴露
延迟暴露 如果你的服务需要预热时间,比如初始化缓存,等待相关资源就位等,可以使用 delay 进行延迟暴露. 延迟 5 秒暴露服务 <dubbo:service delay="5000 ...
- (转)分布式文件存储FastDFS(三)FastDFS配置
http://blog.csdn.net/xingjiarong/article/details/50559768 在上一节中我们一起搭建了一个单节点的FastDFS系统,但是仅仅将系统搭建起来是远远 ...
- return和return false的区别
1. return返回null,起到中断方法执行的效果,只要不return false事件处理函数将会继续执行,表单将提交2. return false,事件处理函数会取消事件,不再继续向下执行.比如 ...
- Linux培训时长多久可以学会?马哥教育9年经验之谈
在Linux的热潮下,很多人萌发了学习Linux的想法.比起自学,培训是一个能够快速.系统的掌握知识的方式,也受到了不少人的青睐. 很多人都想知道通过培训学习Linux需要多长时间,今天咱们就来盘点一 ...
- Codeforces Hello 2018 C - Party Lemonade
传送门:http://codeforces.com/contest/913/problem/C 有n类物品,第i(i=0,1,2,...,n-1)类物品的价值为2i,花费为ci.任意选择物品,使得总价 ...