Question

In: Computer Science

Minimum Recharging Stops You have decided that your first purchase after graduation will be a Tesla...

Minimum Recharging Stops
You have decided that your first purchase after graduation will be a Tesla Model X. You have further decided to drive from Harrisburg to San Francisco, as quickly (and safely) as possible. In order to minimize your travel time, you wish to minimize the number of recharging stops. You have recorded the distances between charging stations on your route, and you know the maximum range that you can travel on a single charge.

Input: An array g containing the distances of charging stations on the route from the starting point; r the range you can travel on a single charge, and d the length of the route from Harrisburg to San Francisco. You are guaranteed that the distances between the charging stations will be less than or equal to r.

Return: The minimum number of stops needed for charging in order to complete the trip.

a) Suppose that you wrote an exhaustive search algorithm. How many possible solutions would you examine?
b) Write an efficient algorithm to solve this problem.

Solutions

Expert Solution

1) For exaustive solution, I will examine the boundary conditions and the condition where range is less than the next recharge station.

2)

An algorithm for the peoblem:

#include<iostream>
using namespace std;
int main()
{
   int N=5,i=0;
   int g[N],r,d;
   for(int i=0;i<N;i++)
   {
       cin>>g[i];
   }
   cin>>r>>d;
   int travelled=0;
   while(d>0)
{
   travelled=travelled+g[i];
   if(travelled>r)
   {
       int extra=0;
       extra=travelled-r;
       travelled=travelled-extra;
       cout<<"Recharge"<<endl;
       r=r+r;//increase range
   }
   else
   {
      
       cout<<"Travelling"<<endl;
   }
   d=d-travelled;
   if(d==0 || d<0)
   cout<<"Reached Destination";
}
  
   return 0;
}


Related Solutions

Just after graduation, you have joined ABC Financial Advisors as a Paraplanner. Your first job is...
Just after graduation, you have joined ABC Financial Advisors as a Paraplanner. Your first job is to prepare basic financial statements and analyse the financial situation of a client. The prepared Fact Sheet based on information provided by the client reveals the following information. The client, Ms Rae Adams, is employed as a Management Trainee at YZ Manufacturing. Her gross salary for the financial year is $72,000. In addition, the employer contributes 9.5% of her gross salary into a personal...
Soon after your graduation, you would be all set for your career path. As you have...
Soon after your graduation, you would be all set for your career path. As you have studied and learnt several investment and portfolio related theories and concepts, you would be interested to start investing and creating portfolio right from the beginning phase of your career. Before you start doing so, it would be ideal to recap those important concepts and theories. You may want to write down those in brief especially covering the following: (a) How do you think about...
4. If you were offered and decided to accept a position after graduation working for a...
4. If you were offered and decided to accept a position after graduation working for a hotel outside of the United States, what do you think would be your biggest challenges? 5. Based on the question above (number 4), what would be your expectations for the hotel to get you acclimated?
Several years after graduation you decided to buy a condo for $235,000. a. Assuming you need...
Several years after graduation you decided to buy a condo for $235,000. a. Assuming you need a 15% down-payment which you have saved, what is the amount of the loan you need to borrow? b. Given your calculation in part a, what will your monthly mortgage payment be assuming a 30 years mortgage at 4.75%? c. What is the total amount you end up paying including principal and interest? d. For comparison purposes, you also look at a 15 year...
What will motivate you in striving toward excellence in your first job after graduation? Please relate...
What will motivate you in striving toward excellence in your first job after graduation? Please relate your reasoning by referencing the theory?
After your graduation, you will be in an academic or clinical field. Depending on your field...
After your graduation, you will be in an academic or clinical field. Depending on your field choice, discuss one nursing theory and identify the effect the implications of this theory could have on nursing administration, management, or education.
You and your lovely and/or handsome spouse have decided the purchase a new home with a...
You and your lovely and/or handsome spouse have decided the purchase a new home with a loan for $260,000. The mortgage you chose offers a contract rate of 4.5%, a maturity of 30 years, and requires the payment of 3 points. What is the annual effective cost of borrowing for this loan if you make your scheduled payments for the full 30 years?
You and your family have recently closed on the purchase of your first home and you...
You and your family have recently closed on the purchase of your first home and you are excited. You are in need of furniture and appliances for your new home. You have decided to purchase some of the items from eBay and have found a dining room set and living room furniture from a private seller on eBay’s website. You look at the pictures on the website and notify the seller through email that you would like to purchase these...
Ryan and Robin met at Rockhurst university and after graduation in 2020; they decided to form...
Ryan and Robin met at Rockhurst university and after graduation in 2020; they decided to form a business to market American flags, “buy American” bumper stickers, and other similar merchandise. The merchandise would be manufactured in China and sold initially only in Missouri. Ryan wants to operate the business as a partnership; while Robin wants to organize the business as a regular C corporation. Limit your answers for the first two question to these two business forms (3 points each)...
Suppose you have decided to purchase an automobile. You analyze your personal budget and decide you...
Suppose you have decided to purchase an automobile. You analyze your personal budget and decide you can afford monthly payments of $506 for five years. If your loan carries an annual interest rate of 12%, what the highest priced car you can afford? a. Excel command ____________ b. answer ____________
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT