Hdu1226 search for water problems

Source: Internet
Author: User

The password is a total of 500-bit complete wide-search password. one of the conditions is a multiple of N. Therefore, a maximum of 1-15 characters in the 4999 medium-search status may appear.

Simple code

# Include <stdio. h>
# Include <string. h>
# Include <queue>
# Include <iostream>
Using namespace STD;


Int n, m, C, Mark [20], visit [5100];
Struct Node
{
Int Len;
Int PRT [510];
} A, B;
Int judge (node S)
{
Int I, T = 0;
For (I = 1; I <= S. Len; I ++)
{
T = (T * C + S. PRT [I]) % N;
}
Return T;
}
Int print (node S)
{
For (INT I = 1; I <= S. Len; I ++)
{
If (S. PRT [I] <= 9) printf ("% d", S. PRT [I]);
Else printf ("% C", S. PRT [I]-10 + 'A ');
}
Printf ("\ n ");
Return 0;
}
Int BFS ()
{
Int I, j, x = 1;
Memset (visit, 0, sizeof (visit ));
A. Len = 0;
A. PRT [0] = 0;
Queue <node> q;
Q. Push ();
While (! Q. Empty ())
{
B = Q. Front ();
Q. Pop ();
For (I = 0; I <16; I ++)
{
If (! Mark [I]) continue;
If (x = 1 & I = 0) continue; // the first digit cannot be set to zero.
A = B;
A. Len = B. Len + 1;
A. PRT [A. Len] = I;
Int K = judge ();
If (k = 0)
{
Print ();
Return 1;
}
If (visit [k]) continue;
If (A. Len <= 499 );
{
Visit [k] = 1;
Q. Push ();
}
}
X ++;
}
Return 0;
}
Int main ()
{
Int T, I, J;
Char STR [15];
Scanf ("% d", & T );
While (t --)
{
Scanf ("% d", & N, & C );
Scanf ("% d", & M );
Memset (mark, 0, sizeof (Mark ));
For (I = 1; I <= m; I ++)
{
Scanf ("% s", STR );
If (STR [0]> = '0' & STR [0] <= '9 ')
Mark [STR [0]-'0'] = 1;
Else
Mark [STR [0]-'A' + 10] = 1;
}
If (n = 0)
{
If (MARK [0]) printf ("0 \ n ");
Else printf ("give me the bomb please \ n ");
}
Else
{
Int flash = BFS ();
If (! Flash) printf ("give me the bomb please \ n ");
}
}
Return 0;
}

Hdu1226 search for water problems

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.