Skip to content

Commit 3fe730d

Browse files
authored
Merge pull request ashutosh97#132 from Artistic18/master
Added Bytelandian Gold Coins
2 parents fc558d1 + 5262e5a commit 3fe730d

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
In Byteland they have a very strange monetary system.
2+
3+
Each Bytelandian gold coin has an integer number written on it. A coin n can be exchanged in a bank into three coins: n/2, n/3 and n/4. But these numbers are all rounded down (the banks have to make a profit).
4+
5+
You can also sell Bytelandian coins for American dollars. The exchange rate is 1:1. But you can not buy Bytelandian coins.
6+
7+
You have one gold coin. What is the maximum amount of American dollars you can get for it?
8+
Input
9+
10+
The input will contain several test cases (not more than 10). Each testcase is a single line with a number n, 0 <= n <= 1 000 000 000. It is the number written on your coin.
11+
Output
12+
13+
For each test case output a single line, containing the maximum amount of American dollars you can make.
14+
15+
Example
16+
17+
Input:
18+
12
19+
2
20+
21+
Output:
22+
13
23+
2
24+
25+
You can change 12 into 6, 4 and 3, and then change these into $6+$4+$3 = $13.
26+
If you try changing the coin 2 into 3 smaller coins, you will get 1, 0 and 0, and later you can get no more than $1 out of them.
27+
It is better just to change the 2 coin directly into $2.

Bytelandian-gold-coins/solution.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
map<int,long long> dp;
4+
long long optcoins(int n){
5+
if(n<12)
6+
return n;
7+
if(dp.count(n))
8+
return dp[n];
9+
dp[n]=optcoins(n/2)+optcoins(n/3)+optcoins(n/4);
10+
return dp[n];
11+
}
12+
int main(){
13+
int x;
14+
while(scanf("%d",&x)!=EOF)
15+
printf("%lld\n",optcoins(x));
16+
return 0;
17+
}

Philosophers_Stone/question.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
3+
One of the secret chambers in Hogwarts is full of philosopher’s stones. The floor of the chamber is covered by h × w square tiles, where there are h rows of tiles from front (first row) to back (last row) and w columns of tiles from left to right. Each tile has 1 to 100 stones on it. Harry has to grab as many philosopher’s stones as possible, subject to the following restrictions:
4+
5+
He starts by choosing any tile in the first row, and collects the philosopher’s stones on that tile. Then, he moves to a tile in the next row, collects the philosopher’s stones on the tile, and so on until he reaches the last row.
6+
When he moves from one tile to a tile in the next row, he can only move to the tile just below it or diagonally to the left or right.
7+
8+
Given the values of h and w, and the number of philosopher’s stones on each tile, write a program to compute the maximum possible number of philosopher’s stones Harry can grab in one single trip from the first row to the last row.
9+
Input
10+
11+
The first line consists of a single integer T, the number of test cases. In each of the test cases, the first line has two integers. The first integer h (1 <= h <= 100) is the number of rows of tiles on the floor. The second integer w (1 <= w <= 100) is the number of columns of tiles on the floor. Next, there are h lines of inputs. The i-th line of these, specifies the number of philosopher’s stones in each tile of the i-th row from the front. Each line has w integers, where each integer m (0 <= m <= 100) is the number of philosopher’s stones on that tile. The integers are separated by a space character.
12+
Output
13+
14+
The output should consist of T lines, (1 <= T <= 100), one for each test case. Each line consists of a single integer, which is the maximum possible number of philosopher’s stones Harry can grab, in one single trip from the first row to the last row for the corresponding test case.
15+
Example
16+
17+
Input:
18+
1
19+
6 5
20+
3 1 7 4 2
21+
2 1 3 1 1
22+
1 2 2 1 8
23+
2 2 1 5 3
24+
2 1 4 4 4
25+
5 2 7 5 1
26+
27+
Output:
28+
32
29+
30+
//7+1+8+5+4+7=32

Philosophers_Stone/solution.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
int main(void)
4+
{
5+
int t;
6+
cin>>t;
7+
while(t--)
8+
{
9+
int r,c;
10+
cin>>r>>c;
11+
int arr[r][c+2]={0};
12+
arr[0][c+1]=0;
13+
14+
for(int i=0;i<r;i++)
15+
for(int j=1;j<=c;j++)
16+
cin>>arr[i][j];
17+
18+
for(int i=r-2;i>=0;i--)
19+
for(int j=1;j<=c;j++)
20+
arr[i][j]+=max((arr[i+1][j-1]),max(arr[i+1][j],arr[i+1][j+1]));
21+
22+
int max = INT_MIN;
23+
for(int i=1;i<=c;i++)
24+
if(arr[0][i]>max)
25+
max = arr[0][i];
26+
27+
cout<<max<<"\n";
28+
}
29+
}

0 commit comments

Comments
 (0)