5 ms·
Libraries in C++ for ACM
- neo7 16y agoHi, Can you explain what is all this?
- l0nwlf 16y agoThese are standard data structures and algorithms coded in C++. Pretty useful for programming competitions.
- sohilgupta 16y agoAwesome work!! Great set of libraries for competitions...
- Abednego 16y agoThanks. I'm glad you find them useful.
- oostevo 16y agoSomebody correct me if I'm wrong, but as far as I can remember from when I was doing ICPC, I wasn't allowed to bring in anything in electronic format. I could, however, bring in printed materials. Have the rules changed? Or are these libraries just for practice problems?
- l0nwlf 16y agoYou can always bring codes in the form of printouts. And these libraries are mainly for practice problems on ACM UVA Online Judge.
- lzm 16y agoAny other ICPC world finalists on Hacker News? Stockholm '09 here.
- rfurmani 16y agoPrague and Shanghai (Igor, the author, was also at Shanghai)
- swah 16y agoIs this beautiful or ugly to a "C/C++" programmer? template< class T, int MAXN > int BST< T, MAXN >::count( const T &x ) const { return find( x ) ? 1 : 0; }
- boris 16y agoThe code is fairly idiomatic C++, except maybe for the name of the class template (BST); hardly anybody names their classes in all capital letters (note that naming template parameters [T, MAXN in this case] in all capitals is quite common). Other than that, maybe the spaces after ( and < as well as before ) and > are a matter of taste.
- dkersten 16y agohardly anybody names their classes in all capital letters (note that naming template parameters [T, MAXN in this case] in all capitals is quite common) Agreed. My code and a lot of C++ code I've seen uses uppercase for template parameters, but never for classes/structs or methods. (Actually, I generally follow the Java conventions for capitalization of class names, method/function names, constants etc, though I use underscores in local variables.)
- marshray 16y agoI don't know. What does find(x) do? (Other than return something which evaluates in boolean context unless the template function is skipped for instantiation due to SFINAE and not modify x or *this unless a C-style or const_cast is used somewhere).
- lallysingh 16y agoI don't think many C++ programmers think that much in the language counts as beautiful.
- scott_s 16y agoAside from the author's habit of putting spaces after angle brackets and parenthesis, it's standard looking code. It's pretty busy looking, but then again, there's a lot going on: - A generic type T is introduced into the scope of this member function. - The template parameter MAXN is a compile time constant that is part of the type of the data structure. - This is the count member function of the class BST, which is paramaterized on the types mentioned above. - count does not modify any instance variables of BST. - The parameter x is passed by constant reference. - count's return type is int. - The actual value returned is 1 if find(x) evaluates to true, and 0 if find(x) evaluates to false. You learn to look for what you need to know when reading the code. Also, it's also worth noting that this code is most decidedly C++ only. C programmers may hate this code.
- georgecmu 16y agoAre you allowed to use STL/BOOST in the competition?
- ideamonk 16y agoSTL is allowed in all the competitions including TC, ICPC, SPOJ, etc BOOST is not allowed in any.
- zem 16y agowhy would boost not be allowed but this guy's libraries be?
- ideamonk 16y agoThis guy's library can be contained within your submission source code, so it can be used. BOOST in any case won't be installed or would be kept out of execution sandbox, on the judge server, so BOOST won't be usable. STL will be present along the gcc version they use by default. S = Standard in STL :)
- bajsejohannes 16y agoYou can anything you like in paper form to the competition, so you could print this guys thing and type it in at the competition. You could certainly do the same for boost (but you'd be limited to the very small subset that is easy to type in). At least, this is how it was seven years ago.
- dkersten 16y agoThe International Olympiad in Informatics also allows STL, but no other libraries.
- Abednego 16y agoGoogle Code Jam allows BOOST and all other freely available languages and libraries.