Skip to content

Instantly share code, notes, and snippets.

View Vicfred's full-sized avatar
:octocat:
I like mathemagic and computering

Vicfred Vicfred

:octocat:
I like mathemagic and computering
View GitHub Profile
@Vicfred
Vicfred / color.cpp
Last active August 29, 2015 13:56
Codechef - Colored Array
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <functional>
#define MAXN 1001
using namespace std;
@Vicfred
Vicfred / colorDP.cpp
Created February 24, 2014 23:51
Codechef - Colored Array
//http://www.codechef.com/problems/COLARR/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define MAXN 1005
using namespace std;
@Vicfred
Vicfred / marble.cpp
Last active August 29, 2015 13:56
Codechef - Funny Marbles
//http://www.codechef.com/problems/MARBLEGF/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
@Vicfred
Vicfred / lattice.cpp
Created March 13, 2014 16:24
Visible Lattice Points
//https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1572
#include <cstdio>
#include <cstdlib>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a%b); }
int main() {
@Vicfred
Vicfred / virtualfriend.cpp
Last active August 29, 2015 13:57
Virtual Friends
//http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2498
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
@Vicfred
Vicfred / dmaya.cpp
Last active August 29, 2015 14:13
IOI06 The Deciphering of Mayan Writing
//http://www.spoj.com/OI/problems/DMAYA/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
using namespace std;
int main () {
int g, sz;
@Vicfred
Vicfred / coins.cpp
Last active February 24, 2020 14:31
how many flips until n heads
// How many times do you have to flip a coin
// to get n heads?
#include <random>
#include <iostream>
int main() {
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(0,1);
@Vicfred
Vicfred / Quirks of C.md
Created February 1, 2019 00:21 — forked from fay59/Quirks of C.md
Quirks of C

Here's a list of mildly interesting things about the C language that I learned mostly by consuming Clang's ASTs. Although surprises are getting sparser, I might continue to update this document over time.

There are many more mildly interesting features of C++, but the language is literally known for being weird, whereas C is usually considered smaller and simpler, so this is (almost) only about C.

1. Combined type and variable/field declaration, inside a struct scope [https://godbolt.org/g/Rh94Go]

struct foo {
   struct bar {
 int x;
@Vicfred
Vicfred / random_pi.cpp
Last active March 19, 2021 22:34
pi approximation using random points in a circle
// approximate pi using random points in a square
// compile using: g++ pi.cpp -o pi
// and then run using: ./pi
#include <iostream>
#include <iomanip>
#include <random>
#include <cmath>
#include <chrono>
using namespace std;
@Vicfred
Vicfred / sieve.cpp
Last active August 16, 2019 05:13
Sieves in C++
#include <vector>
#include <bitset>
#include <iostream>
#include <chrono>
using namespace std;
const int MAXN = 10000000;
bitset<MAXN+2> bs;