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 football (aka soccer) problem solution python | uva 10194

The football problem (uva 10194) is very straight forward programming challenge from competitive programming in which we just have to observe string and pull values out. Which can be stated as (from online judge)

write a program that receives the tournament name, team names and games played and outputs the tournament standings so far. A team wins a game if it scores more goals than its opponent. Obviously, a team loses a game if it scores less goals. When both teams score the same number of goals, we call it a tie. A team earns 3 points for each win, 1 point for each tie and 0 point for each loss. Teams are ranked according to these rules (in this order):
1. Most points earned.
2. Most wins.
3. Most goal difference (i.e. goals scored - goals against)
4. Most goals scored.
5. Less games played.
6. Lexicographic order.

Please note that this tutorial does not cover ordering of teams, it just simply shows extracting required values from string. Ordering of teams if left for students as homework. If you need help then you can read our previous blogs to get idea about ordering.

Sample Input

1

World Cup 1998 - Group A
4
Brazil
Norway
Morocco
Scotland
6
Brazil#2@1#Scotland
Norway#2@2#Morocco
Scotland#1@1#Norway
Brazil#3@0#Morocco
Morocco#3@0#Scotland
Brazil#1@2#Norway

Sample output


World Cup 1998 - Group A
1) Brazil 6p, 3g (2-0-1), 3gd (6-3)
2) Norway 5p, 3g (1-2-0), 1gd (5-4)
3) Morocco 4p, 3g (1-1-1), 0gd (5-5)
4) Scotland 1p, 3g (0-1-2), -4gd (2-6)

Explanation

Given world cup name as input, followed by number of teams and teams names, followed by total number of matches and match results. I.e Team A#3@1#Team B Means that in a game between Team A and Team B, Team A scored 3 goals and Team B scored 1.


We have to give output in the form of
[a]) Team name [b]p, [c]g ([d]-[e]-[f]), [g]gd ([h]-[i])
Where:
• [a] = team rank
• [b] = total points earned
• [c] = games played
• [d] = wins
• [e] = ties
• [f] = losses
• [g] = goal difference
• [h] = goals scored
• [i] = goals against

Code

no_case = int(input())
team = []
match = []
global a, b, c, d, e, f, g, h, I
a, b, c, d, e, f, g, h, I = dict(), dict(), dict(), dict(), dict(), dict(), dict(), dict(), dict()
world_cup = input()
no_of_teams = int(input())


def result(res):
    for i in range(0, len(res)):
        if (res[i] == '#'):
            index = i
            break
    team_1 = res[:index]
    team_1_goals = int(res[index + 1])
    team_2_goals = int(res[index + 3])
    team_2 = res[index + 5:]

    if (team_1_goals > team_2_goals):
        d[team_1] += 1
        f[team_2] += 1
        b[team_1] += 3
    elif (team_1_goals == team_2_goals):
        e[team_1] += 1
        e[team_2] += 1
        b[team_1] += 1
        b[team_2] += 1
    else:
        d[team_2] += 1
        f[team_1] += 1
        b[team_2] += 3

    h[team_1] += team_1_goals
    I[team_1] += team_2_goals
    h[team_2] += team_2_goals
    I[team_2] += team_1_goals

    c[team_1] += 1
    c[team_2] += 1


def get_score(team):
    for i in team:
        g[i] = abs(h[i] - I[i])


for i in range(0, no_of_teams):
    t = input()
    team.append(t)
    a[t] = 0
    b[t] = 0
    c[t] = 0
    d[t] = 0
    e[t] = 0
    f[t] = 0
    g[t] = 0
    h[t] = 0
    I[t] = 0

no_of_matches = int(input())

for i in range(0, no_of_matches):
    match.append(input())

for i in range(0, no_of_matches):
    result(match[i])

get_score(team)

for i in team:
    print(i, b[i], c[i], "g (", d[i], '-', e[i], '-', abs(f[i]), ")", g[i], "gd (", h[i], "-", I[i], ")")


In this program, we just observed common sequence in string and pull out informative content. i.e if at ith index '#' occures then at i+1 position there is goals scored of that team, at i+3 position there opposite team goals followed by team name at i+5th position, and so on.

Again, this only covers extraction and do not covers ordering and ranking of teams.  This is left for students to do on their own, if you need more help read our previous blogs to get idea about ordering.

Hope, this article found helpful to you. Thank you.


Related keywords: football aka soccer, football aka soccer problem, football aka soccer programming challenge, football aka soccer problem solution, football aka soccer problem explanation, football aka soccer online judge, football aka soccer uva, uva 10194, football aka soccer source code python, uva 10194 solution, uva 10194 source code.

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