Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 ECOO 2013 Round 1 Solutions
Index -> Contests
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

How Difficult Was This Question Set?
(No ending time set)
1 - Very Easy
42%
 42%  [ 3 ]
2 - Somewhat Easy
42%
 42%  [ 3 ]
3 - Neither Easy nor Difficult
0%
 0%  [ 0 ]
4 - Somewhat Difficult
14%
 14%  [ 1 ]
5 - Very Difficult
0%
 0%  [ 0 ]
Total Votes : 7

Author Message
SamScott




PostPosted: Thu Apr 04, 2013 6:52 am   Post subject: ECOO 2013 Round 1 Solutions

Hi Everyone,

The ECOO Computing Competition Round 1 is over. Attached are the questions, data files, solutions, and notes. Please use this thread to discuss any aspect of the competition. If you have alternate solutions or solution ideas please post or discuss here.

Sam Scott
Sheridan College



ECOO 2013 Round 1 - Solutions.zip
 Description:

Download
 Filename:  ECOO 2013 Round 1 - Solutions.zip
 Filesize:  314.4 KB
 Downloaded:  666 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
ishidon




PostPosted: Thu Apr 04, 2013 3:21 pm   Post subject: Re: ECOO 2013 Round 1 Solutions

I solved #4 rather simply by just trying every permutation of the coupons.
Here is my code in Python 2.6.
Solved DATA41.txt in around 16 seconds on my computer and DATA42.txt in around 0.6 seconds.
Unfortunately it was after the contest -_-
code:

from itertools import permutations
from copy import deepcopy

def eva(xx, y):
    x = deepcopy(xx)
    for i, v in enumerate(y):
        if v != "BOGO":
            if v == "$5":
                x[i] = max(x[i]-5, 0)
            elif v == "$10":
                x[i] = max(x[i]-10, 0)
            elif v == "$50":
                x[i] = max(x[i]-50, 0)   
            elif v == "10%":
                x[i] *= 0.9
            elif v == "20%":
                x[i] *= 0.8
               
        elif v == "BOGO":
            temp = y.index("!")
            maxv = max(x[i], x[temp])
            if maxv == x[i]:
                x[temp] = 0
            else:
                x[i] = 0
        if v != "TAX":
            x[i] *= 1.13
           
    for i, v in enumerate(x):
        x[i] = round(v, 2)
    return sum(x)

infile = open("DATA41.TXT")
nums = []
keys = []
coupons = [] 
testcases = []
for i in infile:
    i = i.strip()
    if "." in i:
        nums.append(float(i))
    elif "B" in i or "%" in i or "$" in i or "T" in i:
        coupons.append(i)
    else:
        keys.append(int(i))
        if len(keys) == 3:
            testcases.append([nums, coupons, keys[:-1]])
            nums = []
            coupons = []
            keys = [keys[-1]]
testcases.append([nums, coupons, keys[:-1]])
for i in range(5):
    nums = testcases[i][0]
    coupons = testcases[i][1]
    keys = testcases[i][2]
    while coupons.count("BOGO") > 2:
        coupons.remove("BOGO")
       
    if coupons.count("BOGO") == 1:
        coupons.append("BOGO")
    while len(coupons) < len(nums):
        coupons.append("NOTHING")
    lnum = 100000
    for i in set(permutations(coupons, keys[0])):
        if (i.count("BOGO") == 0 or i.count("BOGO") == 2):
            if "BOGO" in i:
                temp = i.index("BOGO")
                ii = []
                c = 0
                for blah in i:
                    if blah == "BOGO" and c == 0:
                        c += 1
                        ii.append("BOGO")
                       
                    elif blah == "BOGO" and c != 0:
                        ii.append("!")
                    else:
                        ii.append(blah)
                num = eva(nums, ii)
            else:
                num = eva(nums, i)
            if num < lnum:
                lnum = num       
    print "The best price is $%.2f" %lnum
crossley7




PostPosted: Thu Apr 04, 2013 7:21 pm   Post subject: RE:ECOO 2013 Round 1 Solutions

Can't write this anymore since I'm in Uni now but there questions look decent. Q4 might be a little trickier than in past years but I think for some regions that is much needed.

Overall though looks like a good balanced contest. Though maybe a few more types of questions would help. Seems a bunch of these were simulation/ad-hoc. A geometry or graph search problem would be helpful to balance it out
Display posts from previous:   
   Index -> Contests
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: