Skip to content

Commit 7d5c267

Browse files
authored
Add files via upload
1 parent 43fbb66 commit 7d5c267

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

greedy/activity_selection.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
void printactivity(int s[],int f[],int n)
5+
{
6+
int i=0;
7+
int temp=f[i];
8+
cout<<"activity selected is "<<i<<" ";
9+
for(int j=1;j<n;j++)
10+
{
11+
temp=f[i];
12+
if(s[j]>=temp)
13+
{
14+
cout<<j<<" ";
15+
i=j;
16+
}
17+
}
18+
}
19+
int main()
20+
{
21+
int s[]={1,3,0,5,8,5};
22+
int f[]={2,4,6,7,9,9};
23+
int n=(sizeof(f)/sizeof(f[0]));
24+
printactivity(s,f,n);
25+
}

greedy/egyptian_fraction.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
written by pankaj kumar.
3+
*/
4+
#include<iostream>
5+
#include<vector>
6+
#include<cmath>
7+
#include<set>
8+
#include<algorithm>
9+
#include<string.h>
10+
#define pan cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
11+
#define mod 1000000007;
12+
using namespace std;
13+
typedef long long ll ;
14+
#define line cout<<endl;
15+
16+
void egyptian(int a,int b)
17+
{
18+
if(a==1)
19+
cout<<"1/"<<b<<" ";
20+
else
21+
{
22+
int hcf,temp;
23+
// don't do here.
24+
// temp=ceil(b/a);
25+
temp=ceil(b/(a*1.0));
26+
cout<<"1/"<<temp<<" ";
27+
hcf=__gcd(a*temp-b,b*temp);
28+
egyptian((a*temp-b)/hcf,(b*temp)/hcf);
29+
}
30+
}
31+
32+
33+
int main()
34+
{
35+
pan;
36+
int a,b;
37+
cout<<"Enter two no ";
38+
cin>>a>>b;
39+
egyptian(a,b);
40+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy