Negationist's blog

By Negationist, history, 19 months ago, In English

I'm currently going through the geo section on usaco and whenever I learn something new I just stick it in my Point template. I worry this may just make my point template egregiously long though as I go on. On the other hand, I don't want to be boned in a contest or something if my Point struct is here, convex hull is there, etc. What is the norm? What do you guys do?

  • Vote: I like it
  • +7
  • Vote: I do not like it

| Write comment?
»
19 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Wherever I have the main submission code, I like to create another folder that just has the stuff that is commonly copy-pasted. But because I mostly use the same computer, I only had to create such folders twice. And ever since my PCs upgraded themselves to windows $$$11$$$, they have been linked, basically I can edit one file from one computer and save it, and it will change on my other computer in real time. I can't help but feel like they're removing local storage for some greater purpose. Anyway, just name the files something you will remember like point.cpp and convexhull.cpp and if you use sublime text, it automatically opens the folder your file is in when you press open file, so you can quickly access anything.

»
19 months ago, hide # |
 
Vote: I like it +13 Vote: I do not like it

This reduces many lines

auto operator<=>(const point_t &p) const = default;

»
19 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Most IDEs have a code snippet feature that lets you easily insert code into your program. You just type the name of the snippet and the code is automatically inserted for you. I use these and they are extremely quick and useful. Here's what I recommend:

Have one small Point struct with just x and y. Use functions that take the Point struct as an argument. This way, you only use the code that you need to while also having easy access to all of your code.

Example:

struct Point;
struct Line;
vector<Point> convex_hull(vector<Point> points);
Point reflect(Point p, Line l);
// ...