"TYVJ 1060" "NOIP 2005" equivalent expression

Source: Internet
Author: User

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

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.