Skip to content

Commit

Permalink
aaaa
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanCruz committed Oct 11, 2019
1 parent e5e08ef commit 6f1d084
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 0 deletions.
49 changes: 49 additions & 0 deletions project-euler/14.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <iostream>
#include <math.h>

using namespace std;

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second

#define MAX 1000000

typedef long long ll;
typedef pair<int, int> ii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);

int n_collatz(long long x) {
int c = 1;

while (x != 1) {
if (x % 2) x = 3*x + 1;
else x /= 2;

c++;
}

return c;
}

int main (void) {
ios_base::sync_with_stdio(false);

int max_n = 0;
int max_i = -1;
for (int i = 1; i <= MAX; i++) {
int n = n_collatz(i);
if (n > max_n) {
max_n = n;
max_i = i;
}
}

cout << max_i << "\n";

return 0;
}

43 changes: 43 additions & 0 deletions project-euler/15.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <iostream>
#include <math.h>

using namespace std;

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second

typedef long long ll;
typedef pair<int, int> ii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);

long long binomial(int x) {
ll r = 1;

for (int i = 2*x-1; i > x; i-=2) {
r *= i;
}
for (int i = 2*x; i > x; i-=2) {
r *= 2;
}
for (int i = 2; i <= x / 2; i++){
r /= i;
}

cout << r << endl;

return r;
}

int main (void) {
ios_base::sync_with_stdio(false);

for (int n = 1; n <= 20; n++)
cout << binomial(n) << "\n";

return 0;
}

51 changes: 51 additions & 0 deletions project-euler/16.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <iostream>
#include <math.h>

using namespace std;

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second

#define MAX 500

typedef long long ll;
typedef pair<int, int> ii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);

int main (void) {
ios_base::sync_with_stdio(false);

int n[MAX];
memset(n, 0, sizeof(int)*MAX);

n[0] = 1;
int p = 1000;
int max_j = 1;

for(int i = 1; i <= p; i++) {
for (int j = 0; j < max_j; j++) {
n[j] *= 2;
}

for (int j = 0; j < max_j; j++) {
n[j+1] += n[j] / 10;
n[j] %= 10;
}
if(n[max_j] > 0) max_j++;
}

int sum = 0;
for(int i = 0; i < max_j; i++) {
cout << n[i] << " ";
sum += n[i];
}

cout << sum << "\n";

return 0;
}

50 changes: 50 additions & 0 deletions project-euler/18.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <iostream>
#include <math.h>

using namespace std;

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second

#define MAX 50000

typedef long long ll;
typedef pair<int, int> ii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);

int line(int n) {
return ( n * (n - 1 ) ) / 2;
}

int main (void) {
ios_base::sync_with_stdio(false);

int t[MAX];
memset(t, 0, sizeof(int)*MAX);

int j = 0;
int l = 1;
while (scanf("%d", t + line(l) + j) != EOF) {
j++;

if (j == l) {
l++;
j = 0;
}
}

for (int i = l-2; i > 0; i--) {
for (j = 0; j < i; j++) {
t[line(i)+j] += max(t[line(i+1)+j],t[line(i+1)+j+1]);
}
}

cout << t[0] << "\n";

return 0;
}

0 comments on commit 6f1d084

Please sign in to comment.