uva online judge self describing sequence problem solution python | uva 10049

The self describing sequence problem  (uva 10049) is also very straight forward and easy programming challenge in competitive programming once understood well. Which can be stated as (from online judge) Solomon Golomb’s self–describing sequence ⟨f(1),f(2),f(3),...⟩ is the only nondecreasing sequence of positive integers with the property that it contains exactly f(k) occurrences of k for each k. A few moments thought reveals that the sequence must begin as follows: n 1 2 3 4 5 6 7 8 9 10 11   12 f(n) 1 2 2 3 3 4 4 4 5 5 5 6 In this problem you are expected to write a program that calculates the value of f(n) given the value of n. Sample Input 100  9999  123456  1000000000  0 Sample Output 21  356  1684  438744 Programming Explanation This is very simple problem states that for given range of n as input (as shown in above image), we have

uva online judge contest scoreboard problem solution python | uva 10258

The contest scoreboard problem (uva 10258) is very straight forward programming challenge from competitive programming. Which can be stated as (from online judge)

Contestants are ranked first by the number of problems solved (the more the better), then by decreasing amounts of penalty time. If two or more contestants are tied in both problems solved and penalty time, they are displayed in order of increasing team numbers.

A problem is considered solved by a contestant if any of the submissions for that problem was judged correct. Penalty time is computed as the number of minutes it took for the first correct submission for a problem to be received plus 20 minutes for each incorrect submission received prior to the correct solution. Unsolved problems incur no time penalties.

This means that for every incorrect submission, contestant receive an penalty of 20 mins. Maximum number of problems solved by contestant in any submission is considered as final problems solved. Our task is to calculate the final score of contestant from his all submissions.

Given each input line consist four parts, 
[contestant number] [number of problems solved] [time required] [submission status]

Each contestant will receive one of the five submission status ( ‘C’, ‘I’, ‘R’, ‘U’ or ‘E’. These stand for Correct, Incorrect, clarification Request, Unjudged and Erroneous submission), where submissions with 'R', 'U' and 'E' are ignored and not considered in final score.

For each incorrect  submission, 20 mins are added to time slot as penalty, no incorrect submission is accepted after correct submission. While considering incorrect submission, time of that submission is skipped, instead +20 where added in place of it. 

Sample Input

1
1 2 10 I 
3 1 11 C 
1 2 19 R 
1 2 21 C 
1 1 25 C

Sample Output

1 2 66 
3 1 11

Explanation


we just have to check if submission is correct or not, if 'yes' then good, else add 20 mins in time slot for that contestant for every incorrect submission. Maintain flags to know that no incorrect submission should repeat after correct one.


Code

Board = {}
Final_score = {}
Teams = []
Useless = ['R','U','E']
temp = input().split(" ")
n = 0

Correct = dict()
Repeat = dict()
while(True):                    #Take input until user enters
    try:
        temp[1]
    except:
        break
    Board[n] = temp
    n = n+1
    temp = input().split(" ")

for i in range(0,n):
    for j in range(0,3):
        Board[i][j] = int(Board[i][j]) #convert to int and add to repeat
    Repeat[Board[i][0]] = False
    Correct[Board[i][0]] = False
 

for i in range(0,n):
        if(Board[i][3] in Useless):
            continue
        elif(Board[i][3] == 'I' and Correct[Board[i][0]] == False):
            if(Repeat[Board[i][0]] == True):
                Final_score[Board[i][0]][2] += 20
                if(Board[i][1] > Final_score[Board[i][0]][1]):
                    Final_score[Board[i][0]][1] = Board[i][1]
            else:
                Repeat[Board[i][0]] = True
                Board[i][2] = 20
                Final_score[Board[i][0]] = Board[i]
        elif(Board[i][3] == 'C'):
            if(Repeat[Board[i][0]] == True):
                Final_score[Board[i][0]][2] += Board[i][2]
                if(Board[i][1] > Final_score[Board[i][0]][1]):
                    Final_score[Board[i][0]][1] = Board[i][1]
            else:
                Repeat[Board[i][0]] = True
                Correct[Board[i][0]] = True    #to avoid 'I' after 'C'
                Final_score[Board[i][0]] = Board[i]

for i in Final_score:

    print(str(Final_score[i][:3]))

After accepting input from user, we check if for any incorrect submission whether it is repeated or not. If yes then add 20 in Board[i][2] as time slot and add maximum number of problems solved in final_score (i.e by checking already exist solved number with new submission number, max is considered).
If repeated is false, then simply add 20 in time slot and add to final_score.

For every correct submission, if repeated is 'yes' then add time taken to solve problem with final score and number of problems solved as max number of problems solved in any submission.
If repeated is false, then marks correct flag as 1 to avoid incorrect submission after correct one, and add to final_score. 

Related keywords: contest scoreboard, uva contest scoreboard problem, contest scoreboard online judge, contest scoreboard explanation, contest scoreboard source code, contest scoreboard solution python, uva 10258, uva 10258 solution, uva 10258 problem explanation.

Comments

Popular posts from this blog

uva online judge vito's family problem solution python | uva 10041

uva online judge australian voting problem solution python | uva 10142

uva online judge common permutation problem solution python | uva 10252