1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
IrinaVladis [17]
3 years ago
10

Even-Odd Operations Given an array of non-negative integers, perform a series of operations until the array becomes empty. Each

of the operations gives a score, and the goal is to maximize the overall score, the sum of the scores from all operations. Determine the maximum possible score after performing the operations on the array. All operations are 1-indexed, and are defined as follows: 1. For every odd-indexed operation, the score is the sum of all integers present in the array. 2. For every even-indexed operation, the score is the negative of the sum of all integers present in the array. 3. After every operation (odd or even), remove either the leftmost or the rightmost integer from the array. For example: Let integerArray = [3, 6, 8] Initial score = 0 The operations are as follows: 1. Operation 1 is odd, so add the sum of the array to the score. score = 3 + 6 + 8 = 17 Choose to delete the rightmost integer (i.e. 8), and now integerArray = [3, 6] 2. Operation 2 is even, so subtract the sum of the array from the score. sum = 3 + 6 = 9 and score = 17 - sum = 17 - 9 = 8 Choose to delete the leftmost integer (i.e. 3), and now integerArray = [6] 3. Operation 3 is odd, so add the sum of the array to the score sum-hand score – 8I sum - 816 - 11 2. Uperation 2 is even, so subtract the sum of the array from the score. sum = 3 + 6 = 9 and score = 17 - sum = 17 - 9 = 8 Choose to delete the leftmost integer (i.e. 3), and now integerArray = [6] 3. Operation 3 is odd, so add the sum of the array to the score. sum = 6 and score = 8 + sum = 8 + 6 = 14 Only one element is left. It is both the leftmost and rightmost element, so delete it (i.e. 6), and now integerArray = [ ] The array is now empty, so no further operations are possible. The maximum possible score is 14. Function Description Complete the function getMaximumScore in the editor below. The function must return the maximum possible score after performing all the operations. getMaximumScore has the following parameter: integerArray: an array of integers Constraints • 1 s size of integerArray < 103 • 0 s integerArray[i] = 109

Computers and Technology
2 answers:
maxonik [38]3 years ago
7 0

Answer:

# include<iostream>

# include<stdio.h>

# include<stdlib.h>

using namespace::std;

int main()

{

   int *a=NULL;

   int n; int score=0;

   cout<<"Enter the value of N";

   cin>>n;

   a=new int[n];

   cout<<"Enter the elements of a";

   for(int i=0;i<=n;i++)

   {

       cin>>a[i];

   }

   int num=n;int k=n;int j=num;

   while(j>=num)

   {

   if(n%2==0)

   {

     for(int i=0;i<=k;i++)

     {

         score+=a[i];cout<<score;      }

     if(a[0]>a[n])

       {

             a[n]=0;

             n--;

         }

     else if(a[0]<a[n])

     {

           a[0]=0;

           n--;

     }

     else if(n==1)

     {

         exit(0);

     }

     

   }

   else

   {

       for(int i=0;i<=n;i++)

       {

           score-=a[i];

       }

       if(a[0]>a[n])

       {

             a[n]=0;

             n--;

       }

     else if(a[0]<a[n])

     {

           a[0]==0;

           n--;

     }

     else

     {

         exit(0);

     }

   }

   j--;

   }

   cout<<"score"<<score;

   return 0;

}

Explanation:

The array above is created dynamically, and rest is as mentioned in question.

ivann1987 [24]3 years ago
6 0

Answer:

Explanation:

def getMaximumScore(array, n):

   """

       array: list of positive numbers/integers

       n : size of array

       return: score (maximum)

   """

   score=0  # initially zero

   operation = "Odd"

   while len(array)!=0:

       s = sum(array)

       if operation=="Odd":

           score+=s

           operation="Even"

           del(array[-1])

       elif operation=="Even":

           score-=s

           operation="Odd"

           del(array[0])

   return score

print("Maximum score: "+str(getMaximumScore([3,6,8],3)))

