Pascal HELP.... please :) – Pascal – Fórum – Programujte.com
 x   TIP: Přetáhni ikonu na hlavní panel pro připnutí webu
Reklama
Reklama

Pascal HELP.... please :) – Pascal – Fórum – Programujte.comPascal HELP.... please :) – Pascal – Fórum – Programujte.com

 

Hledá se programátor! Plat 1 800 € + bonusy (firma Boxmol.com)
Misha
~ Anonymní uživatel
3 příspěvky
15. 6. 2008   #1
-
0
-

Hi, ok... Here's the story- I have been absent from my Pascal programming class for 3 weeks, I came back and now the teacher wants me to try out a few programs for a test tomorrow. I have one that I have no idea how to do...

Here are the directions:
"Mr.Paul has an amusement park. On one ride, there are many different cabins painted different colors. Since the colors evoke different emotions, each cabin is priced individually.
A group of friends want to ride Mr.Paul's cabin ride. They want to sit together, or in cabins right next to each other.
The amount of friends: N
The capacity of one cabin: K
The amount of cabins: M

Now, the program will get these numbers from a file on the desktop (the file should have N,K,M separated by a space, plus the $$ amount each cabin costs), then it should calculate how many cabins are needed, then which combination is the cheapest for the friends.
So, for an example:
Input: 7 2 10
80 70 40 90 100 60 70 80 80 50
Output:
240

Good luck!"

Ok, so I have absolutely no idea.
I wanted to ask you for help- please please please if anyone knows how to make this program, don't hesitate to write at least a little part of it.
Thank you!!!!

Nahlásit jako SPAM
IP: 85.70.181.–
Reklama
Reklama
Mircosoft+1
Věrný člen
15. 6. 2008   #2
-
0
-

Hmm... why not use brute force? You may try every possible combination and keep trace of the cheapest one. So you have four things to do:

1) Generate the combinations.
2) Check if a given combination is valid.
3) Calculate the price for a given combination.
4) Compare every calculated price with the one we remember and then remember the lower one (together with the combination).

Which of them is the biggest problem?

Nahlásit jako SPAM
IP: 89.176.249.–
Chceš-li lepší odpověď, polož lepší otázku.
Moje stránka.
Misha
~ Anonymní uživatel
3 příspěvky
15. 6. 2008   #3
-
0
-

To Mircosoft : Exactly what I thought of... But I have no idea which commands I should use... For example, the number of cabins changes with every use of the program, so what kind of function can I use to calculate this?
If we calculate (add the cabins next to each other- every possible combination), then we can just use something like "if a>b then..."?
(Thank you so much :))

Nahlásit jako SPAM
IP: 85.70.181.–
Misha
~ Anonymní uživatel
3 příspěvky
15. 6. 2008   #4
-
0
-

To Mircosoft [#76984]: I have to go to bed (I'm only 16, so I have a bed time :)), I guess I will just tell the teacher that I couldn't come up with it.
Thank you very much anyway...

When you have time, could you please just post the command that I should use? That way I can ask her to explain that to me?
Thanks!!

Nahlásit jako SPAM
IP: 85.70.181.–
Mircosoft+1
Věrný člen
16. 6. 2008   #5
-
0
-

Commands? You will need Assign, Reset, Read, Readln and Close to read from a file (text file, I suppose). And a variable of type Text. Then some conditions (If), loops (For, While, Repeat) and something to compose the program of (Program, Begin, End, basic operators (:=, =, <>, and, or...) etc.).

I was thinking about the implementation. It's not so easy how it looked at first :-).
First idea:
You have some number of cabins and some seats in each of them. Store them into an array, where each element means one cabin (key words: array, record). Keep their number of seats, price, starting index (will explain later) and number of seats currently occupied.
Upon reading the input, you get the number of cabins. Keep this number - you will need it to run For loops. The array itself can be much bigger and doesn't have to be completely used-up, you just start with index 1 and end with previously read NumberOfCabins.

Then you have an array of booleans, one for every seat. True means occupied, false means non-occupied. Here you generate the combinations: just switch the bools in the way how bits in a number switch when the number is incremented:
FFFFFFFF...
TFFFFFFF...
FTFFFFFF...
TTFFFFFF...
FFTFFFFF...
TFTFFFFF...
Here's what that starting index of cabin is: first cabin will start with first seat. If it has 3 seats, the second cabin will begin on index 4. With 5 seats, the third will begin on index 3+5+1. And so on, like words in a string without spaces: 1112222233344444555555555
Again, the real size of this array must be greater than any possible total number of seats, use some variable to store actual value of max. index to this array.

Checking whether the combination is valid means that you go through array of cabins, take each one's starting index and number of seats and then count according trues (= occupied seats) in that boolean array. Store the counts to cabin array. When finished, go through the cabins again and determine whether there are any gaps - interval of empty cabins surrounded by non-empty cabins. If there are, combination is invalid. Also if total number of trues is not equal to the number of friends.

Then multiply number of occupied seats and price in each cabin, sum it together and you get total price. Compare it with lowest value you found till now and if it's lower, save it instead of the old one. And save the configuration of seats (that boolean array) too.

Then take another combination and do everything again, until all elements in the boolean array are true.


P.S.: Surely it can be done in some faster and more ingenious way, but I have no idea how at this moment.

Nahlásit jako SPAM
IP: 147.32.160.–
Chceš-li lepší odpověď, polož lepší otázku.
Moje stránka.
Zjistit počet nových příspěvků

Přidej příspěvek

Toto téma je starší jak čtvrt roku – přidej svůj příspěvek jen tehdy, máš-li k tématu opravdu co říct!

Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku

×Vložení zdrojáku

×Vložení obrázku

Vložit URL obrázku Vybrat obrázek na disku
Vlož URL adresu obrázku:
Klikni a vyber obrázek z počítače:

×Vložení videa

Aktuálně jsou podporována videa ze serverů YouTube, Vimeo a Dailymotion.
×
 
Podporujeme Gravatara.
Zadej URL adresu Avatara (40 x 40 px) nebo emailovou adresu pro použití Gravatara.
Email nikam neukládáme, po získání Gravatara je zahozen.
-
Pravidla pro psaní příspěvků, používej diakritiku. ENTER pro nový odstavec, SHIFT + ENTER pro nový řádek.
Sledovat nové příspěvky (pouze pro přihlášené)
Sleduj vlákno a v případě přidání nového příspěvku o tom budeš vědět mezi prvními.
Reaguješ na příspěvek:

Uživatelé prohlížející si toto vlákno

Uživatelé on-line: 0 registrovaných, 15 hostů

Podobná vlákna

Pascal: kurz turbo pascal II — založil Systém

Pascal — založil Filip

Pascal — založil Lasserus

Moderátoři diskuze

 

Hostujeme u Českého hostingu       ISSN 1801-1586       ⇡ Nahoru Webtea.cz logo © 20032016 Programujte.com
Zasadilo a pěstuje Webtea.cz, šéfredaktor Lukáš Churý