Poj 1200 Crazy Search hash

Source: Internet
Author: User

Note that the question of simple Hash has already indicated that the number of NCS cannot exceed 16 Million. For details, see the implementation of the Code.

/******************** PRO: poj 1200 TIT: Crazy Search DAT: AUT: UKean EMA: huyocan@163.com *********************/# include <cstdio> # include <cstring> # define maxn 1005 bool has [16000006] = {0 }; int asc [300], n, nc, ans = 1, tag = 0, base = 0, chu = 1, num; int main () {scanf ("% d \ n", & n, & nc); memset (asc,-1, sizeof (asc )); // The ing table of initialization characters that maps nc different characters to 0 to the number of nc nc-1, // in this way, we can get the number of nc hexadecimal char temp = getchar (); for (in T I = 0; I <n-1; I ++) // use this number to modulo the n-bit nc hexadecimal number to remove its highest chu * = nc; for (int I = 0; I <n; I ++) // obtain the first n-bit nc hexadecimal number {num = (int) temp; if (asc [num] =-1) asc [num] = tag ++; // according to the order of appearance to nc different characters are labeled as 0 to nc-1 base = base * nc + asc [num]; temp = getchar ();} has [base] = 1; while (temp! = '\ N') {int num = (int) temp; if (asc [num] =-1) asc [num] = tag ++; // according to the order of the appearance of nc different characters are marked as 0 to nc-1 base = (base % chu) * nc + asc [num]; if (! Has [base]) // generates a number of normal nc hexadecimal values {ans ++; has [base] = 1 ;}temp = getchar ();} printf ("% d \ n", ans); 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.