Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b05ee70

Browse filesBrowse files
committed
update
1 parent bb0cda5 commit b05ee70
Copy full SHA for b05ee70

12 files changed

+1016
-0
lines changed
+102Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
typedef long long ll ;
8+
typedef vector<ll> vl;
9+
typedef vector<bool> vb;
10+
typedef vector<char> vc;
11+
typedef map<ll,ll> ml;
12+
typedef set<char>sc;
13+
typedef set<ll> sl;
14+
#define pan cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
15+
// define values.
16+
// #define mod 1000000007
17+
#define phi 1.618
18+
/* Bit-Stuff */
19+
#define get_set_bits(a) (__builtin_popcount(a))
20+
#define get_set_bitsll(a) ( __builtin_popcountll(a))
21+
#define get_trail_zero(a) (__builtin_ctz(a))
22+
#define get_lead_zero(a) (__builtin_clz(a))
23+
#define get_parity(a) (__builtin_parity(a))
24+
/* Abbrevations */
25+
#define ff first
26+
#define ss second
27+
#define mp make_pair
28+
#define line cout<<endl;
29+
#define pb push_back
30+
#define Endl "\n"
31+
// loops
32+
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
33+
// Some print
34+
#define no cout<<"NO"<<endl;
35+
#define yes cout<<"YES"<<endl;
36+
#define cc ll test;cin>>test;while(test--)
37+
// sort
38+
#define all(V) (V).begin(),(V).end()
39+
#define srt(V) sort(all(V))
40+
#define srtGreat(V) sort(all(V),greater<ll>())
41+
// function
42+
43+
ll power(ll x,ll y,ll mod)
44+
{
45+
ll res=1;
46+
// x=x%mod;
47+
while(y>0)
48+
{
49+
if(y%2==1)
50+
{
51+
res*=x;
52+
// res=res%mod;
53+
}
54+
y/=2; x*=x; // x=x%mod;
55+
}
56+
return res;
57+
}
58+
/* ascii value
59+
A=65,Z=90,a=97,z=122
60+
*/
61+
/* -----------------------------------------------------------------------------------*/
62+
63+
ll hcf(ll a,ll b,ll& x,ll& y)
64+
{
65+
if(b==0)
66+
{
67+
x=1,y=0;
68+
return a;
69+
}
70+
ll x1,y1;
71+
ll ans=hcf(b,a%b,x1,y1);
72+
x=y1;
73+
y=x1-(a/b)*y1;
74+
return ans;
75+
}
76+
77+
ll solve()
78+
{
79+
ll a,b;
80+
cin>>a>>b;
81+
ll x,y;
82+
cout<<"hcf is "<<hcf(a,b,x,y)<<" and both coefficient is "<<x<<" "<<y<<endl;
83+
return 0;
84+
}
85+
86+
int main()
87+
{
88+
//freopen("input.txt"a, "r", stdin);
89+
pan;
90+
solve();
91+
// cc
92+
// {
93+
// solve();
94+
// }
95+
return 0;
96+
}
97+
98+
/* stuff you should look before submission
99+
* int overflow
100+
* special test case (n=0||n=1||n=2)
101+
* don't get stuck on one approach if you get wrong answer
102+
*/

‎Cp_algorithm/a.out

Copy file name to clipboard
19.9 KB
Binary file not shown.

‎best_approach/fibonacci_number.cpp

Copy file name to clipboard
+94Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
// policy based ds
8+
#include<ext/pb_ds/assoc_container.hpp>
9+
#include<ext/pb_ds/tree_policy.hpp>
10+
using namespace __gnu_pbds;
11+
typedef long long ll ;
12+
typedef vector<ll> vl;
13+
typedef vector<bool> vb;
14+
typedef vector<char> vc;
15+
typedef map<ll,ll> ml;
16+
#define pan cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
17+
// define values.
18+
#define mod 10000009
19+
#define phi 1.618
20+
/* Bit-Stuff */
21+
#define get_set_bits(a) (__builtin_popcount(a))
22+
#define get_set_bitsll(a) ( __builtin_popcountll(a))
23+
#define get_trail_zero(a) (__builtin_ctz(a))
24+
#define get_lead_zero(a) (__builtin_clz(a))
25+
#define get_parity(a) (__builtin_parity(a))
26+
/* Abbrevations */
27+
#define ff first
28+
#define ss second
29+
#define mp make_pair
30+
#define line cout<<endl;
31+
#define pb push_back
32+
#define Endl "\n"
33+
// loops
34+
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
35+
// Some print
36+
#define no cout<<"NO"<<endl;
37+
#define yes cout<<"YES"<<endl;
38+
#define cc ll test;cin>>test;while(test--)
39+
// sort
40+
#define all(V) (V).begin(),(V).end()
41+
#define srt(V) sort(all(V))
42+
#define srtGreat(V) sort(all(V),greater<ll>())
43+
// function
44+
45+
ll power(ll x,ll y)
46+
{
47+
ll res=1;
48+
// x=x%mod;
49+
while(y>0)
50+
{
51+
if(y%2==1)
52+
{
53+
res*=x;
54+
// res=res%mod;
55+
}
56+
y/=2; x*=x; // x=x%mod;
57+
}
58+
return res;
59+
}
60+
// datatype definination
61+
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
62+
63+
/* ascii value
64+
A=65,Z=90,a=97,z=122
65+
*/
66+
/* -----------------------------------------------------------------------------------*/
67+
68+
// time complexity of this algorithm is O(logn)
69+
const int MAX = 1000;
70+
int f[MAX] = {0};
71+
72+
int fib(ll n)
73+
{
74+
if (n == 0)
75+
return 0;
76+
if (n == 1 || n == 2)
77+
return (f[n] = 1);
78+
if (f[n])
79+
return f[n];
80+
81+
ll k = (n & 1)? (n+1)/2 : n/2;
82+
f[n] = (n & 1)? (fib(k)*fib(k) + fib(k-1)*fib(k-1))
83+
: (2*fib(k-1) + fib(k))*fib(k);
84+
85+
return f[n];
86+
}
87+
88+
int main()
89+
{
90+
ll n;
91+
cin>>n;
92+
cout<<ll(fib(n))<<endl;
93+
return 0;
94+
}

