Skip to content

Commit 6721326

Browse files
Add files via upload
1 parent b35a5ec commit 6721326

28 files changed

+1281
-38
lines changed

0sumsubA.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include <bits/stdc++.h>
2+
3+
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
4+
#define f(i,a,b) for(i=a;i<b;i++)
5+
#define fr(i,a,b) for(i=a;i>=b;i--)
6+
#define sp "\t"
7+
#define ll long long int
8+
#define ff first
9+
#define ss second
10+
#define pb push_back
11+
#define mp make_pair
12+
#define mod 1000000007
13+
14+
using namespace std;
15+
16+
int i,n,*a;
17+
18+
int maxzlen()
19+
{
20+
unordered_map<int, int> x;
21+
int s=0,l=0;
22+
23+
f(i,0,n)
24+
{
25+
// Add current element to sum
26+
s += a[i];
27+
28+
if (a[i] == 0 && l == 0)
29+
l = 1;
30+
if (s == 0)
31+
l = i + 1;
32+
33+
// Look for this sum in Hash table
34+
if (x.find(s) != x.end()) {
35+
// If this sum is seen before, then update max_len
36+
l = max(l, i - x[s]);
37+
}
38+
else {
39+
// Else insert this sum with index in hash table
40+
x[s] = i;
41+
}
42+
}
43+
return l;
44+
}
45+
46+
47+
main()
48+
{
49+
cout<<"\nEnter the No. of Elements:";
50+
cin>>n;
51+
a=new (nothrow) int[n];
52+
cout<<"\nEnter your Array:\n";
53+
f(i,0,n)
54+
cin>>*(a+i);
55+
maxzlen();
56+
cout<<"\nYour Array:\n";
57+
f(i,0,n)
58+
cout<<*(a+i)<<sp;
59+
delete[] a;
60+
cout<<"\nThe Max Length is :"<<maxzlen();
61+
}

CF_CandiesDivision.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
main()
5+
{
6+
#ifdef _DEBUG
7+
freopen("input.txt", "r", stdin);
8+
//freopen("output.txt", "w", stdout);
9+
#endif
10+
int tc,n,k;
11+
cin>>tc;
12+
while(tc>0)
13+
{
14+
cin>>n>>k;
15+
int b=n-n%k;
16+
b+=min(n%k,k/2);
17+
cout<<b<<endl;
18+
tc-=1;
19+
}
20+
}

LL_prac.cpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#include <bits/stdc++.h>
2+
3+
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
4+
#define f(i,a,b) for(i=a;i<b;i++)
5+
#define fr(i,a,b) for(i=a;i>=b;i--)
6+
#define sp "\t"
7+
8+
using namespace std;
9+
10+
int i;
11+
12+
struct node
13+
{
14+
int data;
15+
struct node *next;
16+
17+
node()
18+
{
19+
data=0;
20+
next=NULL;
21+
}
22+
};
23+
24+
struct node *head=NULL;
25+
26+
void create_LL(int n)
27+
{
28+
head = new node(); //dynamic allocation of new Node
29+
cout<<"\nEnter Data for Node 1:\n"; //1st element
30+
cin>>head->data;
31+
32+
if(head!=NULL) //rest of the elements
33+
{
34+
struct node *temp,*p=head;
35+
f(i,0,n-1)
36+
{
37+
cout<<"\nEnter Data for Node "<<i+2<<":\n";
38+
struct node *temp=new node();
39+
cin>>temp->data;
40+
p->next=temp;
41+
p=temp;
42+
}
43+
free(temp);
44+
}
45+
}
46+
47+
void display_LL()
48+
{
49+
if(head==NULL)
50+
{
51+
cout<<"\nLinked List is Empty!\n";
52+
}
53+
else
54+
{
55+
struct node *temp=head;
56+
i=0;
57+
while(temp!=NULL)
58+
{
59+
cout<<"\n"<<i+1<<sp<<"->"<<sp<<temp->data;
60+
i++;
61+
temp=temp->next;
62+
}
63+
free(temp);
64+
}
65+
66+
}
67+
68+
main()
69+
{
70+
int n;
71+
cout<<"\nEnter the No. of Nodes you want to Insert:\n";
72+
cin>>n;
73+
if(n!=0)
74+
{
75+
create_LL(n);
76+
}
77+
display_LL();
78+
}

