Skip to content

Commit

Permalink
Spoj Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
rezwanh001 committed Mar 6, 2017
1 parent 75e90a1 commit 8c3d039
Show file tree
Hide file tree
Showing 64 changed files with 2,002 additions and 2,002 deletions.
8 changes: 4 additions & 4 deletions AGGRCOW - Aggressive cows/AGGRCOW - Aggressive cows.depend
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# depslib dependency file v1.0
1487534351 source:g:\code c++\sphere\aggrcow - aggressive cows\main.cpp
<bits/stdc++.h>

# depslib dependency file v1.0
1487534351 source:g:\code c++\sphere\aggrcow - aggressive cows\main.cpp
<bits/stdc++.h>
124 changes: 62 additions & 62 deletions AGGRCOW - Aggressive cows/main.cpp
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll pos[123456];
ll N, C;

bool F(ll x){
ll cowsplaced = 1, lastpos = pos[0];
for(ll i = 1; i < N; i++){
if(pos[i] - lastpos >= x){
lastpos = pos[i];
cowsplaced++;
if(cowsplaced == C){
return 1;
}
}
}
return 0;
}

ll binarySearch(){
//sort(pos, pos + N);
ll start = 0, ed = pos[N - 1], mx = -1;
while(start < ed){
int mid = start + (ed - start)/2;
if(F(mid) == 1){
if(mid > mx){
mx = mid;
}
start = mid + 1;
}
else{
ed = mid;
}
}
return mx;
}

int main() {
ll T;
scanf("%lld",&T);
while(T--){
scanf("%lld%lld",&N,&C);
for(ll i = 0;i<N;i++){
scanf("%lld",&pos[i]);
}
//printf("%lld\n",binarySearch());
sort(pos, pos + N);
cout << binarySearch() << "\n";
}

return 0;
}
/**
1
5 3
1
2
8
4
9
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll pos[123456];
ll N, C;

bool F(ll x){
ll cowsplaced = 1, lastpos = pos[0];
for(ll i = 1; i < N; i++){
if(pos[i] - lastpos >= x){
lastpos = pos[i];
cowsplaced++;
if(cowsplaced == C){
return 1;
}
}
}
return 0;
}

ll binarySearch(){
//sort(pos, pos + N);
ll start = 0, ed = pos[N - 1], mx = -1;
while(start < ed){
int mid = start + (ed - start)/2;
if(F(mid) == 1){
if(mid > mx){
mx = mid;
}
start = mid + 1;
}
else{
ed = mid;
}
}
return mx;
}

int main() {
ll T;
scanf("%lld",&T);
while(T--){
scanf("%lld%lld",&N,&C);
for(ll i = 0;i<N;i++){
scanf("%lld",&pos[i]);
}
//printf("%lld\n",binarySearch());
sort(pos, pos + N);
cout << binarySearch() << "\n";
}

return 0;
}
/**
1
5 3
1
2
8
4
9
*/
24 changes: 12 additions & 12 deletions ALCATRAZ1 - SUM OF DIGITS/ALCATRAZ1 - SUM OF DIGITS.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
def Main(T):
for _ in range(T):
s = input()
sm = 0
for i in range(len(s)):
a = int(s[i])
sm += a
print(sm)


if __name__ == '__main__':
T = int(input())
def Main(T):
for _ in range(T):
s = input()
sm = 0
for i in range(len(s)):
a = int(s[i])
sm += a
print(sm)


if __name__ == '__main__':
T = int(input())
Main(T)
30 changes: 15 additions & 15 deletions Adding Revered Nubers/ADDREV-Adding_Reversed_Numbers.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'''
Created on May 20, 2016
@author: Md. Rezwanul Haque
'''
n = int(input())
ans = 0
rezwan = 0
for i in range(n):
a,b = map(int,input().split())
A = int(str(a)[::-1])#reverse
B = int(str(b)[::-1])#reverse
ans = A + B
rezwan = int(str(ans)[::-1])#reverse
print(rezwan)
'''
Created on May 20, 2016
@author: Md. Rezwanul Haque
'''
n = int(input())
ans = 0
rezwan = 0
for i in range(n):
a,b = map(int,input().split())
A = int(str(a)[::-1])#reverse
B = int(str(b)[::-1])#reverse
ans = A + B
rezwan = int(str(ans)[::-1])#reverse
print(rezwan)
84 changes: 42 additions & 42 deletions Aibohphobia/Aibohphobia.cbp
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="Aibohphobia" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/Aibohphobia" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/Aibohphobia" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
</Compiler>
<Unit filename="main.cpp" />
<Extensions>
<code_completion />
<envvars />
<debugger />
</Extensions>
</Project>
</CodeBlocks_project_file>
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="Aibohphobia" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/Aibohphobia" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/Aibohphobia" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
</Compiler>
<Unit filename="main.cpp" />
<Extensions>
<code_completion />
<envvars />
<debugger />
</Extensions>
</Project>
</CodeBlocks_project_file>
20 changes: 10 additions & 10 deletions Aibohphobia/Aibohphobia.layout
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="458" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="458" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>
86 changes: 43 additions & 43 deletions Aibohphobia/main.cpp
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
#include <bits/stdc++.h>
using namespace std;

int LCS(string X, string Y, int m, int n){
int dp[m+1][n+1];

for(int i=0;i<=m;i++){
for(int j=0;j<=n;j++){
if(i == 0 || j == 0){
dp[i][j] = 0;
}
else if(X[i - 1] == Y[j - 1]){
dp[i][j] = dp[i - 1][j - 1] + 1;
}
else{
dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
}
}
}
//cout << dp[m][n] << endl;
return dp[m][n];
}

int main()
{
//LCS("fft", "tff" , 3, 3);

int T;
scanf("%d",&T);

while(T--){
string s1, s2;
cin >> s2;
s1 = s2;

reverse(s2.begin(), s2.end());
int rez = LCS(s1,s2, s1.size(), s2.size());

cout<< abs(s1.size() - rez) << endl;
}

return 0;
}
#include <bits/stdc++.h>
using namespace std;

int LCS(string X, string Y, int m, int n){
int dp[m+1][n+1];

for(int i=0;i<=m;i++){
for(int j=0;j<=n;j++){
if(i == 0 || j == 0){
dp[i][j] = 0;
}
else if(X[i - 1] == Y[j - 1]){
dp[i][j] = dp[i - 1][j - 1] + 1;
}
else{
dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
}
}
}
//cout << dp[m][n] << endl;
return dp[m][n];
}

int main()
{
//LCS("fft", "tff" , 3, 3);

int T;
scanf("%d",&T);

while(T--){
string s1, s2;
cin >> s2;
s1 = s2;

reverse(s2.begin(), s2.end());
int rez = LCS(s1,s2, s1.size(), s2.size());

cout<< abs(s1.size() - rez) << endl;
}

return 0;
}
Loading

0 comments on commit 8c3d039

Please sign in to comment.