Skip to content

Instantly share code, notes, and snippets.

View nathanPro's full-sized avatar

Nathan Proença nathanPro

  • None
  • São Paulo
View GitHub Profile
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int n, count, triangles;
unsigned long points[100003], temp, interval, sum, p2, p3;
#include <cstdio>
#include <map>
using namespace std;
int getCollatz(long a, map<long,int> &source)
{
if( source.find(a) == source.end() )
{
if(a%2 == 0)
@nathanPro
nathanPro / number.cpp
Created May 27, 2015 15:50
Why segfault
int divs[MAX];
void slowSieve(int n)
{
memset(divs, 0, sizeof divs);
for( int i = 2; i <= n; i++ )
if( divs[i] == 0 ) // Achei primo
{
divs[i] = -1; // Fix, pois vou contar o primo em si
// Percorro todas as potências desse primo
#include<bits/stdc++.h>
#define MAX 5000042
using namespace std;
int divs[MAX];
void slowSieve(int n)
{
for( int i = 0; i <= n; i++ )
divs[i] = 0;
#include<bits/stdc++.h>
using namespace std;
typedef int num;
typedef int cood;
typedef int point;
const int MP = 1002;
const double PI = (acos(-1.0));
const double eps = (1e-9);
cood x[MP], y[MP];
point anchor, in[MP], hull[MP];
@nathanPro
nathanPro / counting.rb
Created August 8, 2015 15:43
PD com combinações em ruby
$comb = Hash.new do |comb, n|
if n == 0
comb[n] = Hash.new(0)
comb[0][0] = 1;
else
comb[n] = Hash.new do |hash, k|
if k == 0
hash[k] = 1;
else
hash[k] = comb[n-1][k-1] + comb[n-1][k];
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
template<typename T> inline void _max(T& a, T b){ a = max(a,b); }
template<typename T> inline void _min(T& a, T b){ a = min(a,b); }
int main(){
}
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
template<typename T> inline void _max(T& a, T b){ a = max(a,b); }
template<typename T> inline void _min(T& a, T b){ a = min(a,b); }
const int N = 1e6+7;
int x[N], f[N], y[N], T[N][2];
int s[2], ts;
void split(int t, int k){
@nathanPro
nathanPro / knapsack.cpp
Last active July 26, 2016 04:47
Knapsack se aproveitando de C++11
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
const int N = (2e3) + 7;
int n, k, w[N], v[N];
int _S[N][N];
int& S(int i, int w) { return (w >= 0) ? _S[i][w] : _S[N-1][N-1]; }
int s(int i, int w) { return max({S(i+1,w), v[i] + S(i+1,w-::w[i])}); }
#include "bits/stdc++.h"
#define all(v) begin(v), end(v)
using namespace std;
using ll = int64_t;
const int N = 1e5 + 7;
int n;
int c[N];
vector<int> G[N];