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]
4 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]4 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]4 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
Most engines will contain how many cylinders in order to maintain a proper balance of weight and forces?
Alika [10]
A. An Even Number is the answer!
4 0
4 years ago
Read 2 more answers
Papa Mario of Mario's Pizzeria has baked a huge pizza and cut it into n slices, but he is clumsy and the pizza wasn't evenly sli
rosijanka [135]

Suppose there are n student: 1, 2, 3, ..., i, ..., n.

Now, let's say each want slice size to be: t1, t2, ..., ti, ..., tn.

Let's pizza slices be : s1, s2, ..., si, ..., sn.

Now, it can be said that a student ' i ' will accept a slice of pizza ' si ' only if the size of slice is more then ' ti '.

Logic to distribute: what can be done is we can sort the demand i.e ti of students and also sort the size of pizza slices si. Now, Papa Mario can distribute the sorted slices to students sorted demand(smallest to heighest) one by one as they appear in sorted lists. Now, it will only be possible to distribute the slices to make everyone happy, if and only if in sorted lists of both s and t for each index k, it holds the condition: tk <= sk.

Let me explain you with example:

Lets says size of whole pizza is 100.

Now number of students n = 4.

Let there demands be : 20, 35, 15, 10.

This means 1st student atleast require the slice size of 20 and so on.

Case 1: Papa Mario divides the pizza into slices of size: 25, 20, 20, 35.

=> Now, we sort both lists.

Thus t => 10, 15, 20, 35

and s => 20, 20, 25, 35

Now, as we can see that for all index  tk <= sk, hence pizza can be distrubeted so that everyone can be happy.

Case 2: Papa Mario divides the pizza into slices of size: 30, 20, 20, 30.

=> Now, we sort both lists.

Thus t => 10, 15, 20, 35

and s => 20, 20, 30, 30

Now, as we can see that, for last student with demand of 35, the pizza slice alotted is of size 30, thus he is unhappy, and pizza cannot be distributed so that everyone becomes happy.

Now, after the approach, let's discuss question.

(a) Greedy algorithm paradigm is most appropriate for this problem, as what we are doing is greedily distributing small slices to those students which have least demands first then tackling bigger demands of students, by remaining bigger slices.

(b) As we are mainly sorting thel ist of sizes of pizza slices and student demands, thus we need to use an efficient algorithm to sort the lists. Such an efficient algorithm can be QuickSort() or MergeSort().

(c) Asymptotic running time of our algorithm would be O(n*logn).

3 0
3 years ago
How does polling-based network receive work? How is it different than interrupt based network? Describe both functions and list
Alenkasestr [34]

In a polling-based network receives, the operating system keeps checking the status register after a fixed time interval to see whether a device needs hardware attention or not. CPU gradually checks the status of receive bit after a defined time interval of a clock and if the value of receive bit is true then data is moved from the RX register to the memory. In interrupt-based networks, whenever a device needs hardware processing then an interrupt is raised to inform the CPU for device attention. The data of the device is transferred to memory from the network card.

Polling is a protocol, not a hardware mechanism where the device gets attention by CPU. An interrupt is a hardware mechanism, not a protocol where the device gets attention by the interrupt handler. In polling, during receiving, parts of received data need to transfer to memory but in case of interrupts, whole data is transferred at once after receiving is done. An interrupt is a heavy operation as compared to pooling because hardware involves in it. For large amounts of data, Polling becomes an inefficient method. In polling, CPU gradually checks devices at regular intervals whereas the Interrupt handler can send interrupt at any time. Each device has its own Command ready bit which indicates whether the device requires servicing or not. In polling, CPU wastes numerous clock cycles by repetitively checking the command-ready little bit of each device. In Interrupt based network, the interrupt request line indicates whether the device requires servicing or not. In interrupt-based network, CPU cycles not wasted but CPU is disturbed only when device send interrupt signals.  

Relative performance between programmed I/O and DMA:

For determining the relative performance between programmed I/O and DMA, important factors are:

1. Size of data  

2. Frequency of operations

5 0
4 years ago
Which of the following are considerations in e-commerce and e-government Internet sites? Check all of the boxes that apply.
vovangra [49]

Answer:

protection of sensitive information

Explanation:

6 0
3 years ago
Which type of image is not a supported using the online picture or insert picture command?
Anarel [89]

Answer:

thumbnail pane

Explanation:

just took the review for it

5 0
3 years ago
Other questions:
  • Under the class system, how many host ids were available in a class b network?
    7·1 answer
  • How does Taylorism (scientific management used to streamline mass production) resemble a bureaucracy? Select one: a. Routinizati
    5·1 answer
  • - The concept of communication competence suggests there is no single "ideal" or "effective" way to communicate in every situati
    6·2 answers
  • Which practice is the best option for desktop security? A. Make a unique user ID and password for each account. B. Change the pa
    9·2 answers
  • Select the correct answer.
    10·1 answer
  • Write function that ask for input from a user. Use this input as input for the countdown function that we wrote using the while
    6·1 answer
  • Can anyone please help?
    13·1 answer
  • What is the solution to the equation ?
    8·2 answers
  • Code used when creating a hyperlink to a specific part of the same page.
    15·1 answer
  • Jeremy knows that there is a keyboard shortcut in Word, but he does not know what it is. What should Jeremy do to find out what
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!