110,534
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
///
/// </summary>
class scores
{
class roadCondition
{
public string roadName;
public double roadLength;
public double scale; //受阻系数
public roadCondition(string p_name,double p_roadLength,double p_scale)
{
roadName = p_name;
roadLength = p_roadLength;
scale = p_scale;
}
}
private List<roadCondition> roadList;
public void addRoad(string p_name,double p_roadLength, double p_scale)
{
if(roadList==null)
{
roadList = new List<roadCondition>();
}
roadList.Add(new roadCondition(p_name,p_roadLength,p_scale));
}
public void clearRoad()
{
if(roadList!=null)
{
roadList.Clear();
}
}
public string getBestRoad()
{
return roadList.OrderByDescending(r => r.roadLength * r.scale).FirstOrDefault().roadName;
}
}
//计算
scores theScore = new scores();
theScore.addRoad("c", 100, 0.1);
theScore.addRoad("d", 120, 0.08);
theScore.addRoad("e", 80, 0.15);
Response.Write(theScore.getBestRoad() + "<br />");
web下输出e,最佳是e路径