Created
February 3, 2011 01:30
-
-
Save Surgo/808879 to your computer and use it in GitHub Desktop.
SRM488 - div2 - level one
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
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
"""SRM488 - div2 - level one | |
John and Brus are bored. They have n+m common friends. | |
The first n of them are bored and other m are not. | |
John chooses the j-th (1-based) friend for a talk. | |
If the friend is not bored, he becomes bored after the talk. | |
Brus does the same with the b-th (1-based) friend. | |
Note that John and Brus can't choose the same friend. | |
You have to find the number of bored friends after the talks. | |
Definition: | |
Class: TheBoredomDivTwo | |
Method: find | |
Parameters: int, int, int, int | |
Returns: int | |
Method signature: int find(int n, int m, int j, int b) | |
""" | |
class TheBoredomDivTwo(object): | |
"""The Bored om Div Two | |
Constraints: | |
- n will be between 1 and 47, inclusive. | |
- m will be between 1 and 47, inclusive. | |
- j will be between 1 and n+m, inclusive. | |
- b will be between 1 and n+m, inclusive. | |
- j and b will be different. | |
>>> bored = TheBoredomDivTwo() | |
>>> print bored.find(1, 1, 1, 2) | |
2 | |
>>> print bored.find(2, 1, 1, 2) | |
2 | |
>>> print bored.find(1, 2, 3, 2) | |
3 | |
>>> print bored.find(4, 7, 7, 4) | |
5 | |
""" | |
def __init__(self): | |
pass | |
def find(self, n, m, j, b): | |
return n + (j > n) + (b > n) | |
if __name__ == '__main__': | |
import doctest | |
doctest.testmod() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment