Skip to content

Commit

Permalink
as
Browse files Browse the repository at this point in the history
  • Loading branch information
aajjbb committed Aug 22, 2013
1 parent fbb0019 commit ad9d9e6
Show file tree
Hide file tree
Showing 13 changed files with 324 additions and 61 deletions.
Binary file added LiveArchive/LongestConstantGene
Binary file not shown.
92 changes: 92 additions & 0 deletions LiveArchive/LongestConstantGene.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <memory>
#include <iomanip>
#include <numeric>
#include <functional>
#include <new>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <climits>
#include <cctype>
#include <ctime>

#define REP(i, n) for(int (i) = 0; i < n; i++)
#define FOR(i, a, n) for(int (i) = a; i < n; i++)
#define FORR(i, a, n) for(int (i) = a; i <= n; i++)
#define for_each(q, s) for(typeof(s.begin()) q=s.begin(); q!=s.end(); q++)
#define sz(n) n.size()
#define pb(n) push_back(n)
#define all(n) n.begin(), n.end()

template<typename T> T gcd(T a, T b) {
if(!b) return a;
return gcd(b, a % b);
}
template<typename T> T lcm(T a, T b) {
return a * b / gcd(a, b);
}

template<typename T> void chmin(T& a, T b) { a = (a > b) ? b : a; }
template<typename T> void chmax(T& a, T b) { a = (a < b) ? b : a; }
int in() { int x; scanf("%d", &x); return x; }

using namespace std;

typedef long long Int;
typedef unsigned uint;
typedef unsigned long long uInt;

const uInt MOD = 100000000007;
const int MAXN = 10007;

int T;
int N, N_N;

char str[MAXN];

int main(void) {
T = in();

int i, j, k;

for ( ; T--; ) {
N = in();

map<uInt, int> mp;
int ans = 0;

for (i = 0; i < N; i++) {
scanf("%s", str); N_N = strlen(str);

map<uInt, int> buff;

for (j = 0; j < N_N; j++) {
uInt hash = 1ULL;
for (k = j; k < N_N; k++) {
hash = (((hash * 131ULL) * (str[k] - 'A' + 1)) % MOD) + 1;

if (buff[hash] == 1) continue;

buff[hash] = 1; mp[hash] += 1;

if (mp[hash] == N && ans < k - j + 1) {
ans = k - j + 1;
}
}
}
}
printf("%d\n", ans);
}
return 0;
}
Binary file added LiveArchive/LongestConstantGene.o
Binary file not shown.
12 changes: 9 additions & 3 deletions LiveArchive/i.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
1 2 2 4 0
1 2 3 4 1 2 3 3 4 2 0
0
2
2
ACGGGCGTCGTCCCCGTCGTCGTATC
CTCGTCGTCCCCGTCGTCGTGTC
3
ACGACGGCTGCGGTAACCC
TTACGGCTGCGGTCCCCTT
CCCCCCGTTTACGGCTGCGGTGG

Binary file added LongestConstantGene
Binary file not shown.
90 changes: 90 additions & 0 deletions LongestConstantGene.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <memory>
#include <iomanip>
#include <numeric>
#include <functional>
#include <new>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <climits>
#include <cctype>
#include <ctime>

#define REP(i, n) for(int (i) = 0; i < n; i++)
#define FOR(i, a, n) for(int (i) = a; i < n; i++)
#define FORR(i, a, n) for(int (i) = a; i <= n; i++)
#define for_each(q, s) for(typeof(s.begin()) q=s.begin(); q!=s.end(); q++)
#define sz(n) n.size()
#define pb(n) push_back(n)
#define all(n) n.begin(), n.end()

template<typename T> T gcd(T a, T b) {
if(!b) return a;
return gcd(b, a % b);
}
template<typename T> T lcm(T a, T b) {
return a * b / gcd(a, b);
}

template<typename T> void chmin(T& a, T b) { a = (a > b) ? b : a; }
template<typename T> void chmax(T& a, T b) { a = (a < b) ? b : a; }
int in() { int x; scanf("%d", &x); return x; }

using namespace std;

typedef long long Int;
typedef unsigned uint;
typedef unsigned long long uInt;

const uInt MOD = 1000000009;
const int MAXN = 10007;

int T;
int N, N_N;

char str[MAXN];

int main(void) {
freopen("i.in", "r", stdin);
T = in();

int i, j, k;

for ( ; T--; ) {
N = in();

map<uInt, int> mp;
int ans_cnt = 0, ans_len;

for (i = 0; i < N; i++) {
scanf("%s", str); N_N = strlen(str);

for (j = 0; j < N_N; j++) {
uInt hash = 0LL;
for (k = j; k < N_N; k++) {
hash = ((hash * 31) ^ (str[k] - 'A')) % MOD;
mp[hash] += 1;

if (mp[hash] > ans_cnt) {
ans_cnt = mp[hash], ans_len = k - j + 1;
}
}
}
}

printf("%d\n", ans_len);

}
return 0;
}
Binary file added LongestConstantGene.o
Binary file not shown.
Binary file added SPOJ/PosicoesLivres
Binary file not shown.
99 changes: 41 additions & 58 deletions SPOJ/PosicoesLivres.cpp
Original file line number Diff line number Diff line change
@@ -1,58 +1,41 @@
#include <stdio.h>

