|
||||||
| General Programming Non language specific, Assembly, Linux/Unix, Mac and anything not covered in other topics. Talk about Programming Theory here. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
I have to write a program to solve the following problem:
A and B are playing. A thinks of a number between 1 and N. B has to find it out with using only this question: "Is it equal to or lesser than x?" where x is any number between 1 and N. To make things more difficult, a given value belongs to each of the numbers between 1 and N. Whenever B poses his question, he must pay as many dollars as the value that belongs to x. For example, I get this in an input file: Code:
7 1 3 10 1 5 2 6 I have to find out how much does it cost at least to find out any number A can think of (between 1 and the given N of course). There's an example that shows the optimal question sequence (that produces the minimal amount of dollars required to find out any number between 1 and 7). This minimal amount here is 14. The picture below shows the questions (the numbers in circles). The left child is selected when the answer's yes, and the right child when the answer's no. The small numbers outside the circles mean their value. Now how do I create this optimal question sequence (this binary tree)? I only get the input shown above in the CODE box. Thanks for your help! |
| Sponsored Links |
|
|
|
|||||
|
At this point you have only described the game and strategy, but not the desired input/output of your program. Without that, we cannot help you.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum Programming is a branch of mathematics. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Beginning Programming | frank_l | C and C++ | 11 | 10-11-2007 03:23 AM |
| Not sure my college is good for Programming | marta | General Programming | 1 | 08-17-2007 11:13 AM |
| programming not easy! | ToruS | General Programming | 5 | 03-11-2007 02:19 PM |
| WingedPanther | ........ | 2753.6 |
| Xav | ........ | 2704 |
| Brandon W | ........ | 1702.32 |
| John | ........ | 1207.73 |
| marwex89 | ........ | 1175.24 |
| morefood2001 | ........ | 966.05 |
| dcs | ........ | 655.75 |
| Steve.L | ........ | 475.59 |
| orjan | ........ | 418.58 |
| Aereshaa | ........ | 383.54 |
Goal: 100,000 Posts
Complete: 98%