Skip to content

Commit

Permalink
all i have done till this day
Browse files Browse the repository at this point in the history
  • Loading branch information
Mukulguptaiit committed Dec 28, 2024
1 parent 9281ca0 commit 2fa8bb3
Show file tree
Hide file tree
Showing 27 changed files with 766 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Increasing_Array.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <iostream>
using namespace std;

int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
unsigned long long int sum=0;
int i=0;
while (t--) {
int j;
cin>>j;
if(j<i)sum+=i-j;
else i=j;
}
cout<<sum;
return 0;
}
27 changes: 27 additions & 0 deletions Permutations.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <iostream>
using namespace std;

int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
if(t==1){
cout<<1;
return 0;
}
if(t<4){
cout<<"NO SOLUTION";
return 0;
}
int i=2;
while(i<=t){
cout<<i<<' ';
i+=2;
}i=1;
while(i<=t){
cout<<i<<' ';
i+=2;
}
return 0;
}
27 changes: 27 additions & 0 deletions Repetitions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <iostream>
using namespace std;

int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t=1;
string s;
cin>>s;
char prev='#';
int count=0;
for(char a:s){
if(prev=='#'){
prev=a;
count++;
continue;
}if(prev==a){
count++;
}else{
prev=a;
t=max(count,t);
count=1;
}
}
cout<<max(count,t);
return 0;
}
37 changes: 37 additions & 0 deletions apartments.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k;
std::cin >> n >> m >> k;
std::vector<int> applicants(n);
std::vector<int> apartments(m);

for (int i = 0; i < n; ++i) {
std::cin >> applicants[i];
}

for (int i = 0; i < m; ++i) {
std::cin >> apartments[i];
}

std::sort(applicants.begin(), applicants.end());
std::sort(apartments.begin(), apartments.end());

int i = 0, j = 0, matches = 0;
for(int i=0;i<n;i++){
while (j < m) {
if (std::abs(applicants[i] - apartments[j]) <= k) {
++matches;
++j;
break;
} else if (apartments[j] < applicants[i] - k) {
++j;
}else{
break;
}
}
}
std::cout << matches << std::endl;

return 0;
}
33 changes: 33 additions & 0 deletions apple_division.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <climits>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
int n;
cin >> n;

long long sum = 0;
vector<int> weights(n);
for (int i = 0; i < n; ++i) {
cin >> weights[i];
sum += weights[i];
}

long long mn = LLONG_MAX;
for (int i = 0; i < (1 << n); i++) {
long long sem = 0;
for (int k = 0; k < n; k++) {
if (1 & (i >> k)) {
sem += weights[k];
}
}
mn = min(mn, abs(sum - 2 * sem));
}

cout << mn << endl;
return 0;
}
18 changes: 18 additions & 0 deletions bit_strings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <bits/stdc++.h>
using namespace std;

int main() {
int n;
cin >> n;
int t=n/28;
int p=n%28;
unsigned long long int k=1;
while(t--){
k=(k*(1ULL<<(28)))%1000000007;
}
if(p){
k=(k*(1ULL<<(p)))%1000000007;
}
cout<<k;
return 0;
}
38 changes: 38 additions & 0 deletions chessboard_queens.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <bits/stdc++.h>
using namespace std;

int placequeen(vector<vector<bool>>& vim, int queen) {
if (queen == 8) {
return 1;
}
int count = 0;
for (int j = 0; j < 8; j++) {
if (!vim[queen][j]) {
vector<vector<bool>> vp = vim;
for (int x = 0; x < 8; x++) {
for (int y = 0; y < 8; y++) {
if (x == queen || y == j || abs(x - queen) == abs(y - j)) {
vp[x][y] = 1;
}
}
}
count += placequeen(vp, queen + 1);
}
}
return count;
}

int main() {
vector<vector<bool>> vim(8, vector<bool>(8, 0));
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
char p;
cin >> p;
if (p == '*') {
vim[i][j] = 1;
}
}
}
cout << placequeen(vim, 0);
return 0;
}
24 changes: 24 additions & 0 deletions coin_piles.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <bits/stdc++.h>
using namespace std;

int main() {
int t;
cin >> t;

while (t--) {
int a, b;
cin >> a >> b;

// Ensure a >= b for simplicity
if (a < b) swap(a, b);

// Check if the piles can be emptied
if ((a + b) % 3 == 0 && a <= 2 * b) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}

return 0;
}
30 changes: 30 additions & 0 deletions concert_tickets.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <bits/stdc++.h>
using namespace std;

int main() {
multiset<int> tickets;
int n, m;
cin >> n >> m;

for (int i = 0; i < n; i++) {
int t;
cin >> t;
tickets.insert(t);
}

for (int i = 0; i < m; i++) {
int t;
cin >> t;
auto it = tickets.upper_bound(t);

if (tickets.empty() || it == tickets.begin()) {
cout << -1 << endl;
} else {
--it;
cout << *it << endl;
tickets.erase(it);
}
}

return 0;
}
39 changes: 39 additions & 0 deletions creating_strings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <bits/stdc++.h>
#include <string>
using namespace std;
void recursion(string& t , set<string>& s,int n){
if(s.find(t)!=s.end()){
return;
}
s.insert(t);
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
string p=t;
swap(p[i],p[j]);
recursion(p, s, n);
}
}
}
int main() {
string t;
cin>>t;
sort(t.begin(),t.end());
int n=t.size();
vector<int> alpa(26 ,0);
for(char c:t){
alpa[c-'a']++;
}
int k=tgamma(n+1);
for(auto a:alpa){
if(a>1){
k=k/tgamma(a+1);
}
}
cout<<k<<endl;
set<string> s;
recursion(t, s, n);
for(string p:s){
cout<<p<<endl;
}
return 0;
}
28 changes: 28 additions & 0 deletions digit_queries.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <bits/stdc++.h>
using namespace std;

int main() {
int t;
cin >> t;
while (t--) {
long long x;
cin >> x;

long long less = 9;
int count = 1;
while (x > less * count) {
x -= less * count;
less *= 10;
count++;
}
long long quo = (x - 1) / count;
int remain = (x - 1) % count;

long long number = less / 9 + quo;

string s = to_string(number);
cout << s[remain] << endl;
}

return 0;
}
17 changes: 17 additions & 0 deletions distinct_numbers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
int co=0;
set<int> s;
while(t--){
int x;
cin>>x;
if(s.find(x)==s.end()){
s.insert(x);
co++;
}
}cout<<co;
return 0;
}
27 changes: 27 additions & 0 deletions ferris_wheel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x;
std::cin >> n >> x;
multiset<int> s;
for(int i=0;i<n;i++){
int k;
cin>>k;
s.insert(k);
}
int co=0;
while(!s.empty()){
co++;
auto it=s.begin();
int p=*it;
s.erase(it);
it=s.upper_bound(x-p);
if(it!=s.begin()){
it--;
s.erase(it);
}

}
cout<<co;
return 0;
}
Loading

0 comments on commit 2fa8bb3

Please sign in to comment.