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

Username:   Password: 
 RegisterRegister   
 does anyone have any solutions to this years contest?
Index -> Contests
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Paul




PostPosted: Tue May 11, 2004 11:29 am   Post subject: (No subject)

Bah... me fail english? thats unpossible...
Sponsor
Sponsor
Sponsor
sponsor
bugzpodder




PostPosted: Tue May 11, 2004 8:34 pm   Post subject: (No subject)

i've just being to stage two, and its is ****ing brutal!!
zylum




PostPosted: Sat Oct 02, 2004 2:52 pm   Post subject: (No subject)

i was thinging ahead to the next CCC and thought i'd solve last years S4:

java code follows:
code:
import java.io.*;
import java.util.*;

public class S4 {
        public static int[] ct = new int[3];
        public static int[] cp = new int[3];
       
        public static double findDist(String file) throws IOException {
                BufferedReader input = new BufferedReader (new FileReader (file));
                       
                int l = 0;
                double minDist;
                int[] orient = {1, 2, 3};

                String[] tok = input.readLine().split(" ");
                ct[0] = Integer.parseInt(tok[0]);
                ct[1] = Integer.parseInt(tok[1]);
                ct[2] = Integer.parseInt(tok[2]);
               
                tok = input.readLine().split(" ");
                cp[0] = Integer.parseInt(tok[0]);
                cp[1] = Integer.parseInt(tok[1]);
                cp[2] = Integer.parseInt(tok[2]);
               
                minDist = calcDist();
               
                do {
                        tok = input.readLine().split(" ");
                        int travDist = Integer.parseInt(tok[0]);
                       
                        for (int i = 0; i < travDist; i++) {
                                ct[Math.abs(orient[0])-1] += orient[0]/Math.abs(orient[0]);
                                if (calcDist() < minDist) minDist = calcDist();
                        }
                       
                        int temp;
                        if (tok[1].equals("L")) {
                                temp = orient[0];
                                orient[0] = orient[1];
                                orient[1] = -temp;
                        } else if (tok[1].equals("R")) {
                                temp = orient[0];
                                orient[0] = -orient[1];
                                orient[1] = temp;
                        } else if (tok[1].equals("U")) {
                                temp = orient[0];
                                orient[0] = orient[2];
                                orient[2] = -temp;
                        } else if (tok[1].equals("D")) {
                                temp = orient[0];
                                orient[0] = -orient[2];
                                orient[2] = temp;
                        }
                       
                } while (!tok[1].equals("E"));
               
                return (double) Math.round(minDist*100)/100;
        }
       
        public static double calcDist() {
                double dist = Math.pow(ct[0]-cp[0], 2) + Math.pow(ct[1]-cp[1], 2);
                return Math.sqrt(Math.pow(ct[2]-cp[2], 2) + dist);
        }
       
        public static void main (String[] args) throws IOException {
                System.out.println(findDist("s4.1.data"));
                System.out.println(findDist("s4.2.data"));
                System.out.println(findDist("s4.3.data"));
                System.out.println(findDist("s4.4.data"));
                System.out.println(findDist("s4.5.data"));
        }
}


-zylum
Display posts from previous:   
   Index -> Contests
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 18 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: