# algorithm problem in C++

• (2 Pages)
• 1
• 2

## 18 Replies - 545 Views - Last Post: 15 October 2019 - 01:36 PMRate Topic: 3 Votes //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=417540&amp;s=f4835dac7400c3de87523346b93cb7c0&md5check=' + ipb.vars['secure_hash'], cur_rating: 2, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

Reputation: 0
• Posts: 6
• Joined: 12-October 19

# algorithm problem in C++

Posted 12 October 2019 - 07:54 AM

Polycarp has a cat and his cat is a real gourmet! Dependent on a day of the week he eats certain type of food:

on Mondays, Thursdays and Sundays he eats fish food;
on Tuesdays and Saturdays he eats rabbit stew;
on other days of week he eats chicken stake.
Polycarp plans to go on a trip and already packed his backpack. His backpack contains:

a daily rations of fish food;
b daily rations of rabbit stew;
c daily rations of chicken stakes.
Polycarp has to choose such day of the week to start his trip that his cat can eat without additional food purchases as long as possible. Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally.

Input
The first line of the input contains three positive integers a, b and c (1≤a,b,c≤7⋅108) — the number of daily rations of fish food, rabbit stew and chicken stakes in Polycarps backpack correspondingly.

Output
Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally.

Examples:

input :
```2 1 1
```

output:
```4
```

input :
```3 2 2
```

output:
```7
```

input :
```1 100 1
```

output:
```3
```

input :
```30 20 10
```

output:
```39
```

Is This A Good Question/Topic? 0

## Replies To: algorithm problem in C++

Reputation: 0
• Posts: 6
• Joined: 12-October 19

## Re: algorithm problem in C++

Posted 12 October 2019 - 08:02 AM

I don't know what is the answer, it's very hard and it's for Professionals just

### #3 modi123_1

• Suitor #2

Reputation: 15427
• Posts: 61,796
• Joined: 12-June 08

## Re: algorithm problem in C++

Posted 12 October 2019 - 08:11 AM

What have you tried?

Reputation: 0
• Posts: 6
• Joined: 12-October 19

## Re: algorithm problem in C++

Posted 12 October 2019 - 08:16 AM

Bro , I don't have any idea about the algorithm , how can I tried ?

This post has been edited by Skydiver: 12 October 2019 - 05:39 PM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

### #5 modi123_1

• Suitor #2

Reputation: 15427
• Posts: 61,796
• Joined: 12-June 08

## Re: algorithm problem in C++

Posted 12 October 2019 - 08:30 AM

Ok... What have you thought about or considered?

### #6 Salem_c

• void main'ers are DOOMED

Reputation: 2408
• Posts: 4,542
• Joined: 30-May 10

## Re: algorithm problem in C++

Posted 12 October 2019 - 08:32 AM

> Bro , I don't have any idea about the algorithm , how can I tried ?
And how do you expect to fare in the real world, where the problems are incomplete, poorly specified and usually contradictory?

https://codeforces.c.../problem/1154/C

All the problems on all the quiz sites begin with pencil and paper, not a source code editor.

You start with trivial examples like 1 1 1 and you try to understand why the answer is what it is.

It's all about recognising the pattern of the solution.
When you know that, the code is usually pretty simple.

Reputation: 0
• Posts: 6
• Joined: 12-October 19

## Re: algorithm problem in C++

Posted 12 October 2019 - 08:57 AM

modi123_1:
My only difficulty is my starting point
For example from any day start count

Salem_c:
okay ,I appreciate your suggested , I want you to help me by give me some information that may help me in making my algorithm , not source code

This post has been edited by Skydiver: 12 October 2019 - 05:42 PM
Reason for edit:: Remove unnecessary quotes. No need to quote the post above yours.

### #8 modi123_1

• Suitor #2

Reputation: 15427
• Posts: 61,796
• Joined: 12-June 08

## Re: algorithm problem in C++

Posted 12 October 2019 - 08:58 AM

What's difficult with that?

Is it thinking how to map a number to a day? Sunday = 1, Monday = 2, etc? and doing that logical translation?

Reputation: 0
• Posts: 6
• Joined: 12-October 19

## Re: algorithm problem in C++

Posted 12 October 2019 - 09:22 AM

some thing like that !
If the man has two meals of fish, one of chicken and one of rabbits, then how can I assign a reference point. For example; from which day counting should start? If we choose Wednesday, an error will occur in the number of days and he will have an extra amount, but if we choose Sunday, the answer will be correct.

This post has been edited by Skydiver: 12 October 2019 - 05:40 PM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

### #10 modi123_1

• Suitor #2

Reputation: 15427
• Posts: 61,796
• Joined: 12-June 08

## Re: algorithm problem in C++

Posted 12 October 2019 - 09:33 AM

Sounds like you would need to test out seven days to find the best solution given the food input.

Reputation: 0
• Posts: 6
• Joined: 12-October 19

## Re: algorithm problem in C++

Posted 12 October 2019 - 09:38 AM

yeah

This post has been edited by Skydiver: 12 October 2019 - 05:40 PM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

### #12 modi123_1

• Suitor #2

Reputation: 15427
• Posts: 61,796
• Joined: 12-June 08

## Re: algorithm problem in C++

Posted 12 October 2019 - 09:50 AM

So maybe a loop or even some delicious recursion!

### #13 Skydiver

• Code herder

Reputation: 7187
• Posts: 24,356
• Joined: 05-May 12

## Re: algorithm problem in C++

Posted 12 October 2019 - 10:27 AM

iyaad: There is no need to quote the post above yours. Just use the big Reply button or the Fast Reply area.

### #14 modi123_1

• Suitor #2

Reputation: 15427
• Posts: 61,796
• Joined: 12-June 08

## Re: algorithm problem in C++

Posted 12 October 2019 - 10:34 AM

That was a fun problem. Ultimately I wrapped a WHILE loop in a FOR loop.. the FOR loop to increment each day to test if it is 'the best'.. and the while loop to hash out the has food, remove food, increment temporary day bits.

If I did my code correctly, and ignore inputs, the f: 30, r: 20, c: 10
best starts on a Saturday and has a max days of greater than 35! (not going to give away that answer yet )

### #15 Skydiver

• Code herder

Reputation: 7187
• Posts: 24,356
• Joined: 05-May 12

## Re: algorithm problem in C++

Posted 13 October 2019 - 11:51 AM

Fun little problem. It's easy to solve with the brute force while and for loops, but it's hard to satisfy the 1 second time limit when f: 700000000, r:700000000, c:700000000. Need to think about this some more...