HELP! C++ applied problem

Status
Not open for further replies.
I've gotta finish a program by tomorrow (didn't procrastinate, it's just due tomorrow) and the program is supposed to be like a voting simulation. Now part of this voting simulation uses something called the "Tideman method." I'm not sure i completely understand what it's asking for, although the routine i've written works for one example, it doesn't with the rest of them. Does anyone know what this is and the exact algorithm in figuring out the vote? I'll put this up for now and the exact words and maybe the example so you can see how confusing this is (in addition the algorithm i'm using so you can see what i'm trying to do).
 
I suppose it's not necessary to know all the details to figure out a working solution, but here's how it goes. You get a 4x4 matrix of numbers, which are the voting pairs. For example:
code:<HR>
Code:
   A   B   C   D
A  \   40  22  13<P>B  37  \   50  50<P>C  30  35  \   25<P>D  20  60  20  \

Comparisons are always made along opposite pairs. So to normally determine the winner of a given match up, lets say between A and B, we look at A's vote against B which would be in the A row B column (40). Then you compare that against the row column flipflop, that is B's vote against A or the B row A column (37). Since 40 is bigger than 37, A is considered the match winner.

Using that method, we can make a list of all the pair ups and the winning quantities. So if we go through the entire matrix, we would find the following values (notation of X beats Y by some number #== X/Y#): A/B40, C/A30, D/A20, B/C50, D/B60, C/D25.

Now the tideman method tells us we need to arrange these numbers in descending order, easy enough: D/B60, B/C50, A/B40, C/A30, C/D25, D/A20

OK, now THIS is the tricky part which i don't think i understand. It says we can eliminate these pairs by looking for cycles. A cycle is defined any triplet where given X,Y,Z can be anything, this (X,Y) (Y,Z) and (Z,X) exists. In order to do triplet elimination like that, it also appears that you start from the third number on the list (A/B40) and check for the triplet in numbers above it. You can see no triplet for A/B exists (that requires A/B B/x x/A to appear in the top three). When you're done checking, you move one step down and repeat the same method, checking for triplets in the pairings above it. If there is a triplet (in the case of C/A30 A/B40 B/C50), you delete that element. This means C/A30 is taken off the list. Now this is repeated until you reach the end of the list and that produces the following: D/B60, B/C50, A/B40, D/A20

Since the winners are {D, B, A, D}, D is considered unbeaten and is the winning candidate. This is the algorithm i used in my program, but it doesn't seem to work for this matrix:

code:<HR>
Code:
   A   B   C   D
A  \   63  89  57<P>B  87  \   20  25<P>C  30  35  \   40<P>D  45  50  60  \

My program says the winner is D (and when i do it by hand, it is also D, so the program is reflecting what i am doing). However the answer is B. How is this possible? Perhaps i'll put the program source up too, but it's real messy and i suppose you'll have to compile it to see what's going on.
 
Sorry, perhaps i wasn't clear, but what i wanted to know is if anyone can get the answer they got and if so, what did i do wrong in my algorithm? :confused:

<edit> Nevermind, i got it. Apparently, B was the only one of the pairs where no other pair claims to beat it and thus that is considered the winner. Feel free to lock this thread. :oops: </edit>

[This message was edited by Nikolai(km) on March 21, 2001 at 02:09.]
 
Status
Not open for further replies.