Advanced Eclipse Competition Tips and Techniques

advertisement
Advanced Eclipse
Competition Tips and Techniques
• Go to Window->Preferences->Java->Code Style->
Code Templates->Comments->Types and add a
line
• Go to Window->Preferences->Java->Editor->
Templates
• Example: sysout to sop
• Custom example: header comments
• Generating source
• Create a new class
• New comments appear
• Generate header comments
• Generate the rest of the file
Ctrl 1
Ctrl Shift M
Ctrl Shift F
Ctrl Shift O
Ctrl /
Ctrl \
Ctrl Shift Space
Ctrl
Ctrl I
Shift Space
Quick fix (works even when there are no
errors
Add import
Reformat
Organize Imports
Comment
UnComment
Parameter hints
Hyperlink identifier
Correct indentation
Incremental content assist
•
•
•
•
•
Stands for Java archive
What java itself uses
Right mouse click on the project
Export->Java runnable jar
Looking at contents of jar file
• jar tvf Test.jar
• Executing a .jar file
• java –jar Test.jar
• Java applets can run in a Web browser using a
Java Virtual Machine (JVM), or in Sun's
AppletViewer, a stand-alone tool for testing
applets.
• Since Java's byte code is cross platform Java
applets can be executed by browsers for many
platforms. The JVM for each platform
translates.
}
• init() - called exactly once in an applet's life, when the
applet is first loaded. It's normally used to read PARAM
tags, start downloading any other images or media files
you need, and set up the user interface.
• start() - called at least once in an applet's life, when
the applet is started or restarted. In some cases it
may be called more than once. Many applets you
write will not have explicit start()methods and will
merely inherit one from their superclass. A start()
method is often used to start any threads the applet
will need while it runs.
• stop() - called at least once in an applet's life, when
the browser leaves the page in which the applet is
embedded. The applet's start() method will be called if
at some later point the browser returns to the page
containing the applet. In some cases the stop() method
may be called multiple times in an applet's life. Many
applets you write will not have explicit stop()methods
and will merely inherit one from their superclass.
• destroy() - called exactly once in an applet's life, just
before the browser unloads the applet. This method is
generally used to perform any final clean-up.
}
import java.awt.*;
import java.applet.Applet;
public class Welcome extends Applet
{
public void paint(Graphics g) {
int inset, rectWidth, rectHeight;
g.setColor(Color.pink);
g.fillRect(0,0,300,160);
g.setColor(Color.green);
inset = 0; rectWidth = 299; rectHeight = 159;
while (rectWidth >= 0 && rectHeight >= 0) {
g.drawRect(inset, inset, rectWidth, rectHeight);
I
nset += 15;
rectWidth -= 30;
rectHeight -= 30;
}
}
}
• StudentTester in Debug Project: Run  Debug
• Set breakpoint (on line number, right mouse
click, and Toggle Breakpoint)
• Run to line (Green play button)
• Hover over code
• Look at value of variable
• Change a value
• Warning: if you do not have java api source, of
course the debugger will not find it.
• Now let’s add some breakpoints to Students
• There is lots more good stuff in the Debugger-EXPLORE!


No matter what your performance is in a
contest, do not be disappointed.
Success in programming contests is affected
by factors other than skill
◦ adrenaline
◦ luck
◦ the problem set of the contest




A good team is essential to succeeding in a
programming contest
A good programming team must have the
ability to find an appropriate algorithm the
set.
Teams should be able to code algorithms into
a working program
Teams should be able to work well together

When training, make sure that every member of
the team is proficient in the basics:
◦
◦
◦
◦




Use if the IDE
Writing methods
Debugging
Compiling
An effective team will have members with
specialties
All team members should know each other’s
strengths and weaknesses and communicate
effectively with each other.
Deciding which member should solve each
problem.
Always think about the welfare of the team

The problems presented in programming
contests often fall into one of five categories:
◦ Searches - breadth-first search or depth-first
search
◦ Graphs - shortest path
◦ Geometry -General and computational geometry
◦ Dynamic programming - solving complex problems
by breaking them down into simpler sub-problems
◦ Trivial, and non-standard - problems that can be
solved without much knowledge of algorithms




During the contest make sure you read the entire
problem and categorize its parts into easy,
medium and hard.
Tackling the easiest parts first is usually a good
idea.
Do not assume because contestants are leaving
that they completed the problem.
You do not want to waste too much of your time
with a single part of the problem.
◦ Try not to let the computer sit idle.
◦ Keep the computer active is to use the chair in front of
the computer only for typing and not for thinking.
◦ You can also save computer time by writing your
program on paper, analyzing it, and THEN using the
computer.





Test the Program with Multiple Datasets
Sample input and output is usually provided
for the problem, but you need to test
additional data
Inexperienced contestants get excited when
one of their programs matches the sample
output for the corresponding input
However, problem may not be correctly
solved.
Think of the boundaries and “quirky” cases



Judges often omit information.
Judges always try to make easy problem
statements longer to make them look harder
and the difficult problem statements shorter
to make them look easy
Professional State Farm Software
Development Experts write and judge the
problems.

Avoid Recursion
Recursion takes more time
Recursive programs crash more frequently
for some people, recursion is harder to debug
Recursion should not be discounted completely, as some
problems are very easy to solve recursively (DFS,
backtracking), and there are some people who like to
think recursively
◦ it is a bad habit to solve problems recursively if they can
be easily solved iteratively
◦
◦
◦
◦


In live programming contests, there is no point in
writing classic code, or code that is compact but
often hard to understand and debug
In programming contests, classic code serves
only to illustrate the brilliance of the programmer



Make sure all necessary classes are included
Programs sent to the online judge should be
in plain text format
Mysterious Characters
◦ If you receive a Compile error message and cannot
discover the cause, check if your editor is adding
extra symbols to your code



Many people believe that the best
programmer is the one with greatest
knowledge of algorithms. However, problemsolving skills contribute to programming
success as much as raw knowledge of
algorithms. Do not lose your nerve during a
contest, and always try to perform your best!
Try to get a good night’s sleep
We are PROUD of you!



http://programmingteam.cc.gatech.edu/SER2
012/
http://www.ccscse.org/progcontest.php?year
=26th
Shahriar Manzoor at
http://xrds.acm.org/article.cfm?aid=969641
Download