Last active
December 17, 2015 21:19
-
-
Save mutaku/5673767 to your computer and use it in GitHub Desktop.
Ural Championship 2013 Problem Set
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Problem A. Graphics Settings | |
| ''' | |
| Example input: | |
| 1 | |
| vsync 10 | |
| 640 480 10000000 | |
| 2 | |
| Off vsync | |
| Resolution 320 240 | |
| ''' | |
| def calculate_fps(w, h, clock, impact_factor): | |
| # Calculate FPS based on the following equation: | |
| # equation: frame_rate = clock_rate / frame_cycles / impact_factor | |
| # frame_cycles is gpu cycles / frame | |
| # clock_rate is gpy cycles / sec | |
| # impact_factor is unitless | |
| return (clock / float(w * h) / impact_factor) | |
| def fps_grade(fps_list): | |
| # Convert list of FPS vals to ratings | |
| return [ | |
| 'Slideshow' if fps < 10 else | |
| 'Perfect' if fps > 60 else | |
| 'So-so' | |
| for fps in fps_list] | |
| def data_from_lines(lines): | |
| # Split a range of lines into spaced components | |
| return [data.next().split() for _ in range(lines)] | |
| def generator(data): | |
| # Parse input file and cluster data by case | |
| # Feed clustered data to our algorithm | |
| results = list() | |
| # Parse options as [option_name, impact_factor] | |
| number_options = data.next() | |
| options = {k: v for (k, v) in data_from_lines(number_options)) | |
| # Generate running impact_factor | |
| impact_factor = sum([x[1] for x in options]) | |
| # Grab the initial resolution and clock rate | |
| w, h, clock = [int(x) for x in data.next().split()] | |
| # Parse changes as [new_state, option_name] or [resolution, w, h] | |
| # note that option changes are len(change) == 2 versus resolution | |
| # which is len(change) == 3 | |
| number_changes = int(data.next()) | |
| changes = data_from_lines(number_changes) | |
| # Calculate FPS | |
| # do this for initial | |
| results.append(calc_fps(w, h, clock, impact_factor)) | |
| # and then iterate through changes | |
| for change in changes: | |
| # handle a resolution change as [Resolution, w, h] | |
| if len(change) == 3: | |
| w, h = change[1:] | |
| # handle option change as [Off/On, Option] | |
| else: | |
| # get the impact_factor change | |
| perturbation = options[change[1]] | |
| if change[0] == 'Off': | |
| impact_factor -= perturbation | |
| else change[0] == 'On': | |
| impact_factor += perturbation | |
| results.append(calc_fps(w, h, clock, impact_factor)) | |
| # Convert numerical FPS to categorical classifications | |
| return fps_grade(results) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Link to problem set as PDF: https://docs.google.com/file/d/0B2kGPJ31ig1-bXgwT1djZk1ZdjQ/edit?usp=sharing