题目是这样的:
Description:
Input
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
Output a real number denoting the answer, with an absolute or relative error of at most 10 ^- 9.
Hint
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 <iostream>
#include <cstdio>
using namespace std;
int a[505];
int main()
{
int n,m;
int n1,n2;
double max=0;
int v;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
if(n==1)
{
cout<<0.000000000000000<<endl;
return 0;
}
for(int j=0;j<m;j++)
{
cin>>n1>>n2>>v;
double n3= (double)(a[n1]+a[n2])/v;
if(n3>max)
{
max=n3;
}
}
printf("%.15lf",max);
return 0;
}
仅代表个人观点,欢迎交流探讨,勿喷~~~
PhotoBy:WLOP