Bnuoj 4299 God Save the i-th Queen (idea title)

Source: Internet
Author: User

Topic link = = "http://www.bnuoj.com/v3/problem_show.php?pid=4299

Test instructions: A x*y on the chessboard put N Queens, and then put a queen, there are a few spaces can be placed, if and already on the board of Queen different rows of different columns of different slashes

Idea: Each point in the four straight lines, can not be put queen, so a bit of the line mark, and then traverse all points, if the point where the line has been marked, it is not selected. Finished

Code:

1#include <stdio.h>2#include <string.h>3#include <algorithm>4#include <iostream>5 6 using namespacestd;7 8 Const intt=4e4+9;9 Ten intH[T],L[T],XIE_1[T],XIE_2[T];///Xie_1 represents a straight line with a slope greater than 0 One intsum,n,m; A  - voidbegin1 () - { thesum=0; -memset (H,0,sizeof(int)*T); -memset (L,0,sizeof(int)*T); -memset (Xie_1,0,sizeof(int)*T); +memset (xie_2,0,sizeof(int)*T); - } +  A voidJudgeintXinty) at { -     intW; -h[x]=1; l[y]=1; -xie_1[x+y+1]=1; -w=m+1-Y;///mark the board with a negative slope, the column label is inverted, from m-->1, so the line is also L (x+w+1) . -xie_2[x+w+1]=1; in } -  to voidJudge_two (intXinty) + { -     intw=m+1-y; the     if(H[x] | | l[y] | | xie_1[x+y+1] || xie_2[x+w+1] ) *         return ; $sum++;Panax Notoginseng  - } the  +  A  the  + intMain () - { $     intk,a,b; $      while(SCANF ("%d%d%d", &n,&m,&k), (n+m+k)) -     { - begin1 (); the          for(intI=1; i<=k;i++) -         {Wuyiscanf"%d%d",&a,&b); the judge (A, b); -         } Wu          for(intI=1; i<=n;i++) -              for(intj=1; j<=m;j++) About Judge_two (i, j); $printf"%d\n", sum); -     } -     return 0; -}
View Code

Bnuoj 4299 God Save the i-th Queen (idea title)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.