Set A to a prime number, modulus to another prime, and then the answer to the polynomial of violence, and if the answer is equal, the two polynomial are considered equal.
This kind of hash has the error probability question why still must use the hash? Because the probability of error is too small, a and modulus of the value of the person can not get a good card.
And then contributed 2 times WA, for the first time because the number is not judged by the boundary, the second time because the multiplication of the explosion int!!!
Hash Dafa Good ~
#include <cstdio> #include <cstring> #include <algorithm>using namespace Std;typedef long ll; const int N = 10003;const int a = 10007;const int p = 100007;char S[n], c[n], Stf[n];int num, now, Stnum[n], Topnum, sty[n ], Topfh;int get (char c) {if (c = = ' + ' | | c = = '-') return 1; if (c = = ' * ') return 2; if (c = = ' ^ ') return 3;} BOOL FH (char c) {return c = = ' + ' | | c = = '-' | | c = = ' * ' | | c = = ' ^ ' | | c = = ' (' | | c = = ') ';} int Ipow (int a, int b) {ll s = 1;for (int i = 1; I <= b; ++i) s = s * A% p;return (int) s;} int cal (char FH, int a, int b) {switch (FH) {case ' + ': return (A + b)% P;break;case '-': return (-A + p)% p;break;case ' * ': return (int) (1LL * A * b% p); Break;case ' ^ ': return Ipow (A, b); break;}} int _ () {int len = strlen (s), tmp = 0, j = +, k;c[0] = ", for (int i = 0; i < len; ++i) if (s[i]! =") c[++tmp] = s[ I];c[tmp + 1] = "; len = tmp; TMP = 1; Topnum = TOPFH = 0;while (tmp <= len) {if (FH (C[tmp])) {if (c[tmp] = = ' (') j + = 10;else if (c[tmp] = = ') ')J-= 10;else {k = get (C[tmp]), while (TOPFH && STY[TOPFH] >= k + j) {Stnum[topnum-1] = cal (STF[TOPFH], stnum[t Opnum-1], stnum[topnum]);--topnum; --TOPFH;} STF[++TOPFH] = c[tmp]; STY[TOPFH] = k + j;} ++tmp;} else {if (c[tmp] = = ' a ') stnum[++topnum] = A, ++tmp;else {k = 0;for (; c[tmp] >= ' 0 ' && c[tmp] <= ' 9 ' &&am P TMP <= Len; ++tmp) K = k * + c[tmp]-' 0 '; stnum[++topnum] = k;}} while (TOPFH) {stnum[topnum-1] = cal (STF[TOPFH], stnum[topnum-1], stnum[topnum]);--topnum;--topfh;} return stnum[1];} int main () {gets (s), num = _ (), int m;scanf ("%d\n", &m), for (int i = 0; i < m; ++i) {gets (s); n = _ (); if (now = = num) Putchar (' A ' + i);} Puts (""); return 0;}
Magic Hash Ah, your low error rate is how metaphysical, your reliability so confusing ~
"TYVJ 1060" "NOIP 2005" equivalent expression