Skip to content

Instantly share code, notes, and snippets.

View rep-movsd's full-sized avatar

Vivek rep-movsd

View GitHub Profile
procedure TForm1.DrawCircle3(cx, cy, r: Integer);
var
angle, angleInc : Extended;
i : integer;
x, y, sina, sinb, cosa, cosb, sinab, cosab : Extended;
begin
PaintBox1.Canvas.MoveTo(cx + r, cy);
angleinc := 360 / r;
sinb := Sin(angleinc / (180.0 / 3.14159));
@rep-movsd
rep-movsd / topcoder.template.cpp
Last active May 16, 2016 18:44
Topcoder template
#include <bits/stdc++.h>
#define vec vector
#define vint vector<int>
#define vstr vector<string>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define st string
@rep-movsd
rep-movsd / naive_tokenizer.cpp
Created May 16, 2016 19:08
Naive string tokenizer
vector<string> split(string s)
{
vector<string> sRet;
size_t i = 0;
do
{
string sWord;
@rep-movsd
rep-movsd / better_tokenizer.cpp
Last active May 16, 2016 19:12
A better tokenizer
vector<string> split2(string s)
{
vector<string> sRet;
istringstream iss(s);
string sWord;
while(iss >> sWord)
sRet.push_back(sWord);
@rep-movsd
rep-movsd / best_tokenizer.cpp
Created May 16, 2016 19:17
stream iterator based tokenizer
vector<string> split3(string s)
{
istringstream iss(s);
istream_iterator<string> begi(iss), endi;
return vector<string>(begi, endi);
}
@rep-movsd
rep-movsd / one_line_tokenizer.cpp
Last active May 16, 2016 19:33
One liner tokenizer (wont work)
vector<int> v(istream_iterator<int>(istringstream(s)), istream_iterator<int>());
@rep-movsd
rep-movsd / split.cpp
Last active May 16, 2016 20:06
Generic splitter
vector<string> split(const string& s, string seps=" ")
{
vector<string> ret;
for(auto ps = &s[0], pd = ps, pe = ps + int(s.size()); ps < pe; ps = pd + 1)
{
ret.emplace_back(string(ps, pd = find_first_of(ps, pe, begin(seps), end(seps))));
}
return ret;
}
@rep-movsd
rep-movsd / compact_split.cpp
Last active May 16, 2016 19:58
Compact split()
vstr split(cstref s, st seps=" ")
{
vstr ret;
for(auto ps = pbeg(s), pd = ps, pe = ps + sz(s); ps < pe; ps = pd + 1)
ret.eb(st(ps, pd = find_first_of(ps, pe, all(seps))));
return ret;
}
const int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int days_acc[13] = {0};
partial_sum(days, days+12, days_acc+1);
int date2day(int m, int d)
{
return days_acc[m] + d;
}
@rep-movsd
rep-movsd / Birds.cpp
Created May 16, 2016 21:17
Topcoder Birds (CC 2002 REG Semi 500 pointer)
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <functional>
#include <set>
#include <numeric>