Блог пользователя Negationist

Автор Negationist, история, 19 месяцев назад, По-английски

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?

  • Проголосовать: нравится
  • +7
  • Проголосовать: не нравится

»
19 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится +13 Проголосовать: не нравится

This reduces many lines

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

»
19 месяцев назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

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);
// ...