10401-Injured Queen Problem

Source: Internet
Author: User

[Cpp]
Description: dizzy. It is always wrong Because gets is used to read the string, but it is correct to read it with scanf. It is speechless. There is a string. The length of the string len represents a matrix of len * len ,? This indicates that a queen can be placed in a row of people in this column. The Queen can only attack one column and target the places around it. numbers and letters are hexadecimal and are represented by n, indicates that there must be a queen in row n of this column. That is to say, this column has been determined to only have this queen.
# Include <cstdio>
# Include <cstring>
# Include <cstdlib>
Long v [20] [20];
Int main ()
{
// Freopen ("a.txt", "r", stdin );
Int len;
Int arr [20];
Char s [50];
Long sum;
While (scanf ("% s", s )! = EOF)
{
Len = strlen (s );
For (int I = 0; I <len; I ++)
If (s [I] = '? ') Arr [I + 1] = 0;
Else if (s [I]> = '1' & s [I] <= '9') arr [I + 1] = s [I]-'0 ';
Else if (s [I]> = 'A' & s [I] <= 'F ') arr [I + 1] = s [I]-'A' + 10;
Memset (v, 0, sizeof (v ));
If (! Arr [1]) for (int I = 1; I <= len; I ++) v [I] [1] = 1;
Else v [arr [1] [1] = 1;
For (int I = 2; I <= len; I ++)
If (! Arr [I])
{
For (int j = 1; j <= len; j ++)
For (int k = 1; k <= len; k ++)
If (abs (k-j)> 1) v [j] [I] + = v [k] [I-1];
}
Else
{
For (int k = 1; k <= len; k ++)
If (abs (k-arr [I])> 1) v [arr [I] [I] + = v [k] [I-1];
}
Sum = 0;
For (int I = 1; I <= len; I ++) sum + = v [I] [len];
Printf ("% lld \ n", sum );
}
Return 0;
}

Description: dizzy. It is always wrong Because gets is used to read the string, but it is correct to read it with scanf. It is speechless. There is a string. The length of the string len represents a matrix of len * len ,? This indicates that a queen can be placed in a row of people in this column. The Queen can only attack one column and target the places around it. numbers and letters are hexadecimal and are represented by n, indicates that there must be a queen in row n of this column. That is to say, this column has been determined to only have this queen.
# Include <cstdio>
# Include <cstring>
# Include <cstdlib>
Long v [20] [20];
Int main ()
{
// Freopen ("a.txt", "r", stdin );
Int len;
Int arr [20];
Char s [50];
Long sum;
While (scanf ("% s", s )! = EOF)
{
Len = strlen (s );
For (int I = 0; I <len; I ++)
If (s [I] = '? ') Arr [I + 1] = 0;
Else if (s [I]> = '1' & s [I] <= '9') arr [I + 1] = s [I]-'0 ';
Else if (s [I]> = 'A' & s [I] <= 'F ') arr [I + 1] = s [I]-'A' + 10;
Memset (v, 0, sizeof (v ));
If (! Arr [1]) for (int I = 1; I <= len; I ++) v [I] [1] = 1;
Else v [arr [1] [1] = 1;
For (int I = 2; I <= len; I ++)
If (! Arr [I])
{
For (int j = 1; j <= len; j ++)
For (int k = 1; k <= len; k ++)
If (abs (k-j)> 1) v [j] [I] + = v [k] [I-1];
}
Else
{
For (int k = 1; k <= len; k ++)
If (abs (k-arr [I])> 1) v [arr [I] [I] + = v [k] [I-1];
}
Sum = 0;
For (int I = 1; I <= len; I ++) sum + = v [I] [len];
Printf ("% lld \ n", sum );
}
Return 0;
}

 

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.