int main(){
int width, height, slotVazios, x1, x2, y1, y2, xMenor, xMaior, yMenor, yMaior, subpartes, i,j, k, board[550][550];
scanf( "%i%i%i", &width, &height, &subpartes );
while( height != 0 ){
slotVazios = width * height;
for( i = 0; i < width; i++) {
for( j = 0; j < height; j++) {
board[i][j] = 0;
}
}
for(i = 0; i < subpartes; i++) {
scanf( "%i%i%i%i", &x1, &y1, &x2, &y2);
if( x1 <= x2 ){
xMenor = x1;
xMaior = x2;
}
else{
xMenor = x2;
xMaior = x1;
}
if( y1 <= y2 ){
yMenor = y1;
yMaior = y2;
}
else{
yMenor = y2;
yMaior = y1;
}
for(j = xMenor; j<= xMaior; j++ ){
for( k = yMenor; k <= yMaior; k++ ){
if( board[j-1][k-1] == 0 ){
board[j-1][k-1] = 1;
slotVazios--;
}
}
}
}

switch( slotVazios ){
case 0:
printf( "There is no empty spots.\n" );
break;
case 1:
printf( "There is one empty spot.\n" );
break;
default:
printf( "There are %i empty spots.\n", slotVazios );
break;
}

scanf( "%i%i%i", &width, &height, &subpartes );
}


return 0;
}
#include <stdio.h>
#include <algorithm>

using namespace std;

int N, M, P;
int slot, x1, x2, y1, y2;
int subpartes, i,j, k, board[550][550];

int main(void) {
for ( ; scanf("%d%d%d", &N, &M, &P) == 3; ) {
slot = N * M;
for (i = 0; i < N; i++) {
for(j = 0; j < M; j++) {
board[i][j] = 0;
}
}

for (i = 0; i < P; i++) {
int d = scanf("%d%d%d%d", &x1, &y1, &x2, &y2);

for (j = min(x1, x2); j <= max(x1, x2); j++) {
for (k = min(y1, y2); k <= max(y1, y2); k++) {
if (board[j-1][k-1] == 0) {
board[j-1][k-1] = 1;
slot--;
}
}
}
}

if (slot == 0) {
printf("There is no empty spots.\n");
} else if (slot == 1) {
printf("There is one empty spot.\n");
} else {
printf("There are %d empty spots.\n", slot);
}
}
return 0;
}
Binary file added SPOJ/PosicoesLivres.o
Binary file not shown.
Binary file added SuffixTree
Binary file not shown.
92 changes: 92 additions & 0 deletions SuffixTree.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <memory>
#include <iomanip>
#include <numeric>
#include <functional>
#include <new>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <climits>
#include <cctype>
#include <ctime>

#define REP(i, n) for(int (i) = 0; i < n; i++)
#define FOR(i, a, n) for(int (i) = a; i < n; i++)
#define FORR(i, a, n) for(int (i) = a; i <= n; i++)
#define for_each(q, s) for(typeof(s.begin()) q=s.begin(); q!=s.end(); q++)
#define sz(n) n.size()
#define pb(n) push_back(n)
#define all(n) n.begin(), n.end()

template<typename T> T gcd(T a, T b) {
if(!b) return a;
return gcd(b, a % b);
}
template<typename T> T lcm(T a, T b) {
return a * b / gcd(a, b);
}

template<typename T> void chmin(T& a, T b) { a = (a > b) ? b : a; }
template<typename T> void chmax(T& a, T b) { a = (a < b) ? b : a; }
int in() { int x; scanf("%d", &x); return x; }

using namespace std;

typedef long long Int;
typedef unsigned uint;

struct Node {
int used;

Node* child[30];

Node() {
this->used = 0;
}

void add(string str, int pos, int len) {
if (pos == len) return;

int curr = str[pos] - 'A';

Node *next = child[curr];

if (null == NULL) next = new Node();


}
};

struct SuffixTree {
int words;

Node root;

void addSuffix(string str) {
string base;

int i;

for (i = (int) str.size() - 1; i >= 0; i--) {
base += str[i];

root.add(base, 0, (int) str.size());
}
}
};

int main(void) {

return 0;
}
Binary file added SuffixTree.o
Binary file not shown.

0 comments on commit ad9d9e6

Please sign in to comment.