HDU 5167 (map + violence)

Source: Internet
Author: User

Test instructions: Give a number n and ask if n can be the product of the number of Fibonacci sequences

First brush the Fibonacci sequence, then enumerate

1#include <cstdio>2#include <cstring>3#include <queue>4#include <map>5#include <iostream>6 using namespacestd;7typedefLong LongLL;8 ConstLL Max =1000000000;9LL num[ -];TenMap<ll,BOOL>m; One voidInit () A { -Queue<ll>Q; -m[0] =true; them[1] =true; -num[0] =0; -num[1] =1; -      for(inti =2; I < $; i++) +     { -Num[i] = num[i-1] + num[i-2]; + Q.push (Num[i]); Am[Num[i]] =true; at     } -      while(!q.empty ()) -     { -         inttemp =Q.front (); - Q.pop (); -          for(inti =1; I < $; i++) in         { -LL res = temp *Num[i]; to             if(Res >Max) +                  Break; -             if(m[res]) the                 Continue; *m[res] =true; $ Q.push (res);Panax Notoginseng         } -     } the  + } A intMain () the { + init (); -     inttest, N; $scanf"%d", &test); $      while(test--) -     { -scanf"%d", &n); the         if(m[n]) -printf"yes\n");Wuyi         Else theprintf"no\n"); -     } Wu     return 0; -}
View Code

HDU 5167 (map + violence)

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.