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

Username:   Password: 
 RegisterRegister   
 CCC 2004 Answers to J5
Index -> Contests
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
kythoon




PostPosted: Mon Mar 01, 2004 2:06 pm   Post subject: CCC 2004 Answers to J5

Hey, wonder if any of you remember me?


But that is beside the point, does anyone have the answer to the J5 for this year?

Thanks
Sponsor
Sponsor
Sponsor
sponsor
zylum




PostPosted: Mon Mar 01, 2004 3:53 pm   Post subject: (No subject)

i did the denior one but can you post the question? i want to see if i could solve it...
kythoon




PostPosted: Mon Mar 01, 2004 7:07 pm   Post subject: (No subject)

sorry, i dont have the question sheet any more, and it is not on the internet.

It was about factals though, it was just hard understanding was was being asked
Brightguy




PostPosted: Tue Mar 02, 2004 9:28 pm   Post subject: Re: CCC 2004 Answers to J5

I wrote the senior portion, but I decided to take a look at this question because there were a lot of people talking about it and nobody had posted a solution.

It sure was an interesting problem... It actually took me a while to understand what they meant. I think they could have worded it a lot better... Rolling Eyes

Anyway, I have a working solution, which I wrote in Visual Basic. In the attachment I'll include the basic source code which will load the data from a file (should be in same directory). As well, I'll include a compiled .exe where you can just input the variables into text boxes, and it'll even output a simple picture of the fractal. Very Happy

Sorry, but I didn't comment the source... if you have any questions you'll have to ask me. Basically, the main code is the Fractal procedure, which takes a line and splits it into five new smaller lines, each 1/3 of the original line's length.

Remember when testing inputs the width of the fractal should always be a power of 3 (27 and 81 work best).



J5 - 2004.zip
 Description:

Download
 Filename:  J5 - 2004.zip
 Filesize:  5.5 KB
 Downloaded:  423 Time(s)

zylum




PostPosted: Tue Mar 02, 2004 9:31 pm   Post subject: (No subject)

can someone please post the questoin for J5??? i dont have access to the junior questions and its not online...

-zylum
Brightguy




PostPosted: Tue Mar 02, 2004 9:48 pm   Post subject: Re: CCC 2004 Answers to J5

Problem J5: Fractals

A fractal is a geometric shape where the pattern of the whole shape is self-replicating at each subsection of the shape. A simple "block fractal" is shown below. At each stage of the fractal growth, every straight line in the fractal is divided into three parts. The first and last sections stay straight; the middle section contains a square "bump" which has the same height as the width of the middle section. (You will want to consider the four orientations of a line segment within the fractal. Depending upon which line segment is currently being generated, the bump may protrude up, down, left, or right.)

Write a program that will keep track of the integer points of the lines in a similar "block fractal" with its bottom left corner at (0,1). The program will accept three integers as input: the level of the fractal, the width of the fractal, and an x-coordinate. You may assume that the width of the fractal will be some power of three, and that it will be large enough so that every corner of the fractal will fall on an integer intersection in the Cartesian plane. The width will never be more than 81. The x-coordinate, x, will be in the range of 0 - width (inclusive). Your program should output the y-coordinate value(s), y, where the lines of the fractal intersect the point (x,y).

That's the main important stuff...
zylum




PostPosted: Tue Mar 02, 2004 10:03 pm   Post subject: (No subject)

thanks Wink
TheZsterBunny




PostPosted: Sat Mar 06, 2004 6:44 pm   Post subject: (No subject)

I was one of the people marking the CCCs at school, and I have a statistic for you:

of the 40 people writing the Junior CCC this year, one person got 3 marks on the fifth question by hard-coding the answers into the source.

Scary.

-bunny

-------edit-------

In Turing. sorry, forgot to say that.

-bunny
Sponsor
Sponsor
Sponsor
sponsor
bugzpodder




PostPosted: Mon Mar 08, 2004 9:46 am   Post subject: (No subject)

code:
#include<iostream>
#include<vector>

using namespace std;

struct Point{
public:
        Point (int _x=0, int _y=0){x=_x;y=_y;}
        int x,y;
        bool operator <(Point p){
                return (x<p.x||(x==p.x && y<p.y));
        }
       
};

struct Segment{
public:
        Segment(Point _p1=Point(0,0),Point _p2=Point(0,0),int _dir=1){if (_p2<_p1) swap(_p1,_p2);p1=_p1;p2=_p2;dir=_dir;}
        int d(){if(p1.y==p2.y) return 1; return -1;}
        int len(){ if (d()==1) return p2.x-p1.x; return p2.y-p1.y;}

       
        Point p1,p2;
        int dir;
};
bool ret[100];
int main(){

        int lvl,wid,x,i,ii;
        cin>>lvl>>wid>>x;
        vector<Segment> arr(1,Segment(Point(0,1),Point(wid,1),1));
        Segment s;
        Point p1,p2,p3,p4;

        for (ii=1;ii<=lvl;ii++){
               
                for (i=arr.size()-1;i>=0;i--){
                        s=arr[i];
                        arr.erase(arr.begin()+i,arr.begin()+i+1);
                        if (s.d()==1){
                                p1=Point(s.p1.x+s.len()/3,s.p1.y);
                                p2=Point(s.p1.x+s.len()/3,s.p1.y+s.dir*s.len()/3);
                                p3=Point(s.p1.x+2*s.len()/3,s.p1.y+s.dir*s.len()/3);
                                p4=Point(s.p1.x+2*s.len()/3,s.p1.y);

                        }
                        else{
                                p1=Point(s.p1.x,s.p1.y+s.len()/3);
                                p2=Point(s.p1.x+s.dir*s.len()/3,s.p1.y+s.len()/3);
                                p3=Point(s.p1.x+s.dir*s.len()/3,s.p1.y+2*s.len()/3);
                                p4=Point(s.p1.x,s.p1.y+2*s.len()/3);

                        }
                        arr.push_back(Segment(s.p1,p1,s.dir));
                        arr.push_back(Segment(p1,p2,-1));
                        arr.push_back(Segment(p2,p3,s.dir));
                        arr.push_back(Segment(p3,p4,1));
                        arr.push_back(Segment(p4,s.p2,s.dir));

                }


        }
        for (ii=0;ii<arr.size();ii++){
                if (arr[ii].p1.x==arr[ii].p2.x && arr[ii].p1.x==x)
                        for (i=arr[ii].p1.y;i<=arr[ii].p2.y;i++)
                                ret[i]=true;
                else if (arr[ii].p1.x<=x && x<=arr[ii].p2.x)
                        ret[arr[ii].p1.y]=true;
        }
        for (i=0;i<=81;i++)
                if (ret[i])
                        cout<<i<<" ";
        cout<<endl;

        return 0;
}
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  [ 9 Posts ]
Jump to:   


Style:  
Search: