-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed6f511
commit 95ed899
Showing
5 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//DATE: 20/06/2016 | ||
//Author: Ramjeet Saran | ||
//http://www.spoj.com/problems/ALICESIE/ | ||
|
||
|
||
# include <bits/stdc++.h> | ||
|
||
# define gc getchar_unlocked | ||
# define pc putchar_unlocked | ||
# define li long int | ||
# define lli long long int | ||
|
||
using namespace std; | ||
|
||
|
||
int main() { | ||
int T, N; | ||
cin>>T; | ||
while(T--) { | ||
cin>>N; | ||
cout<<(N + 1) / 2<<endl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//DATE: 20/06/2016 | ||
//Author: Ramjeet Saran | ||
//http://www.spoj.com/problems/DISUBSTR/ | ||
|
||
// SUFFIX ARRAY APPLICATION | ||
// TRY 1: using SET MAP GOT TLE | ||
|
||
# include <bits/stdc++.h> | ||
|
||
# define gc getchar_unlocked | ||
# define pc putchar_unlocked | ||
# define li long int | ||
# define lli long long int | ||
|
||
using namespace std; | ||
|
||
int LCP(string s1, string s2) { | ||
int counter = 0, len1 = s1.length(), len2 = s2.length(); | ||
for(int i = 0; i < len1; i++) { | ||
if(s1[i] == s2[i]) { | ||
counter++; | ||
} else { | ||
break; | ||
} | ||
} | ||
return counter; | ||
} | ||
int main() { | ||
int T; | ||
cin>>T; | ||
while(T--) { | ||
string S; | ||
vector<string> suffixArray; | ||
cin>>S; | ||
int length = S.length(); | ||
for(int i = 0; i < length; i++) { | ||
suffixArray.push_back(S.substr(i)); | ||
} | ||
sort(suffixArray.begin(), suffixArray.end()); | ||
int ans = suffixArray[0].length(); | ||
for(int j = 1; j < length; j++) { | ||
// cout<<suffixArray[ j ] << " "<<suffixArray[ j - 1]<<endl; | ||
ans += suffixArray[j].length() - LCP(suffixArray[j], suffixArray[j - 1]); | ||
} | ||
cout<<ans<<endl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//DATE: 20/06/2016 | ||
//Author: Ramjeet Saran | ||
//http://www.spoj.com/problems/MCOINS/ | ||
|
||
// GAME ALGORITHMS | ||
|
||
# include <bits/stdc++.h> | ||
|
||
# define gc getchar_unlocked | ||
# define pc putchar_unlocked | ||
# define li long int | ||
# define lli long long int | ||
|
||
using namespace std; | ||
|
||
|
||
int main() { | ||
int N, K, M; | ||
cin>>N>>K>>M; | ||
int *arr = new int[1000001]; | ||
memset(arr, 0, 1000001); | ||
for(int i = 1; i <= 1000000; i++) { | ||
if(arr[i - 1] == 0 || (i - N >= 0 && arr[i - N] == 0) || (i - K >= 0 && arr[i - K] == 0)) { | ||
arr[i] = 1; | ||
} | ||
} | ||
int A; | ||
for(int j = 0; j < M; j++) { | ||
cin>>A; | ||
arr[A] == 1 ? cout<<"A" : cout<<"B"; | ||
} | ||
cout<<endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//DATE: 19/06/2016 | ||
//Author: Ramjeet Saran | ||
//http://www.spoj.com/problems/SILVER/ | ||
|
||
|
||
#include <bits/stdc++.h> | ||
|
||
# define MAX(a,b) a>b ? a : b; | ||
# define MIN(a,b) a<b ? a : b; | ||
# define lli long long int | ||
# define ull unsigned long long int | ||
# define FOR(i,j,n) for(i = j; i < n; i++) | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
int N; | ||
scanf("%d", &N); | ||
while(N) { | ||
int res = (int) floor(log2(N)); | ||
printf("%d\n", res); | ||
scanf("%d", &N); | ||
} | ||
} |