-
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.
Competative programming lab programs
- Loading branch information
tusharpatil1907
committed
Aug 3, 2023
0 parents
commit 1637d9b
Showing
47 changed files
with
1,688 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,14 @@ | ||
{ | ||
"files.associations": { | ||
"*.embeddedhtml": "html", | ||
"SEJAL.C": "cpp", | ||
"cstdio": "cpp", | ||
"cstring": "cpp", | ||
"stdio.h": "c", | ||
"VITO'S.C": "cpp", | ||
"sstream": "cpp", | ||
"string": "cpp", | ||
"vitos.C": "cpp", | ||
"vito's_family.C": "cpp" | ||
} | ||
} |
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,41 @@ | ||
#include <stdio.h> | ||
#include <conio.h> | ||
// add clrscr and getch if running in turbo compiler | ||
int main() | ||
{ | ||
int n = 0, i = 0, j = 0, mcl = 0, temp, cl = 0; | ||
// clrscr(); | ||
printf("\n Enter a value of i: "); | ||
scanf("%d", &i); | ||
printf("\n Enter a value of j: "); | ||
scanf("%d", &j); | ||
|
||
temp = i; | ||
while (temp <= j) | ||
{ | ||
n = temp; | ||
do | ||
{ | ||
if (n % 2 == 0) | ||
{ | ||
n = n / 2; | ||
} | ||
else | ||
{ | ||
n = (3 * n) + 1; | ||
} | ||
cl++; | ||
|
||
} while (n != 1); | ||
|
||
if (cl > mcl) | ||
{ | ||
mcl = cl; | ||
} | ||
temp++; | ||
cl = 1; | ||
} | ||
printf("\n %d %d %d \n",i,j,mcl); | ||
getch(); | ||
return 0; | ||
} |
Binary file not shown.
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,88 @@ | ||
|
||
// c program | ||
|
||
|
||
// #include <stdio.h> | ||
// #include <conio.h> | ||
// int Set[30000] = {0, 1, 2, 4, 6, 9}; | ||
// int main() | ||
// { | ||
// int remember, i, n; | ||
// // c1rscr(); | ||
// remember = 1; | ||
// for (i = 6; i < 30000; i++) | ||
// { | ||
// int Temp = Set[i - 1]; | ||
// int j; | ||
// for (j = remember; j < i; j++) | ||
// { | ||
// if (Set[j + 1] >= i) | ||
// break; | ||
// } | ||
|
||
// Set[i] Temp + j; | ||
// remember = j; | ||
// } | ||
// while (scanf("%d", &n)) | ||
// { | ||
// if (n == 0) | ||
// break; | ||
// for (i = 1; i < 30000; i++) | ||
// { | ||
// if (Set[i + 1] > n) | ||
// break; | ||
// } | ||
// printf("%d\n\n", i); | ||
// } | ||
// return 0; | ||
// } | ||
|
||
|
||
|
||
// c++ program | ||
|
||
#include<iostream> | ||
#include<vector> | ||
#define lim 673368 | ||
using namespace std; | ||
long long f[lim] = { 1, 1, 2, 2 }; | ||
long long i, j, x, sz=4; | ||
long long cur, bound, n; | ||
int main(){ | ||
for( i=3; sz<lim; ++i ){ | ||
for( j=0; j<f[i] && sz<lim; ++j ){ | ||
f[sz++] = i; | ||
} | ||
} | ||
while( cin >> n, n ){ | ||
if( n<lim ){ | ||
cout << f[n] << endl; | ||
continue; | ||
} | ||
x = 3; | ||
cur = 4; | ||
bound = 6; | ||
while( bound+x*f[x] < n ){ | ||
bound += x*f[x]; | ||
cur += f[x]; | ||
++x; | ||
} | ||
cout << ( cur + (n-bound)/x ) << endl; | ||
} | ||
} | ||
|
||
/*----------OUT PUT----------- | ||
1 | ||
1 | ||
5 | ||
3 | ||
8 | ||
4 | ||
100 | ||
21 | ||
9999 | ||
356 | ||
123456 | ||
1684 | ||
*/ |
Binary file not shown.
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,97 @@ | ||
/* 12438420 10142 Australian Voting Accepted C++ 0.052 2013-10-03 06:22:29 */ | ||
#include<stdio.h> | ||
#include<stdlib.h> | ||
int main(){ | ||
bool first=true; | ||
int t; | ||
scanf("%d",&t); | ||
for(int T=1;T<=t;T++){ | ||
char str[20][81]; | ||
bool fail[20]; | ||
int rank[1000][20]; | ||
int ticket[20]; | ||
int n; | ||
scanf("%d",&n); | ||
(void) getchar(); | ||
for(int i=0;i<n;i++) | ||
gets(str[i]); | ||
|
||
int people=0; | ||
char tmp[1000]; | ||
while( gets(tmp) ){ | ||
if( tmp[0]=='\0' ) | ||
break; | ||
int count=0,k=0; | ||
for(int i=0;tmp[i]!='\0';i++) | ||
if( tmp[i]==' ' ) | ||
rank[people][k++]=count-1,count=0; | ||
else | ||
count=count*10+tmp[i]-'0'; | ||
rank[people++][k++]=count-1; | ||
} | ||
for(int i=0;i<n;i++) | ||
fail[i]=false; | ||
|
||
if( !first ) | ||
putchar('\n'); | ||
first=false; | ||
|
||
int exist=n; | ||
while( true ){ | ||
int min=2e9; | ||
bool found=false; | ||
|
||
for(int i=0;i<n;i++) | ||
ticket[i]=0; | ||
for(int i=0;i<people;i++){ | ||
for(int j=0;j<n;j++) | ||
if( !fail[rank[i][j]] ){ | ||
ticket[rank[i][j]]++; | ||
break; | ||
} | ||
} | ||
for(int i=0;i<n;i++){ | ||
if( ticket[i]>people/2.0 ){ | ||
printf("%s\n",str[i]); | ||
found=true; | ||
} | ||
if( !fail[i]&&min>ticket[i] ) | ||
min=ticket[i]; | ||
} | ||
if( found ) | ||
break; | ||
|
||
for(int i=0;i<n;i++) | ||
if( ticket[i]==min ) | ||
fail[i]=true,exist--; | ||
if( exist<=0 ){ | ||
for(int i=0;i<n;i++) | ||
if( ticket[i]==min ) | ||
printf("%s\n",str[i]); | ||
break; | ||
} | ||
} | ||
|
||
} | ||
return 0; | ||
} | ||
|
||
|
||
|
||
|
||
// Sample Input | ||
|
||
// 1 | ||
|
||
// 3 | ||
// John Doe | ||
// Jane Smith | ||
// Sirhan Sirhan | ||
// 1 2 3 | ||
// 2 1 3 | ||
// 2 3 1 | ||
// 1 2 3 | ||
// 3 1 2 | ||
// Output for Sample Input | ||
|
||
// John Doe |
Binary file not shown.
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,138 @@ | ||
#include <iostream> | ||
#include <fstream> | ||
#include <stdio.h> | ||
#include <vector> | ||
#include <sstream> | ||
|
||
using namespace std; | ||
|
||
void sort(int[], int, int); | ||
int find_partition(int[], int, int); | ||
void find_bridge_combinations(vector<int>); | ||
bool pick_first_over_second(int, int, int, int); | ||
|
||
int main() { | ||
int testcases; | ||
cin >> testcases; | ||
cin.ignore(100, '\n'); | ||
while (testcases > 0) { | ||
vector<int> list; | ||
int size; | ||
cin >> size; | ||
int array[size]; | ||
for (int i = 0; i < size; i++) { | ||
cin >> array[i]; | ||
} | ||
sort (array, 0, size-1); | ||
for (int i = 0; i < size; i++) { | ||
list.push_back(array[i]); | ||
} | ||
find_bridge_combinations(list); | ||
testcases--; | ||
if (testcases != 0) { | ||
cout << endl; | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
void sort(int array[], int start, int end) { | ||
int partition = find_partition(array, start, end); | ||
if (start < partition-1) { | ||
sort(array, start, partition-1); | ||
} | ||
if (partition < end) { | ||
sort(array, partition, end); | ||
} | ||
|
||
} | ||
|
||
int find_partition(int array[], int start, int end) { | ||
int i = start; | ||
int j = end; | ||
|
||
int partition = (i+j)/2; | ||
int pivot = array[partition]; | ||
|
||
while (i <= j) { | ||
while (array[i] < pivot) { | ||
i++; | ||
} | ||
while (array[j] > pivot) { | ||
j--; | ||
} | ||
if (i <= j) { | ||
int temp = array[i]; | ||
array[i] = array[j]; | ||
array[j] = temp; | ||
i++; | ||
j--; | ||
} | ||
} | ||
return i; | ||
} | ||
void find_bridge_combinations(vector<int> list) { | ||
int total_time = 0; | ||
string result; | ||
ostringstream oss; | ||
int size = list.size(); | ||
/* | ||
first = AD, A, AC, A | ||
sec = AB, A, CD, B | ||
*/ | ||
while (list.size() >= 4) { | ||
if (pick_first_over_second(list[0], list[1], list[size-2], list[size-1])) { | ||
oss << list[0] << " " << list[size-1] << "\n"; | ||
oss << list[0] << "\n"; | ||
oss << list[0] << " " << list[size-2] << "\n"; | ||
oss << list[0] << "\n"; | ||
total_time += (2*list[0] + list[size-2] + list[size-1]); | ||
} else { | ||
oss << list[0] << " " << list[1] << "\n"; | ||
oss << list[0] << "\n"; | ||
oss << list[size-2] << " " << list[size-1] << "\n"; | ||
oss << list[1] << "\n"; | ||
total_time += (list[0] + 2*list[1] + list[size-1]); | ||
} | ||
list.pop_back(); | ||
list.pop_back(); | ||
size = list.size(); | ||
} | ||
if (list.size() == 1) { | ||
total_time += list[0]; | ||
oss << list[0] << "\n"; | ||
} else if (list.size() == 3) { | ||
total_time += (list[1] + list[0] + list[2]); | ||
oss << list[0] << " " << list[2] << "\n"; | ||
oss << list[0] << "\n"; | ||
oss << list[0] << " " << list[1] << "\n"; | ||
} else { | ||
total_time += list[1]; | ||
oss << list[0] << " " << list[1] << "\n"; | ||
} | ||
|
||
cout << total_time << endl; | ||
cout << oss.str(); | ||
} | ||
|
||
bool pick_first_over_second(int first, int sec, int third, int fourth) { | ||
int first_val = (2*first + third + fourth); | ||
int sec_val = (first + 2*sec + fourth); | ||
return first_val < sec_val; | ||
} | ||
|
||
// input | ||
// 1 | ||
// 4 | ||
// 1 | ||
// 2 | ||
// 5 | ||
// 10 | ||
|
||
// output | ||
// 17 | ||
// 1 2 | ||
// 1 | ||
// 5 10 | ||
// 2 | ||
// 1 2 |
Binary file not shown.
Oops, something went wrong.