HDU 5077 NAND (table) 2014 Asia Regional Anshan Station H

Source: Internet
Author: User

Question link: Click the open link

It is a bitwise operation function that asks how many steps can be taken to obtain a given number;

Train of Thought: I am not opportunistic to create a table, but I can only create a table... The thought of table creation is to use a set of available numbers to represent the State BFs. In the end, there is a need for 11 steps, which requires nearly 1 H. Except this 10 minute is enough.

CPP:

# Include <cstdio> # include <cstring> # include <queue> # include <vector> # include <map> using namespace STD; int mark [300]; struct node {int deep; vector <int> us; void Init () {deep = 0; us. push_back (15); US. push_back (51); US. push_back (85); US. push_back (0); US. push_back (255);} bool find (int n) {for (INT I = 0; I <us. size (); I ++) if (US [I] = N) return 1; return 0 ;}}; int NAND (int A, int B) {return (255 ^ (A & B) ;}queue <node> q; Map <VEC Tor <int>, bool> map; // The checkbool check () {int bj = 1; for (INT I = 0; I <256; I ++) {If (MARK [I] <0) {bj = 0 ;}} if (bj) for (INT I = 0; I <256; I ++) {printf ("% d,", Mark [I]);} return BJ;} // leave the last check version bool check () {int CNT = 0; for (INT I = 0; I <256; I ++) {If (MARK [I] <0) {CNT ++ ;}} if (CNT <2) for (INT I = 0; I <256; I ++) {printf ("% d,", Mark [I]);} return (CNT <2 );} void BFS () {node TPE; TPE. init (); q. push (TPE); For (INT I = 0; I <5; I ++) {mark [TPE. Us [I] = 0;} while (! Check () {node TP = Q. front (); q. pop (); For (INT I = 0; I <TP. us. size (); I ++) {for (Int J = 0; j <TP. us. size (); j ++) {int temp = NAND (TP. us [I], TP. us [J]); If (MARK [temp] <0) MARK [temp] = TP. deep + 1; if (! TP. find (temp) {node He = TP; he. deep ++; he. us. push_back (temp); sort (HE. us. begin (), he. us. end (); If (Map [He. us] = 1) continue; Map [He. us] = 1; q. push (HE) ;}}}} int main () {for (INT I = 0; I <256; I ++) MARK [I] =-1; BFS (); Return 0 ;}


HDU 5077 NAND (table) 2014 Asia Regional Anshan Station H

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.