若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。


  • 运维

  • 前端

  • 编程

  • 随笔

  • hust-oj

1131: Problem B: Jogging Trails

发表于 2017-10-06   |   分类于 HUSTOJ   |   阅读次数 1,443

题目描述

Problem B: Jogging Trails
Gord is training for a marathon. Behind his house is a park with a large network of jogging trails connecting water stations. Gord wants to find the shortest jogging route that travels along every trail at least once.
Input consists of several test cases. The first line of input for each case contains two positive integers: n <= 15, the number of water stations, and m < 1000, the number of trails. For each trail, there is one subsequent line of input containing three positive integers: the first two, between 1 and n, indicating the water stations at the end points of the trail; the third indicates the length of the trail, in cubits. There may be more than one trail between any two stations; each different trail is given only once in the input; each trail can be travelled in either direction. It is possible to reach any trail from any other trail by visiting a sequence of water stations connected by trails. Gord's route may start at any water station, and must end at the same station. A single line containing 0 follows the last test case.
For each case, there should be one line of output giving the length of Gord's jogging route.

输入

暂无

输出

暂无

样例输入

4 5
1 2 3
2 3 4
3 4 5
1 4 10
1 3 12
0

样例输出

41

参考代码

#include <math.h>
#include <stdio.h>
#define pi (2*acos(0))
double D,V,d,delta;
int i,j,k;
double v(double d) 
{
    double R = D/2;
    double r = d/2;
    double vCyl = D * pi * R * R;
    double vcyl = d * pi * r * r;
    double vCone = pi * (D/2)*(D/2)*(D/2) / 3;
    double vcone = pi * (d/2)*(d/2)*(d/2) / 3;
    double res = vCyl - 2*vCone - vcyl + 2*vcone;
    return res;
}
main() 
{
    while (2 == scanf("%lf%lf",&D,&V) && D) 
    {
        delta = d = D/2;
        for (d=D/2; delta > .000000001; delta /=2) 
        {
            if (v(d) < V) d -= delta; else d += delta;
        }
        printf("%0.3lfn",d);
   }
}

解析

暂无

hustoj

发表评论 取消回复

邮箱地址不会被公开。 必填项已用*标注

*
*


hoxis wechat
著作权归作者所有
站点更新说明
  • 文章目录
  • 站点概览
若是凉夜已成梦

若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。

1904 日志
6 分类
12 标签
RSS
weibo github twitter facebook

友情链接

Dreams孤独患者 Skip 原站点
© 2017 若是凉夜已成梦
Powered by WordPress | 已运行
Theme By NexT.Mist