PAT 1033. To Fill or Not to Fill

题目:http://pat.zju.edu.cn/contests/pat-a-practise/1033

题解:

代码:

#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define INF 0x6fffffff
struct point
{
    double price;
    double distance;
} node[505];
bool cmp(const struct point &a,const struct point &b)
{
    return a.distance0)
    {
        printf("The maximum travel distance = 0.00\n");
    }
    else
    {
        flag=true;
        nowCapacity=0.0;
        summ=0.0;
        for(int i=0; ilen)//两站距离大于最大行驶距离
            {
                flag=false;
                printf("The maximum travel distance = %.2f\n",node[i].distance+ len);
                break;
            }
            minPrice=node[i].price;
            idx=i;
            for(int j=i+1; j<=n&&node[j].distance-node[i].distance<=nowCapacity*davg; ++j)
            {//找出当前油箱里的油能到达的所有加油站里,油价最便宜的那个
                if(node[j].price

来源: http://blog.csdn.net/acm_ted/article/details/20592059

你可能感兴趣的:(PAT)