|
|
I have been trying to solve this problem for several days, but suddenly I ran out of ideas. Could you give me some hints on the task? I have tried brute force and some pruning, but it got TLE. I would be really happy! :) I've got AC! The main observation is that no two queens can be in the same row or column. Thus, we make an array perm[i], which stands for queen in the ith row and perm[i]th column. The problem is to find the number of permutations, which differs from the initial by 3 elements and check for each possibility whether we have conflicts on the diagonals. perm[i] is the initial permutation. I hope this hint was helpful! All the X of the input are difference. (Maybe Y are different too. I haven't tried That means, the following test won't exist: ----- 4 1 1 2 3 2 2 4 4 ----- This may be important for you to solve this question more easily (at least for me, my code won't work that situation and get AC in 0.031s though) Good luck! how could it have been passed??? and with 0.031 because of the test cases are to easy.... you can use (next_permutation) easyly... I was not attentive reading this problem's situations, so I did not pay enough attention to the fact, that EXACTLY three queens should be rearranged. My first solution did count situations, when only two queens were moved... It produced a WA (-: Well, i think that you can simulate the 2 movements rearrangement, with exactly 3 queens, i think this problem statement should be clarified in that sense. If you have a queen "a" in position 0 0, another "b" in position 1 1 and a last "c" in position 2 2... in a N=3 chessboard, you can put a in position 1 2, b in position 0 0 and c in position 2 1. Its like a 2 queens movement, but i moved 3 queens. This test is incorrect because queen "a" attacks "b" Edited by author 15.03.2010 20:52 This hint has helped me to AC.thx 50 authors lost AC after rejudge. 9 1 1 2 3 3 6 4 8 5 2 6 4 7 9 8 7 9 5 Analyze this test answer is 2 you must count combinations of y and x.Do this on paper that helps me and i got AC My program is O(n^3). I think n can be added to 100. Should cut branch? Ireally don't think so... hi! really i can't understand it. who can explain it to me with some examples, please!! thanks!! > Post your source code or email me personally if you intend to have a faster time being recorded. Email me to drajmsadeq@yahoo.com How can you solve it? I got TLE! - 9 1 1 2 3 3 6 4 8 5 2 6 4 7 9 8 7 9 5 the answer is 2 good luck You are great !!! How can you find such a great test,i am no idea of searching,thank you your good test help me much,much... > 9 > 1 1 > 2 3 > 3 6 > 4 8 > 5 2 > 6 4 > 7 9 > 8 7 > 9 5 > > the answer is 2 > good luck > > 9 > > 1 1 > > 2 3 > > 3 6 > > 4 8 > > 5 2 > > 6 4 > > 7 9 > > 8 7 > > 9 5 > > > > the answer is 2 > > good luck > > 9 > > 1 1 > > 2 3 > > 3 6 > > 4 8 > > 5 2 > > 6 4 > > 7 9 > > 8 7 > > 9 5 > > > > the answer is 2 > > good luck Sorry, I still don't know what the 2 answers are , Could sb tell me? You should move 1st 2nd and 7th Queen. 1st 2nd and 8th Queen. |
|
|