ThanosSort.cpp

Lines changed: 68 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,76 @@
1-
#include<bits/stdc++.h>
2-
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
3-
#define f(i,a,b) for(i=a;i<b;i++)
4-
#define fr(i,a,b) for(i=a;i>=b;i--)
5-
#define endl '\n'
6-
#define ll long long int
7-
#define ff first
8-
#define ss second
9-
#define pb push_back
10-
#define mp make_pair
11-
#define mod 1000000007
1+
#include<iostream>
122
using namespace std;
133

14-
int ar[100],mx=1;
4+
int i;
155

16-
int Sort(int l, int r)
6+
void ThanosS(int a[],int n)
177
{
18-
if(l+1==r)
19-
{
20-
if(ar[l]<=ar[r])
21-
return 2;
22-
return -1;
23-
}
24-
25-
int mid=(l+r)/2;
26-
int x=Sort(l,mid);
27-
int y=Sort(mid+1,r);
28-
mx=max(mx,max(x,y));
29-
if(x>0 and y>0 and ar[mid]<=ar[mid+1])
30-
mx=x+y;
31-
return -1;
8+
int c=1,flag=0,j;
9+
if(n >= 1)
10+
{
11+
for(i=0;i<n;i++)
12+
{
13+
for(j=1;j<n;j++)
14+
{
15+
if(a[i] <= a[j])
16+
{
17+
c++;
18+
}
19+
else
20+
{
21+
flag=1;
22+
n/=2;
23+
break;
24+
}
25+
}
26+
}
27+
}
28+
if(flag==1 && n > 1)
29+
{
30+
ThanosS(a,n);
31+
}
32+
cout<<"\n"<<c;
3233
}
3334

34-
int main()
35+
bool isPower(int x, long int y)
36+
{
37+
if (x == 1)
38+
return (y == 1);
39+
long int pow = 1;
40+
while (pow < y)
41+
pow *= x;
42+
return (pow == y);
43+
}
44+
/*bool isPower(int x, int y)
45+
{
46+
// logarithm function to calculate value
47+
int res1 = log(y) / log(x);
48+
double res2 = log(y) / log(x); // Note : this is double
49+
50+
// compare to the result1 or result2 both are equal
51+
return (res1 == res2);
52+
}*/
53+
54+
main()
3555
{
36-
int n,i,x;
37-
cin>>n;
38-
f(i,0,n)
39-
cin>>ar[i];
40-
x=Sort(0,n-1);
41-
cout<<mx;
56+
int a[100],n,x;
57+
cin>>n;
58+
x=isPower(2,n);
59+
if(x==1)
60+
{
61+
for(i=0;i<n;i++)
62+
{
63+
cin>>a[i];
64+
}
65+
ThanosS(a,n);
66+
/*for(i=0;i<n;i++)
67+
{
68+
cout<<a[i]<<"\t";
69+
}*/
70+
}
71+
/*else
72+
{
73+
cout<<"\nNo. of Elements are not in an order of 2\n";
74+
}*/
75+
4276
}

ThanosSortNeetya.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include<bits/stdc++.h>
2+
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
3+
#define f(i,a,b) for(i=a;i<b;i++)
4+
#define fr(i,a,b) for(i=a;i>=b;i--)
5+
#define endl '\n'
6+
#define ll long long int
7+
#define ff first
8+
#define ss second
9+
#define pb push_back
10+
#define mp make_pair
11+
#define mod 1000000007
12+
using namespace std;
13+
14+
int ar[100],mx=1;
15+
16+
int Sort(int l, int r)
17+
{
18+
if(l+1==r)
19+
{
20+
if(ar[l]<=ar[r])
21+
return 2;
22+
return -1;
23+
}
24+
25+
int mid=(l+r)/2;
26+
int x=Sort(l,mid);
27+
int y=Sort(mid+1,r);
28+
mx=max(mx,max(x,y));
29+
if(x>0 and y>0 and ar[mid]<=ar[mid+1])
30+
mx=x+y;
31+
return -1;
32+
}
33+
34+
int main()
35+
{
36+
int n,i,x;
37+
cin>>n;
38+
f(i,0,n)
39+
cin>>ar[i];
40+
x=Sort(0,n-1);
41+
cout<<mx;
42+
}

a.exe

46.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)