![]() |
k black and k white
I have a problem: Given a chess-board n*n (the user inputs n). In the chess -board there are k black queens and k white queens (requirement: 2 queens with different color cannot beat each other. We don't care about 2 queens with the same color). Find k max?
PHP Code:
|
Re: k black and k white
I have changed the code, but I still cannot display it??
PHP Code:
|
Re: k black and k white
> Is this ok?
Presumably not, because otherwise you wouldn't be posting here. What exactly does the program not do that you want it to, in specific terms? What input do you give and what output did you get, and what output did you expect? |
Re: k black and k white
I not only want to find kmax but also I want to display the chess-board. I run the program for n = 5 but if n> 5, it'll take too much time. Some of my friend can run up to n = 12!!!
|
Re: k black and k white
Could you outline how the code works and the algorithm you use?
|
Re: k black and k white
Sorry I have not made the description!
Outline: 1. A square in the chess-board has 3 properties: the queen in it, can be attacked by how many black queen and how may white ones. 2. We put the black queens and white queens consecutively by using a variable Next to control (if Next is divisible by 2, black goes; else white goes) 3. If the number of white queens equal to the number of black queens and that number is greater than max (max is first assigned as 0) then max is that number. |
Re: k black and k white
Your code doesn't call ShowBoard. Could that be why it doesn't display it?
|
Re: k black and k white
Maybe my problem is not too difficult for many programmers, but to me it is challenging. I have tried ShowBoard function in the function Release (just imitate the Arrange function but put an if (white == black && black == max) then ShowBoard, but this did not work so I did not use it. Can you suggest me some solutions for this?
|
Re: k black and k white
This doesn't make sense. If you've written all the above code then determining where to put a ShowBoard call should be trivial. Have you written it or have you got it all from other people suggesting you some solutions?
But I can't suggest where to put the call to ShowBoard simply because I do not know where you want to put that call. Only you know where you want the board to be shown. Also I'm not sure what you expect would be shown, because after ArrangeQueen has returned, it looks like the board will be full of asterisks (*). Do you want to see 64 asterisks or something else? |
Re: k black and k white
correction: n*n asterisks, not 64.
|
| All times are GMT +5.5. The time now is 11:08. |