HDU 1800 Flying to Mars string hash

Source: Internet
Author: User

Analysis:

Test instructions is very understood, dividing a number of columns into as few ordered sequences as possible.

This has a simple and rare nature: the number of identical numbers determines the number of columns to divide.

If the problem data is small, it can be directly counted. But there is a hint that the number of data bits is almost 30 bits, and there is a leading 0, so consider the number of string hash statistics.

Code:

(Refer to the book, after all, just learn, first grasp the posture.) )
#include <cstdio> #include <cstring> #include <cstdlib> const int MAXN = 7010;
Char s[32];
int HASH[MAXN], COUNT[MAXN];
int n;

int ans;
        inline int Elfhash (char *key) {unsigned long h = 0;
                while (*key) {h = (H << 4) + (*key++);
                unsigned long g = h & 0xf0000000l;
                if (g) H ^= G >> 24;
        H &= ~g;
} return h;
        } inline void Hashit (char *s) {int k;
        while (*s = = ' 0 ') s++;
        K = Elfhash (s);
        int t = k% Maxn;
        while (hash[t]! = k && Hash[t]! =-1) {T = (t + ten)% Maxn;
                } if (hash[t] = = 1) {count[t] = 1;
        Hash[t] = k;
        } else if (++count[t] > ans) ans = count[t];
Return
        } int main () {#ifndef LOC freopen ("In.txt", "R", stdin); #endif while (~scaNF ("%d", &n)) {memset (hash,-1, sizeof (hash));
                GetChar ();
                ans = 1;
                        for (int i = 0; i < n; i++) {scanf ("%s", s);
                Hashit (s);
        } 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.