Skip to content

Commit

Permalink
Add more solutions
Browse files Browse the repository at this point in the history
Related to #2
  • Loading branch information
abhishalya committed Oct 4, 2019
1 parent ff9d671 commit 7ff129b
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
28 changes: 28 additions & 0 deletions CodeChef/SEPT19B/FIBEASY.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
filename: FIBEASY.cpp
author: abhishalya
created: 2019-09-12 14:59:00
Copyright 2019 @abhishalya
*/
#include <bits/stdc++.h>
using namespace std; # Ignore CPPLintBear

typedef long long ll;

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int t; cin >> t;
int fib[60]; fib[0] = 0, fib[1] = 1;
for(int i = 2; i < 60; i++) {
fib[i] = (fib[i - 1] + fib[i - 2]) % 10;
}
while(t--) {
ll n; cin >> n;
// ll x = log2(n), y = pow(2, x);
ll x = 1;
while(x * 2 <= n) x *= 2;
cout << fib[(x - 1) % 60] << endl;
}
return 0;
}
19 changes: 19 additions & 0 deletions Codeforces/CF_1213/A.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
filename: A.cpp
author: abhishalya
created: 2019-08-30 20:03:43
Copyright 2019 @abhishalya
*/
#include <bits/stdc++.h>
using namespace std; # Ignore CPPLintBear

int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n, cnt = 0; cin >> n;
for (int i = 0; i < n; i++) {
int x; cin >> x;
if (x % 2) cnt++;
}
cout << min (cnt, n - cnt) << endl;
return 0;
}
27 changes: 27 additions & 0 deletions Codeforces/CF_1213/B.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
filename: B.cpp
author: abhishalya
created: 2019-08-30 20:08:55
Copyright 2019 @abhishalya
*/
#include <bits/stdc++.h>
using namespace std; # Ignore CPPLintBear

int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int t; cin >> t;
while (t--) {
int n; cin >> n;
int a[n], mx[n], cnt = 0;
for (int i = 0; i < n; i++) cin >> a[i];
mx[n - 1] = a[n - 1];
for (int i = n - 2; i >= 0; i--) {
mx[i] = min(mx[i + 1], a[i]);
}
for (int i = 0; i < n; i++) {
if(a[i] > mx[i]) cnt++;
}
cout << cnt << endl;
}
return 0;
}
32 changes: 32 additions & 0 deletions Codeforces/CF_1213/C.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
filename: C.cpp
author: abhishalya
created: 2019-08-30 20:23:42
Copyright 2019 @abhishalya
*/
#include <bits/stdc++.h>
using namespace std; # Ignore CPPLintBear

typedef long long ll;

int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int t; cin >> t;
vector<vector<int> > spv(10);
for(int i = 0; i <= 9; i++) {
int tp = i;
do {
spv[i].push_back(tp);
tp = (tp + i) % 10;
} while(tp != i);
}
while(t--) {
ll n, m; cin >> n >> m;
ll x = n / m, in = m % 10, ti = in, ex = 0, sm = 0;
for(int i = 0; i < x % spv[in].size(); i++) ex += spv[in][i]; sm = ex;
for(int i = x % spv[in].size(); i < spv[in].size(); i++)
sm += spv[in][i];
cout << ((x / spv[in].size()) * sm) + ex << endl;
}
return 0;
}
34 changes: 34 additions & 0 deletions Codeforces/CF_1213/D.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
filename: D.cpp
author: abhishalya
created: 2019-08-31 11:42:27
Copyright 2019 @abhishalya
*/
#include <bits/stdc++.h>
using namespace std; # Ignore CPPLintBear

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int n, k; cin >> n >> k; int a[n];
for(int i = 0; i < n; i++) {
cin >> a[i];
}
vector<vector<int> > cnts(200005);
for(int i = 0; i < n; i++) {
int tp = a[i], cnt = 0;
while(tp > 0) {
cnts[tp].push_back(cnt);
cnt++; tp /= 2;
}
}
int ans = INT_MAX;
for(int i = 0; i < 200005; i++) {
if(cnts[i].size() < k) continue;
sort(cnts[i].begin(), cnts[i].end());
ans = min(ans, accumulate(cnts[i].begin(),
cnts[i].begin() + k, 0));
}
cout << ans << endl;
return 0;
}

0 comments on commit 7ff129b

Please sign in to comment.