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;
}
转载于:https://www.cnblogs.com/jhcelue/p/6910150.html
CodeForces 444C. DZY Loves Physics(枚举+水题)相关推荐
- Codeforces 444C DZY Loves Colors 线段树区间更新
// Codeforces 444C DZY Loves Colors 线段树区间更新// 题目链接:// http://codeforces.com/problemset/problem/444/C ...
- CodeForces - 444C DZY Loves Colors(线段树+剪枝)
题目链接:点击查看 题目大意:给出一个长度为 n 的数组 a 和计算贡献的数组 sum,需要执行 m 次操作,每次操作分为下列两种类型: 1 l r x:将区间 [ l , r ] 内的 a 用 x ...
- Codeforces 444C DZY Loves colors(分块)
我们维护一个标记表示区间内的数是否全相同即可. 如果全相同很容易算出 a , b a,b a,b 数组需要更新多少,打标记即可. 否则暴力修改. #include <map> #inclu ...
- Educational Codeforces Round 7 B. The Time 水题
B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...
- 【CodeForces - 1A】Theatre Square(水题,几何)(CODEFORCES,梦的开始)
题干: Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters ...
- Codeforces Round #300 A. Cutting Banner 水题
A. Cutting Banner Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/538/pro ...
- Codeforces 447C - DZY Loves Sequences
447C - DZY Loves Sequences 思路:dp 代码: #include<bits/stdc++.h> using namespace std; #define ll l ...
- Codeforces 446C —— DZY Loves Fibonacci Numbers(线段树)
题目:DZY Loves Fibonacci Numbers 题意比較简单,不解释了. 尽管官方的题解也是用线段树,但还利用了二次剩余. 可是我没有想到二次剩余,然后写了个感觉非常复杂度的线段树,还是 ...
- [蓝桥杯2015决赛]分机号-枚举(水题)
题目描述 X老板脾气古怪,他们公司的电话分机号都是3位数,老板规定,所有号码必须是降序排列,且不能有重复的数位. 比如:751,520,321 都满足要求,而766,918,201 就不符合要求. 现 ...
最新文章
- Deadline来了,如何按时结题?
- Java8新特性之函数式接口
- Sass笔记(CSS 的预编译语言)
- mysql编译安装后目录空_MySQL源码安装完成后修改安装路径启动问题
- python手把手教程_【Python 1-7】Python手把手教程之——详解列表List
- restify mysql_[菜鸟试水]关于Nodejs搭建后台API服务(Mysql-Restify)[下]
- Python《使用selenium解决动态加载的问题》
- cmd xcopy 拷贝文件夹_u盘文件夹被病毒隐藏怎么解决 u盘文件夹被病毒隐藏解决方法【详细步骤】...
- 图解FCKeditor在asp.net环境的安装(上)
- c语言 怎么访问64位地址_巧言C语言指针 | 纯干货讲解
- android 打包成多个so,Android Studio打包.so库到apk中实例详解
- 2019上半年系统集成项目管理工程师上午真题及答案解析
- linux oracle ora-00257,Oracle数据库的ORA-00257故障解决过程
- C++实现简单贪吃蛇代码
- 计算机主机报警 声,电脑开机报警4声长鸣解决教程 | 专业网吧维护
- 高级计算机怎么计算增速,增速的计算公式
- easyexcle 设置列宽_在excel中,如何让excel的列宽自动调整
- 【usaco 2013 feb Bronze】计算周长
- 136A.Presents
- 第三极拟撤离中关村:网上书店挤占生存空间
热门文章
- Java类型转换工具类(十六进制—bytes互转、十进制—十六进制互转,String—Double互转)
- mybatis-plus忽略映射字段
- zookeeper 3.5.6安装
- python restful风格_总结python bottle框架支持jquery ajax的RESTful风格的PUT和DELETE方法
- mycat核心配置详解(schema.xml配置)
- 通过安装和配置AD域解决Windows Server 2016的IIS无法加载SMB文件卷文件的问题
- 使用redis分布式锁+lua脚本实现分布式定时任务控制demo
- php里面用魔术方法和匿名函数闭包函数动态的给类里面添加方法
- 浪潮科大讯飞Altera用OpenCL实现FPGA深度学习语音识别加速方案
- Nginx 笔记与总结(12)Nginx URL Rewrite 实例(ecshop)