You might be interested in
For this problem, you will write a function standard_deviation that takes a list whose elements are numbers (they may be floats
Evgesh-ka [11]

Answer:

  1. import math  
  2. def standard_deviation(aList):
  3.    sum = 0
  4.    for x in aList:
  5.        sum += x  
  6.    
  7.    mean = sum / float(len(aList))
  8.    sumDe = 0
  9.    for x in aList:
  10.        sumDe += (x - mean) * (x - mean)
  11.    
  12.    variance = sumDe / float(len(aList))
  13.    SD = math.sqrt(variance)
  14.    return SD  
  15. print(standard_deviation([3,6, 7, 9, 12, 17]))

Explanation:

The solution code is written in Python 3.

Firstly, we need to import math module (Line 1).

Next, create a function standard_deviation that takes one input parameter, which is a list (Line 3). In the function, calculate the mean for the value in the input list (Line 4-8). Next, use the mean to calculate the variance (Line 10-15). Next, use sqrt method from math module to get the square root of variance and this will result in standard deviation (Line 16). At last, return the standard deviation (Line 18).

We can test the function using a sample list (Line 20) and we shall get 4.509249752822894

If we pass an empty list, a ZeroDivisionError exception will be raised.

3 0
3 years ago
You are using a wireless client adapter with a site survey utility and a notebook computer to perform a manual site survey in a
Oduvanchick [21]

Answer:

Signal strength and SNR

Explanation:

The signal strength and SNR are two important values to record during the manual site survey process. Signal loss and propagation loss have different effects, and packet retries are more of an issue with dynamic rate selection.

5 0
3 years ago
You have been tasked with ensuring that access to certain server managed resources is only available to client devices with TPM
elixir [45]

Answer:

Device Health Attestation Services

Explanation:

Based on the scenario being described it can be said that the Windows Server role that can be used to automate this check is known as Device Health Attestation Services. This is a role that allows the administrator to automatically check if a device has the required trustworthy BIOS, TPM, or boot software enabled, as well as Bitlocker encryption.

7 0
3 years ago
when an object is passed as a non-reference pointer parametor to a method, modifiying the members of that object from
larisa [96]

Answer:

"this" keyword representing the class object itself.

Explanation:

Object-oriented programming concept emphasizes on using blueprints representing the structure of a data collection type to continuously create an instance of that data structure. The instance of that object is called a class object. It is used in database management systems to populate the database.

Functions defined in the class objects are called methods and are used specifically by the class instance to modify the data content of the class object defined.

When a member of a class is referenced in the class, it can be accessed with the "this" keyword. At an instance of the class object, the variable holding the object should be called to get the class content because of the "this" keyword binding the instance of the object to the method.

6 0
3 years ago
Do you need a internet browser to go to the intrnet?​
Sloan [31]

Answer:

No you do not need a interent browzer to get to the internet.

Explanation:

7 0
3 years ago
Read 2 more answers
Other questions:
  • All of the following are incentives proprietary schools use to attract a student except
    7·2 answers
  • A microphone is a type of electronic.<br><br> True/Faulse
    14·1 answer
  • Www.microsoft.com is an example of this (two words) (last letter is e) and has to be (10 letters)
    10·1 answer
  • In vehicles equipped with ABS, the driver's foot must remain firmly on the _________ to activate the ABS.
    7·2 answers
  • so i just went to play forge of empires and when i logged on to it all of my progress was gone and i was so far in to it
    15·2 answers
  • Characteristics of RAM​
    5·1 answer
  • Sustainable development is a goal towards which all human societies need to be moving. elaborate the statement in about 120 word
    9·1 answer
  • Are there any Potential Dangers in Artificial Intelligence?
    11·2 answers
  • If you anticipate running a particular query often, you can improve overall performance by saving the query in a special file ca
    11·1 answer
  • a 2x4 line decoder with enable is implemented using nand gate only. how many nand gate is needed to construct this line decoder?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!