相关疑难解决方法(0)

做出完整的圆形路径,最短路径运动?

我在接受采访时得到了这个问题,但我无法解决.

你有一条环形公路,有N个加油站.你知道每个车站有多少气体.你知道从一个站到下一个站所需的气体量.你的车从0气开始.问题是:创建一个算法,知道你必须从哪个加油站开始驾驶以完成圆形路径.它没有指定您必须访问所有站.你只能顺时针驾驶.

我不得不在c#中做到这一点

我开始的唯一代码是GasStation实体

class GasStation
  int gasAtStation;
  int gasToMoveToNextStationNeeded;
  string nameOfGasStation;


GasTation wheretoStart(List<GasStation> list)
{

}
Run Code Online (Sandbox Code Playgroud)

我是这样做的:

static void Main(string[] args)
        {
            int[] gasOnStation = {1, 2, 0, 4};
            int[] gasDrivingCostTonNextStation = {1, 1,2, 1};

            FindStartingPoint(gasOnStation, gasDrivingCostTonNextStation);

        }

        static void FindStartingPoint(int[] gasOnStation, int[] gasDrivingCosts)
        {
            // Assume gasOnStation.length == gasDrivingCosts.length
            int n = gasOnStation.Length;
            int[] gasEndValues = new int[n];
            int gasValue = 0;
            for (int i = 0; i < n; i++)
            {
                gasEndValues[i] = gasValue;
                gasValue += gasOnStation[i]; …
Run Code Online (Sandbox Code Playgroud)

c# algorithm

2
推荐指数
1
解决办法
1462
查看次数

标签 统计

algorithm ×1

c# ×1