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 7d5c267

Browse filesBrowse files
authored
Add files via upload
1 parent 43fbb66 commit 7d5c267
Copy full SHA for 7d5c267

File tree

2 files changed

+65
-0
lines changed
Filter options

2 files changed

+65
-0
lines changed

‎greedy/activity_selection.cpp

Copy file name to clipboard
+25Lines 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

Copy file name to clipboard
+40Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.