‎dp algo/0-1_knap.cpp

Copy file name to clipboard
+121Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
typedef long long ll ;
8+
typedef set<pair<int,int>> spi;
9+
typedef set<pair<ll,ll>> spl;
10+
typedef vector<pair<int,int>> vpi;
11+
typedef vector<int> vi;
12+
typedef vector<ll> vl;
13+
typedef vector<bool> vb;
14+
typedef vector<char> vc;
15+
typedef vector<pair<ll,ll>> vpl;
16+
typedef vector<string> vs;
17+
typedef map<int,int>mi;
18+
typedef map<ll,ll> ml;
19+
typedef set<string> ss;
20+
typedef set<char>sc;
21+
typedef set<int> si;
22+
typedef set<ll> sl;
23+
#define pan cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
24+
// define values.
25+
#define mod 1e9+7LL
26+
#define phi 1.618
27+
/* Bit-Stuff */
28+
#define get_set_bits(a) (__builtin_popcount(a))
29+
#define get_set_bitsll(a) ( __builtin_popcountll(a))
30+
#define get_trail_zero(a) (__builtin_ctz(a))
31+
#define get_lead_zero(a) (__builtin_clz(a))
32+
#define get_parity(a) (__builtin_parity(a))
33+
/* Abbrevations */
34+
#define ff first
35+
#define ss second
36+
#define mp make_pair
37+
#define line cout<<endl;
38+
#define pb push_back
39+
#define Endl "\n"
40+
// loops
41+
#define loop(i,start,end) for(ll i=ll(start);i<ll(end);i++)
42+
#define loop0(num) for(ll i=0;i<ll(num);i++)
43+
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
44+
// Some print
45+
#define no cout<<"NO"<<endl;
46+
#define yes cout<<"YES"<<endl;
47+
#define cc ll test;cin>>test;while(test--)
48+
// sort
49+
#define all(V) (V).begin(),(V).end()
50+
#define srt(V) sort(all(V))
51+
#define srtGreat(V) sort(all(V),greater<ll>())
52+
// function
53+
54+
ll power(ll x, ll y, ll p)
55+
{
56+
ll res = 1;
57+
x = x % p;
58+
while (y > 0)
59+
{
60+
if (y & 1)
61+
res = (res*x) % p;
62+
y = y>>1;
63+
x = (x*x) % p;
64+
}
65+
return res;
66+
}
67+
/* ascii value
68+
A=65,Z=90,a=97,z=122 1=49
69+
*/
70+
/* -----------------------------------------------------------------------------------*/
71+
// freopen("input.txt", "r", stdin);
72+
// freopen("output.txt", "w", stdout);
73+
74+
75+
int main()
76+
{
77+
cout<<"No of object : ";
78+
ll n;
79+
cin>>n;
80+
cout<<"Enter profit : ";
81+
vl profit(n+1,0),weight(n+1,0);
82+
ll temp=0;
83+
for(ll i=1;i<=n;i++)
84+
{
85+
cin>>temp;
86+
profit[i]=temp;
87+
}
88+
cout<<"Enter weight now : ";
89+
loop(i,1,n+1)
90+
cin>>weight[i];
91+
cout<<"Enter size of bucket : ";
92+
ll size=0;
93+
cin>>size;
94+
ll arr[n+1][size+1];
95+
loop(i,0,n+1)
96+
{
97+
loop(j,0,size+1)
98+
{
99+
if(i==0||j==0)
100+
{
101+
arr[i][j]=0;
102+
}
103+
else
104+
{
105+
if(j>=weight[i])
106+
arr[i][j]=max(arr[i-1][j],profit[i]+arr[i-1][j-weight[i]]);
107+
else
108+
arr[i][j]=arr[i-1][j];
109+
}
110+
}
111+
}
112+
cout<<"matrix look like "<<endl;
113+
loop(i,0,n+1)
114+
{
115+
loop(j,0,size+1)
116+
{
117+
cout<<arr[i][j]<<" ";
118+
}
119+
line;
120+
}
121+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.