Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions Contributors/Nitin-200104042.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
## NITIN KUMAR
- Batch: 2020-2024 {CSE}
- Github Profile: {https://github.com/Nitin73290}
- Linkedin Profile: {https://www.linkedin.com/in/nitin-kumar-77067321a/}


POLICE CATCHES THIEVES

// C++ program to find maximum number of thieves caught
#include <bits/stdc++.h>
using namespace std;
int policeThief(char arr[], int n, int k)
{
// Initialize the current lowest indices of
// policeman in pol and thief in thi variable as -1
int pol = -1, thi = -1, res = 0;
// Find the lowest index of policemen
for (int i = 0; i < n; i++) {
if (arr[i] == 'P') {
pol = i;
break;
}
}

// Find the lowest index of thief
for (int i = 0; i < n; i++) {
if (arr[i] == 'T') {
thi = i;
break;
}
}

// If lowest index of either policemen or thief remain
// -1 then return 0
if (thi == -1 || pol == -1)
return 0;
while (pol < n && thi < n) {
// can be caught
if (abs(pol - thi) <= k) {

pol = pol + 1;
while (pol < n && arr[pol] != 'P')
pol = pol + 1;

thi = thi + 1;
while (thi < n && arr[thi] != 'T')
thi = thi + 1;

res++;
}
else if (thi < pol) {
thi = thi + 1;
while (thi < n && arr[thi] != 'T')
thi = thi + 1;
}
else {
pol = pol + 1;
while (pol < n && arr[pol] != 'P')
pol = pol + 1;
}
}
return res;
}

int main()
{
int k, n;
char arr1[] = { 'P', 'T', 'T', 'P', 'T' };
k = 2;
n = sizeof(arr1) / sizeof(arr1[0]);
cout << "Maximum thieves caught: " << policeThief(arr1, n, k) << endl;

char arr2[] = { 'T', 'T', 'P', 'P', 'T', 'P' };
k = 2;
n = sizeof(arr2) / sizeof(arr2[0]);
cout << "Maximum thieves caught: " << policeThief(arr2, n, k) << endl;

char arr3[] = { 'P', 'T', 'P', 'T', 'T', 'P' };
k = 3;
n = sizeof(arr3) / sizeof(arr3[0]);
cout << "Maximum thieves caught: " << policeThief(arr3, n, k) << endl;

return 0;
}

// This code is contributed by Aditya Kumar (adityakumar129)
47 changes: 47 additions & 0 deletions Contributors/NitinKumar-200104042.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
## NITIN KUMAR
- Batch: 2020-2024 {CSE}
- Github Profile: https://github.com/Nitin73290
- Linkedin Profile: {https://www.linkedin.com/in/nitin-kumar-77067321a/}

PEGION HOLE ALGORITHM

/* C program to implement Pigeonhole Sort */
#include <bits/stdc++.h>
using namespace std;

/* Sorts the array using pigeonhole algorithm */
void pigeonholeSort(int arr[], int n)
{
// Find minimum and maximum values in arr[]
int min = arr[0], max = arr[0];
for (int i = 1; i < n; i++)
{
if (arr[i] < min)
min = arr[i];
if (arr[i] > max)
max = arr[i];
}
int range = max - min + 1;

int index = 0;
for (int i = 0; i < range; i++)
{
vector<int>::iterator it;
for (it = holes[i].begin(); it != holes[i].end(); ++it)
arr[index++] = *it;
}
}

int main()
{
int arr[] = {8, 3, 2, 7, 4, 6, 8};
int n = sizeof(arr)/sizeof(arr[0]);

pigeonholeSort(arr, n);

printf("Sorted order is : ");
for (int i = 0; i < n; i++)
printf("%d ", arr[i]);

return 0;
}
45 changes: 45 additions & 0 deletions Nitin Kumar-200104042.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## Nitin Kumar
- Batch: 2020-2024 {CSE}
- Github Profile: {https://github.com/Nitin73290}
- Linkedin Profile: {https://www.linkedin.com/in/nitin-kumar-77067321a/}

Fitting Shelves Problem


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

void minSpacePreferLarge(int wall, int m, int n)
{
int num_m = 0, num_n = 0, min_empty = wall;
int p = wall/m, q = 0, rem=wall%m;
num_m=p;
num_n=q;
min_empty=rem;
while (wall >= n) {
// place one more shelf of length n
q += 1;
wall = wall - n;
// place as many shelves of length m
// in the remaining part
p = wall / m;
rem = wall % m;
if (rem <= min_empty) {
num_m = p;
num_n = q;
min_empty = rem;
}
}
cout << num_m << " " << num_n << " "
<< min_empty << endl;
}

int main()
{
int wall = 29, m = 3, n = 9;
minSpacePreferLarge(wall, m, n);

wall = 76, m = 1, n = 10;
minSpacePreferLarge(wall, m, n);
return 0;
}
Loading