Skip to content

Commit

Permalink
add some from spoj br
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanCruz committed Oct 12, 2019
1 parent 6f1d084 commit 8a3d5a5
Show file tree
Hide file tree
Showing 7 changed files with 260 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ tmp
[0-9]*
i[0-9]*
![0-9]*.cpp
*.txt
47 changes: 47 additions & 0 deletions spoj-br/BAPOSTAS.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <bits/stdc++.h>

using namespace std;

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

#define MAX 10010

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;
int v[MAX];
int pd[MAX];
v[0] = 0;
pd[0] = 0;

while(scanf("%d", &n) != EOF && n) {
for (int i = 1; i <= n; i++) {
scanf("%d", v + i);
}

for (int i = 1; i <= n; i++) {
pd[i] = max(v[i], pd[i-1]+v[i]);
}

int max_pd = *max_element(pd, pd + n + 1);

if (max_pd > 0) {
printf("The maximum winning streak is %d.\n", max_pd);
} else {
printf("Losing streak.\n");
}
}

return 0;
}

38 changes: 38 additions & 0 deletions spoj-br/BIT.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <bits/stdc++.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);

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

int v;
int t = 0;

int notas[] = {50, 10, 5, 1};
int cedulas[4];

while (scanf("%d", &v) != EOF && v != 0) {
for (int i = 0; i < 4; i++) {
cedulas[i] = v / notas[i];
v -= notas[i] * cedulas[i];
}

printf("Teste %d\n", ++t);
printf("%d %d %d %d\n", cedulas[0], cedulas[1], cedulas[2], cedulas[3]);
}


return 0;
}

56 changes: 56 additions & 0 deletions spoj-br/CORMENMG.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <bits/stdc++.h>

using namespace std;

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

#define MAX 6000

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

struct pd_struct {
long long with, without;
};

int char_to_int(char c) {
return c - '0';
}

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

char s[MAX];
pd_struct pd[MAX];

int i;
while (true) {
scanf("%s", s);
if(s[0] == '0') break;

pd[0].with = 0;
pd[0].without = 1;

for (i = 1; s[i] != '\0'; i++) {
if (s[i-1] == '1' || (s[i-1] == '2' && s[i] <= '6'))
pd[i].with = pd[i-1].without;
else pd[i].with = 0;

if (s[i] == '0')
pd[i].without = 0;
else
pd[i].without = pd[i-1].with + pd[i-1].without;
}

printf("%lld\n", pd[i-1].with + pd[i-1].without);
}

return 0;
}

52 changes: 52 additions & 0 deletions spoj-br/DESCULPA.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <bits/stdc++.h>

using namespace std;

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

#define MAX 60
#define MAX_C 1002

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

int size[MAX];
int qtt[MAX];
long long pd[MAX][MAX_C];
int f;

long long calc(int n, int i) {
if (i >= f) return 0;
if (pd[i][n] != -1) return pd[i][n];

pd[i][n] = max(n - size[i] >= 0 ? qtt[i] + calc(n-size[i], i+1) : 0, calc(n, i+1));

return pd[i][n];
}

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

int n;
long long t = 0;
while(scanf("%d %d", &n, &f) && (n || f)) {
for (int i = 0; i < f; i++) {
for (int j = 0; j <= n; j++) {
pd[i][j] = -1;
}

scanf("%d %d", size+i, qtt+i);
}

printf("Teste %lld\n%lld\n\n", ++t, calc(n, 0));
}

return 0;
}

1 change: 1 addition & 0 deletions spoj-br/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://br.spoj.com/problems/{{problem_id}}/
65 changes: 65 additions & 0 deletions spoj-br/TESOURO2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include <bits/stdc++.h>

using namespace std;

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

#define MAX 1010

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

int pd[MAX];
int treasure[MAX];
list<int> parents[MAX];
int n;
int qt;
int to;

int calc_pd(int i) {
if (pd[i] == -1) {
int max_treasure = 0;

for(list<int>::iterator it = parents[i].begin(); it != parents[i].end(); it++) {
max_treasure = max(max_treasure, calc_pd(*it));
}

pd[i] = treasure[i] + max_treasure;
}

return pd[i];
}

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

while (scanf("%d", &n) != EOF && n) {
for (int i = 1; i <= n; i++) {
parents[i].clear();
}

for (int i = 1; i <= n; i++) {
pd[i] = -1;
scanf("%d %d", treasure+i, &qt);

for (int j = 0; j < qt; j++) {
scanf("%d", &to);
parents[to].push_back(i);
}
}

for (int i = 1; i <= n; i++)
calc_pd(i);

printf("%d\n", *max_element(pd+1, pd+n+1));
}

return 0;
}

0 comments on commit 8a3d5a5

Please sign in to comment.