algorithm problem in C++

  • (2 Pages)
  • +
  • 1
  • 2

18 Replies - 530 Views - Last Post: 15 October 2019 - 01:36 PM Rate Topic: **--- 3 Votes

#1 iyaad   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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++

#2 iyaad   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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 :online2long:
Was This Post Helpful? 0
  • +
  • -

#3 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15359
  • View blog
  • Posts: 61,588
  • Joined: 12-June 08

Re: algorithm problem in C++

Posted 12 October 2019 - 08:11 AM

What have you tried?
Was This Post Helpful? 0
  • +
  • -

#4 iyaad   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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.

Was This Post Helpful? 0
  • +
  • -

#5 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15359
  • View blog
  • Posts: 61,588
  • Joined: 12-June 08

Re: algorithm problem in C++

Posted 12 October 2019 - 08:30 AM

Ok... What have you thought about or considered?
Was This Post Helpful? 0
  • +
  • -

#6 Salem_c   User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 2397
  • View blog
  • Posts: 4,530
  • 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.
Was This Post Helpful? 2
  • +
  • -

#7 iyaad   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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.

Was This Post Helpful? 0
  • +
  • -

#8 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15359
  • View blog
  • Posts: 61,588
  • 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?
Was This Post Helpful? 0
  • +
  • -

#9 iyaad   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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.

Was This Post Helpful? 0
  • +
  • -

#10 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15359
  • View blog
  • Posts: 61,588
  • 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.
Was This Post Helpful? 0
  • +
  • -

#11 iyaad   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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.

Was This Post Helpful? 0
  • +
  • -

#12 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15359
  • View blog
  • Posts: 61,588
  • 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!
Was This Post Helpful? 0
  • +
  • -

#13 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7139
  • View blog
  • Posts: 24,245
  • 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.
Was This Post Helpful? 0
  • +
  • -

#14 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15359
  • View blog
  • Posts: 61,588
  • 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 ;) )
Was This Post Helpful? 0
  • +
  • -

#15 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7139
  • View blog
  • Posts: 24,245
  • 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...
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2