开发者

Compute Salary Increments

In a company, there are three categories: A,B,C.

They want to give an increment.开发者_StackOverflow中文版 So if category C gets N% as increment. category B gets 2N% as increment and category A gets 3N% as increment. But the increment should be atleast 1% and The total updated salary should not exceed $50,000.

Print the increment and the total updated salary for a particular employee.

Assume all the required variables.

How do I solve the above, there seem to be many unknown parameters like SALARY A, SALARY B, SALARY C, and increment N. looking for the maximum possible value of N within the restriction


If you're looking to implement a simple procedural update of employees, you haven't specified a language (which is good since I only provide pseudo-code for homework anyway), but here it is:

def update (N,MAX)
    if N < 1:
        return
    for every employee E:
        select E.catagory:
            if 'C':
                E.salary = E.salary * (1 +     N / 100)
            endif
            if 'B':
                E.salary = E.salary * (1 + 2 * N / 100)
            endif
            if 'A':
                E.salary = E.salary * (1 + 3 * N / 100)
            endif
        endselect
        if E.salary > MAX:
            E.salary = MAX
        endif
        print E.name " is now on a wage of $" E.salary
     endfor
enddef

Now your task is to translate that into whatever language you have to implement this in :-)


If you're wanting to solve all the unknowns in an equation, you have a problem (conflicting requirements). It appears you may be after the value of N which will make the largest wage $50K.

You just need to go through every employee and figure the maximum percentage out:

def update (MAX) returns N:
    N = Infinity
    for every employee E:
        select E.catagory:
            if 'C':
                ThisN = MAX / E.salary - 1
            endif
            if 'B':
                ThisN = (MAX / E.salary - 1) / 2
            endif
            if 'A':
                ThisN = (MAX / E.salary - 1) / 3
            endif
        endselect
        if ThisN < N:
            N = ThisN
        endif
     endfor
     if N < 1:
         # Conflicting requirement
     endif
enddef

It's possible to come up with a value of N that's less than 1 if, for example, a category C employee is already on $50K. You need to decide what you want to do in that case, either:

  • give no-one a payrise (violates the >=1% rule).
  • give everyone 1% (violates the $50K cap rule).
  • give everyone 1% but cap at $50K (violates the 1,2,3 multiplier rule).

Once you have the percent increase from that code (with your decision on what to do for the conflicting requirements), you can pass it into the first piece of code above to actually do and print the update.


To just work out maximum N for any set of salaries:

If N is a percentage, let n be N/100 (to make the math easier). Let the salary for each category be a, b, and c respectively.

Since n >= 0.01, and the salary plus the increment <= 50000, and we can assume a salary is greater than 0, then

0 < a <= 50000 * (1 - n)
0 < b <= 50000 * (1 - 2 * n)
0 < c <= 50000 * (1 - 3 * n)

The last line puts the strongest restriction on n - i.e. 0.01 <= n < 0.333...

You might need to know the minimum wage :)

If you actually have data for employees, then the maximum N will depend on the maximum salary for employees in each category.

max(a) <= 50000 * (1 - n)
max(b) <= 50000 * (1 - 2 * n)
max(c) <= 50000 * (1 - 3 * n)

So we have several requirements for n:

n <= 1 - max(a)/50000
n <= 1/2 - max(b)/100000
n <= 1/3 - max(c)/150000

So you just need the minimum of the values on the right.


Given three Lists of Employees' Salaries, A, B, C,

Set Increment=0%
Set TempNewSalaries{A,B,C} = {A+3*Increment%, B+2*Increment%, C+Increment%}
Set NewSalaries{A,B,C} = TempNewSalaries{A,B,C}
While MaximumSalaryOfAll TempNewSalaries{A,B,C} <= 50000
    Set NewSalaries{A,B,C} = TempNewSalaries{A,B,C}
    Increment = (Increment+1)%
    Set TempNewSalaries{A,B,C} = {A+3*Increment%, B+2*Increment%, C+Increment%}
End While
Return NewSalaries{A,B,C}

The pattern here is:

  1. Establish what a higher increment would give
  2. Validate that these values would still be valid given your constraints
  3. Repeat
  4. Return the maximum valid result, discarding the first invalid result


Calculate increment between current salary and $50,000. ratio=(50000-current)/current. Then convert to percent above 100. N=100*ratio-100. If Employee is in category C, return N. If Employee is in category B, let N=N/2. Return N. If Employee is in category A, let N=N/3. Return N.


The missing variable are the number of employee in each category, and of course not all of them have the same salary, that's why we need the average salary and the number of employee in each category.

Assume the average salary for Category A is SA, B is SB and C is SC

Assume the Employ Number for Category A is NA, B is NB and C is NC

then

 50,000 = ((3N*SA*NA) +(2N*SB*NB)+(N*SC*NC))/100 + ((SA*NA) +(SB*NB)+(SC*NC))

N= ((50,000 -((SA*NA) +(SB*NB)+(SC*NC))) *100)/((3*SA*NA)+(2*SB*NB)+(SC*NC))

let we assume the constant K =100/ ((3*SA*NA)+(2*SB*NB)+(SC*NC))

 M=((SA*NA) +(SB*NB)+(SC*NC))

the amount 0<X<50000 and Y=N then Y=(X-M)*K linear equation

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