-
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.
These codes are mainly solutions from codeforces and atcoder. no advanced algorithms. just bruteforce and simulation. tried to learn dynamic programming
- Loading branch information
Showing
37 changed files
with
1,037 additions
and
0 deletions.
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 @@ | ||
#include <iostream> | ||
using namespace std; | ||
int main () | ||
{ | ||
long long n; | ||
cin >> n; | ||
long long a, b, c, triplets = 0; | ||
for ( a = 1; a <= n; a++) | ||
{ | ||
for ( b = a; b <= n; b++) | ||
{ | ||
for ( c = b; c <= n; c++) | ||
{ | ||
if (a*b*c <= n) triplets++; | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
cout << triplets << 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,42 @@ | ||
#include <iostream> | ||
using namespace std; | ||
int main() | ||
{ | ||
int t; | ||
cin >> t; | ||
while (t--) | ||
{ | ||
int n, l, i = 0, j = 0; | ||
cin >> n >> l; | ||
int deci[n]; | ||
while (n--) | ||
{ | ||
|
||
cin >> deci[i]; | ||
i++; | ||
} | ||
|
||
int bina[n][l]; | ||
for (i = 0; i < n; i++) | ||
{ | ||
for (j = 0; j < l; j++) | ||
{ | ||
bina[i][j] = 0; | ||
} | ||
} | ||
for (i = 0; i < n; i++) | ||
{ | ||
|
||
for (j = l-1; j >= 0; j--) | ||
{ | ||
if (deci[n]) | ||
{ | ||
bina[i][j] = deci[n] % 2; | ||
deci[n] = deci[n] / 2; | ||
} | ||
cout << bina[i][j]; | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include <sstream> | ||
using namespace std; | ||
int main() | ||
{ | ||
int t, n, c = 0; | ||
cin >> t; | ||
while (t--) | ||
{ | ||
float outs = 0, runs = 0; | ||
float ans; | ||
c++; | ||
cin >> n; | ||
while (n--) | ||
{ | ||
string run; | ||
cin >> run; | ||
int x = run.size() - 1; | ||
if (run[x] != '*') | ||
outs++; | ||
float run2; | ||
stringstream ss; | ||
ss << run; | ||
ss >> run2; | ||
runs += run2; | ||
} | ||
if (outs == 0) | ||
cout << "Case " << c << ":" << " " << -1 << endl; | ||
else | ||
{ | ||
ans = runs / outs; | ||
if (ans - int(ans) > 0) | ||
{ | ||
cout << "Case " << c << ":" << " " << -1 << endl; | ||
} | ||
else | ||
cout << "Case " << c << ":" << " " << int(ans) << endl; | ||
} | ||
} | ||
return 0; | ||
} |
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,25 @@ | ||
//ac | ||
#include <iostream> | ||
using namespace std; | ||
int main() | ||
{ | ||
int n, i, rightguess = 0; | ||
cin >> n; | ||
int s, b, zerornot; | ||
for (i = 0; i < n; i++) | ||
{ | ||
cin >> s; | ||
|
||
for (b = 1; b <= (s - 3) / 7; b++) // for a = 1 we get the highest number of b | ||
{ | ||
zerornot = (s - 3 * b) % (4 * b + 3); // determining --> is it a natural number or fractional | ||
if (zerornot == 0) | ||
{ | ||
rightguess++; | ||
break; | ||
} | ||
} | ||
} | ||
cout << n - rightguess << endl; | ||
return 0; | ||
} |
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,21 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
long long t , n, m; | ||
cin >> t; | ||
for(int i = 0 ; i < t ; i++){ | ||
cin >> n >> m; | ||
if (n==m==1) | ||
cout << 0 << endl; | ||
else if (n<m){ | ||
cout << n << endl; | ||
} | ||
else{ | ||
cout << m << endl; | ||
} | ||
|
||
} | ||
return 0; | ||
} |
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,22 @@ | ||
import random | ||
|
||
def encrypt(plaintext): | ||
ciphertext = '' | ||
for letter in plaintext: | ||
i = ALPHA.index(letter) | ||
c = (a*i + b) % m | ||
ciphertext += ALPHA[c] | ||
return ciphertext | ||
|
||
|
||
ALPHA = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ{}_ #" | ||
m = len(ALPHA) | ||
a = random.randrange(1, m) | ||
b = random.randrange(1, m) | ||
|
||
message = open("message.txt").read().replace('\n', '') | ||
cipher = encrypt(message) | ||
|
||
with open("cipher.txt", 'w') as f: | ||
for i in range(0,len(cipher),64): | ||
f.write( cipher[i:i+64]+'\n' ) |
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,44 @@ | ||
#include <iostream> | ||
#include <iomanip> | ||
int i; | ||
using namespace std; | ||
int frac(int x, int y) | ||
{ | ||
int z; | ||
z = x / y; | ||
cout << z << " "; | ||
int rem; | ||
rem = x%y; | ||
if(rem!=1) | ||
frac(y, rem); | ||
else | ||
cout << y; | ||
return 0; | ||
} | ||
|
||
int howmuch(int x, int y) | ||
{ | ||
i++; | ||
int rem; | ||
rem = x%y; | ||
if(rem!=1) | ||
howmuch(y, rem); | ||
else | ||
cout << i << " "; | ||
return 0; | ||
} | ||
|
||
int main() | ||
{ | ||
int t; | ||
cin >> t; | ||
while (t--) | ||
{ | ||
i = 0; | ||
int x, y, rem; | ||
cin >> x >> y; | ||
howmuch(x,y); | ||
frac(x, y); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import requests | ||
from bs4 import BeautifulSoup | ||
daily_star = requests.get('https://www.thedailystar.net') | ||
parsed_html = BeautifulSoup(daily_star.text, 'html.parser') | ||
headlines = parsed_html.find_all('h3') | ||
for i in headlines: | ||
if len(i.text.strip()) > 0: | ||
print(i.text) | ||
|
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,39 @@ | ||
#include <iostream> | ||
using namespace std; | ||
int main() | ||
{ | ||
int t, x = 6; | ||
cin >> t; | ||
int a[3]; | ||
for (int i = 0; i < t; i++) | ||
{ | ||
|
||
cin >> a[0] >> a[1] >> a[2]; | ||
while (x--) | ||
{ | ||
if (a[0] + a[2] - 2 * a[1] == 0) | ||
{ | ||
cout << 0 << endl; | ||
break; | ||
} | ||
else if (abs(a[0] + a[2] - 2 * a[1]) == 1) | ||
{ | ||
cout << 1 << endl; | ||
break; | ||
} | ||
else | ||
{ | ||
if (a[0] + a[2] - 2 * a[1] > 1) | ||
{ | ||
a[1] = a[1] + 1; | ||
a[0] = a[0] - 1; | ||
} | ||
else | ||
{ | ||
a[1] = a[1] - 1; | ||
a[0] = a[0] + 1; | ||
} | ||
} | ||
} | ||
} | ||
} |
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,26 @@ | ||
#include <iostream> | ||
#include <cmath> | ||
|
||
int main() { | ||
float t, x, y, a, b, d_bcac; | ||
std::cin >> t; | ||
for (int i=0; i<t; i++) | ||
{ | ||
std::cin >> x >> y; | ||
d_bcac = (x+y)/2; //if abs used then d_bcac won't be a float number | ||
if(d_bcac - round(d_bcac) == 0) | ||
{ | ||
for (int i=0; i<=d_bcac; i++) | ||
{ | ||
a=i; | ||
b=d_bcac-i; | ||
if (abs(a-x) +abs(b-y) == d_bcac) | ||
break; | ||
} | ||
std::cout << a << " " << b << "\n"; | ||
} | ||
//std::cout << (x+2*d_bcac-y)/2 << " " << (y+2*d_bcac-x)/2 << "\n"; | ||
else | ||
std::cout << -1 << " " << -1 << "\n"; | ||
} | ||
} |
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,31 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
int main() { | ||
int t, i; | ||
cin >> t; | ||
for(i = 0 ; i < t ; i++){ | ||
int n, l, r, k, a = 0, spended =0, chocolates = 0; | ||
cin >> n >> l >> r >> k; | ||
int chocoprice[n]; | ||
for (i = 0; i < n; i++) cin >> chocoprice[i]; | ||
for ( i = 0; i < n; i++) | ||
{ | ||
if(chocoprice[i] >= l && chocoprice[i] <= r) a++; | ||
} | ||
int buyable[a]; | ||
for (int i = 0; i < n; i++) | ||
{ | ||
if(chocoprice[i] >= l && chocoprice[i] <= r) buyable[a] = chocoprice[i]; | ||
} | ||
int asize = sizeof(buyable) / sizeof(buyable[0]); | ||
sort(buyable, buyable + asize); | ||
for ( i = 0; i < a; i++) | ||
{ | ||
spended += buyable[i]; | ||
if (spended <= k) chocolates++; | ||
} | ||
cout << chocolates << endl; | ||
} | ||
return 0; | ||
} |
Oops, something went wrong.