3267 - I2P(I)2025_Chou_Hu_Hw7_ClassB Scoreboard

Time

2025/11/11 20:30:00 2025/11/18 18:30:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
14809 Trump's Tariff
14810 Gyro Zeppeli

14809 - Trump's Tariff   

Description

Donald Trump: Latest News, Top Stories & Analysis - POLITICO

Trump is on the move. Tariff after tariff, he put on other countries.

You, a good American citizen, will help Trump automate his tariff using a combination of functions.

Given T countries that have money and their old tariff. You are given N simple functions that define a function composition FF(old_tariff_rate) is the new tariff rate. Trump wants you to calculate the potential money that he will get for the great USA. Which is the sum of all countries new_tariff_rate * money.

Given this code:

class Country:
    def __init__(self, money, tariff):
        self.money = money
        self.tariff = tariff

def func_comp(*funcs):
    # Do something here
    return F

 

t, n = map(int, input().split())
countries = {}
for _ in range(t):
    line = input().split()
    country_name, money, tariff_start = \
        line[0], float(line[1]), float(line[2])
    countries[country_name] = Country(money, tariff_start)

function_list = []
for _ in range(n):
    line = input().split()
    command = line[0]
    num = int(line[1])
    if command == "add":
        # Do something
​        pass
    elif command == "sub":
        # Do something
​        pass
    elif command == "div":
        # Do something
​        pass
    elif command == "mul":
        # Do something
        pass
    elif command == "mod":
        # Do something
        pass

F = func_comp(*function_list)
# Continue this code

 

For each country:

  • Let new_tariff_rate = F(old_tariff_rate), (rate is a percentage, so for example if rate is 25, it means 25%)
  • The money each country has to pay is min(country_money, country_money * (new_tariff_rate / 100))

 

You will receive N lines of either one of these mini-functions:

  •     add v means return x + v
  •     sub v means return x  - v
  •     mul v means return x * v
  •     div v means return x / v
  •     mod v means return x % v

Your task is to create a function composition of these functions. For example, you are given: 

add 2
mul 2
div 3
sub 0
mod 0

 

Your F function will equal:

F(x) = (((((x + 2) * 2) / 3) - 0) % 0)
 
> Note: remember to handle zero division error, for example x / 0 and x % 0, just return x
 

Hint

func_comp function returns a function

Input

The first line contains T and N,

T = the number of countries you will need to put a tariff on

N = the number of mini functions you will get to recalculate the next tariff rate

 

The next T lines you will get: country_name, country_money, country_old_tariff_rate

where:

- country_name is unique for each country

- country_money is a floating number

- country_old_tariff_rate is a floating number

 

The next N lines you will get: command, number

where:

- command is either add | sub | mul | div | mod

- number is an integer
 

Constraints

  • T <= 1000
  • N <= 1000
  • number can be negative
  • country_money is never negative

 

Output

Output T countries and their money after the tariff is paid.

Output Trump's money, which is the sum of the money paid by all T countries

Format all floating numbers to 1 decimal place in the output. 

e.g. 2.6667 = 2.7

Sample Input  Download

Sample Output  Download

Tags




Discuss




14810 - Gyro Zeppeli   

Description

HD wallpaper: Anime, Jojo's Bizarre Adventure, Gyro Zeppeli

Gyro Zeppeli is a Jojo character who utilizes "Golden ratio" to fight enemies. "Golden ratio" is the ratio you get when you divide a number in a Fibonacci sequence, Fn+1/Fn for n = infinity. The ratio is 1.618.

Given N commands and K length, you are asked to implement a list of numbers and generators that get manipulated by N commands and output the first K numbers.

The list's element is either:

  1. An integer
  2. A generator

Given this code:

def fib_gen(limit):
    # You need to implement this
    pass

def filter_gen(gen, condition):
    for x in gen:
        if condition(x):
            yield x

 

Implement:

  1. fib_gen() function, which is a generator function for a Fibonacci sequence. (use yield)
    e.g. 0, 1, 1, 2, 3, 5, 8, 12, ...
  2. fib index limit: It appends a limited Fibonacci sequence generator to the list at the given index.
  3. push index value: It appends an integer value to the list at the given index.
  4. pop index: It removes an integer or a whole generator from the list at the given index.
  5. filter comparison value: It filters all the integers inside the list (including the generators) based on the comparison and the value given.

 

For example, in sample input two:

10 10, means we are given 10 commands, and 10 numbers to output

fib 0 100, means push the first 100 Fibonacci generator to index 0. Your list now should look like this: [fib(0 to 100)]

push 1 10, means push the integer 10 to index 1. Your list now should look like this: [fib(0 to 100), 10]

push 0 15, means push the integer 15 to index 0. Your list now should look like this: [15, fib(0 to 100), 10]

push 0 150, means push the integer 150 to index 0. Your list now should look like this: [150, 15, fib(0 to 100), 10]

pop 1, means remove the index 1. Your list now should look like this: [150, fib(0 to 100), 10]

filter higher 20, means filter everything in your list only to remain every number that is higher than 20. Your list now should look like this: [150, filter(fib_gen(0 to 100, higher than 20))]

fib 0 15, means push the first 15 Fibonacci generator to index 0. Your list now should look like this: [fib(0 to 15), 150, filter(fib(0 to 100, higher than 20))]

filter lower 100, means filter everything in your list only to remain every number that is lower than 100. Your list now should look like this: [filter(fib(0 to 15), lower than 100), filter(filter(fib(0 to 100, higher than 20)), lower than 100)]

pop 0, means remove the index 0. Your list now should look like this: [filter(filter(fib(0 to 100, higher than 20)), lower than 100)]

push 0 100, means push the integer 100 to index 0. Your list now should look like this: [100, filter(filter(fib(0 to 100, higher than 20)), lower than 100)]

Therefore, your first 10 numbers should be 100, 34, 55, 89

Input

The first line is 2 integers, N and K, where:

  • N = the number of commands
  • K = the number of numbers you have to output. (generator is not a number)

The next N line will be either of these commands, in this format:

  • fib index limit
  • push index value
  • pop index
  • filter comparison value

Constraints

  • comparison is either lower | higher
  • index is never out of bounds.
  • limit <= 5000
  • value is an integer

​>Note: lower is < and higher is > (not equal to)

Output

Output K number from the list starting from the front.

If K > len(list), output len(list) numbers.

Sample Input  Download

Sample Output  Download

Tags




Discuss