{"id":1420,"date":"2024-02-17T23:37:51","date_gmt":"2024-02-17T15:37:51","guid":{"rendered":"http:\/\/www.forillusion.com\/?p=1420"},"modified":"2025-02-14T11:39:02","modified_gmt":"2025-02-14T03:39:02","slug":"training-report-on-the-fourth-week-of-winter-vacation-training","status":"publish","type":"post","link":"https:\/\/www.forillusion.com\/index.php\/training-report-on-the-fourth-week-of-winter-vacation-training\/","title":{"rendered":"\u5bd2\u5047\u8bad\u7ec3\u7b2c\u56db\u5468\u8bad\u7ec3\u62a5\u544a"},"content":{"rendered":"\n<p><div class=\"has-toc have-toc\"><\/div><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Part 1.\u8bad\u7ec3\u9898\u9898\u89e3<\/h2>\n\n\n\n<p>\u5bd2\u5047\u7b97\u6cd5\u8bad\u7ec3\uff08\u4e8c\uff09\u5b57\u7b26\u4e32\u7b97\u6cd5<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">#Algo0201. \u3010\u6a21\u677f\u3011\u5b57\u7b26\u4e32\u54c8\u5e0c<\/h3>\n\n\n\n<p><a href=\"https:\/\/hydro.ac\/d\/ahuacm\/p\/Algo0201\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"nofollow\" >\u9898\u76ee\u63cf\u8ff0<\/a><\/p>\n\n\n\n<p>\u9898\u76ee\u9700\u8981\u6c42\u51fa\u7ed9\u5b9a\u5b57\u7b26\u4e32\u4e2d\u662f\u5426\u6709\u91cd\u590d\u7684\uff0c\u5229\u7528\u6876\u5b58\u50a8\u5b57\u7b26\u4e32\u7684Hash\uff0c\u5e76\u5224\u65ad\u8be5Hash\u662f\u5426\u5b58\u5728\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>char s&#91;2001];\nint n,ans;\nconst int N=100005;\nint a&#91;43961944];\n\nstruct Hash\n{\n    const int Mod1=43961944,u1=131;\n    int h1&#91;N],b1&#91;N];\n    void build(char *s)\n    {\n        b1&#91;0]=1;\n        for (int i=1;i&lt;=strlen(s+1);i++)\n        {\n            b1&#91;i]=b1&#91;i-1]*u1%Mod1;\n            h1&#91;i]=(h1&#91;i-1]*u1+s&#91;i]-48)%Mod1;\n        }\n    }\n\n    int getHash(int l,int r)\n    {\n        return (h1&#91;r]-h1&#91;l-1]*b1&#91;r-l+1]%Mod1+Mod1)%Mod1;\n    }\n}Hash;\n\nint main()\n{\n    CI n;\n    F(i,1,n)\n    {\n        CI (s+1);\n        Hash.build(s);\n        int h=Hash.getHash(1,strlen(s+1));\n        if (a&#91;h]==0) \n        {\n            a&#91;h]=1;\n            ans++;\n        }\n    }\n    CO ans L;    \n    return 0;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">#Algo0202. \u3010\u6a21\u677f\u3011KMP\u5b57\u7b26\u4e32\u5339\u914d<\/h3>\n\n\n\n<p><a href=\"https:\/\/hydro.ac\/d\/ahuacm\/p\/Algo0202\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"nofollow\" >\u9898\u76ee\u63cf\u8ff0<\/a><\/p>\n\n\n\n<p>\u672c\u9898\u5229\u7528KMP\u7b97\u6cd5\uff0c\u8f93\u51fa\u6a21\u5f0f\u4e32\u5339\u914d\u7684\u4f4d\u7f6e\uff0c\u5e76\u5728\u7ed3\u5c3e\u6253\u5370next\u6570\u7ec4\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int n,m,nxt&#91;1000006];\nchar a&#91;1000006],b&#91;1000006];\nint main()\n{\n    \/\/ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);\n    CI (a+1)&gt;&gt;(b+1);\n    n=strlen(a+1);\n    m=strlen(b+1);\n    nxt&#91;1]=0;\n    int j=0;\n    for (int i=2;i&lt;=m;i++)\n    {\n        while (b&#91;i]!=b&#91;j+1]&amp;&amp;j&gt;0)\n            j=nxt&#91;j];\n        if (b&#91;i]==b&#91;j+1])\n        {\n            j++;\n            nxt&#91;i]=j;\n        }\n    }\n\n    j=0;\n    for (int i=0;i&lt;n;i++)\n    {\n        while (a&#91;i+1]!=b&#91;j+1]&amp;&amp;j&gt;0)\n            j=nxt&#91;j];\n        if (a&#91;i+1]==b&#91;j+1]) j++;\n        if (j==m) cout&lt;&lt;i+1-m+1&lt;&lt;endl;\n    }\n    for (int i=1;i&lt;=m;i++)\n        cout&lt;&lt;nxt&#91;i]&lt;&lt;\" \";\n    cout&lt;&lt;endl;\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">#Algo0203. Censoring S<\/h3>\n\n\n\n<p><a href=\"https:\/\/hydro.ac\/d\/ahuacm\/p\/Algo0203\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"nofollow\" >\u9898\u76ee\u63cf\u8ff0<\/a><\/p>\n\n\n\n<p>\u672c\u9898\u5229\u7528KMP\u67e5\u627e\u6a21\u5f0f\u4e32\u7684\u540c\u65f6\uff0c\u7528\u4e00\u4e2a\u6808\u6765\u8bb0\u5f55\u7b54\u6848\uff0c\u5e76\u7528top\u6307\u9488\u6307\u5411\u6808\u9876\uff0c\u540c\u65f6\u7528\u4e00\u4e2a\u6808f\u6765\u8bb0\u5f55\u5b57\u7b26\u4e32\u6bcf\u4f4d\u7684j\u6307\u9488\u4f4d\u7f6e\u3002\u5f53\u5339\u914d\u5230\u6a21\u5f0f\u4e32\u540e\uff0ctop\u6570\u7ec4\u540e\u79fb\u6a21\u5f0f\u4e32\u7684\u4f4d\u6570\uff0c\u540c\u65f6\u5c06j\u6307\u9488\u8c03\u6574\u5230f\u6808\u6808\u9876\u8bb0\u5f55\u7684\u4f4d\u7f6e\u5904\u3002\u8fd9\u6837\u5c31\u53ef\u4ee5\u5728\u5339\u914d\u5230\u4e00\u4e2a\u5b57\u7b26\u4e32\u540e\uff0c\u5c06j\u6307\u9488\u8fd8\u539f\u5230\u4e0a\u4e00\u6b21\u5339\u914d\u7684\u60c5\u51b5\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int n,m,nxt&#91;1000006],f&#91;1000006];\nchar a&#91;1000006],b&#91;1000006],c&#91;1000006];\n\nint main()\n{\n    \/\/ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);\n    CI (a+1)&gt;&gt;(b+1);\n    n=strlen(a+1);\n    m=strlen(b+1);\n    nxt&#91;1]=0;\n    int j=0;\n    for (int i=2;i&lt;=m;i++)\n    {\n        while (b&#91;i]!=b&#91;j+1]&amp;&amp;j&gt;0)\n            j=nxt&#91;j];\n        if (b&#91;i]==b&#91;j+1])\n        {\n            j++;\n            nxt&#91;i]=j;\n        }\n    }\n\n    int top=0;\n    for (int i=0;i&lt;n;i++)\n    {\n        c&#91;++top]=a&#91;i+1];\n        \/\/ cout&lt;&lt;top&lt;&lt;c&#91;top]&lt;&lt;endl;\n        while ((a&#91;i+1]!=b&#91;j+1])&amp;&amp;j&gt;0)\n            j=nxt&#91;j];\n\n        if (a&#91;i+1]==b&#91;j+1]) j++;\n        f&#91;top]=j;\n        if (j==m) top-=m,j=f&#91;top];\n    }\n    c&#91;++top]='\\0';\n    cout&lt;&lt;(c+1)&lt;&lt;endl;\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">#Algo0204. \u65e0\u7ebf\u4f20\u8f93<\/h3>\n\n\n\n<p><a href=\"https:\/\/hydro.ac\/d\/ahuacm\/p\/Algo0204\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"nofollow\" >\u9898\u76ee\u63cf\u8ff0<\/a><\/p>\n\n\n\n<p>\u5b57\u7b26\u4e32\u6709\u4e00\u4e2a\u5faa\u73af\u8282\u6784\u6210\uff0c\u6c42\u5faa\u73af\u8282\u7684\u6700\u5c0f\u957f\u5ea6\u3002\u8f93\u51fa\u8fd9\u4e2a\u5b57\u7b26\u4e32\u7684next\u6570\u7ec4\uff0c\u4e0d\u96be\u53d1\u73b0\uff0c\u5f53\u5faa\u73af\u8282\u5f00\u59cb\u5faa\u73af\u65f6\uff0cnext\u503c\u4ece1\u9010\u4e2a\u589e\u52a0\uff0c\u5e76\u5728\u672b\u5c3e\u5904\uff0cnext\u503c\u8868\u793a\u8be5\u6570\u7ec4\u5faa\u73af\u4e86\u591a\u5c11\u4f4d\u3002\u5c06\u5b57\u7b26\u4e32\u603b\u957f\u5ea6\u51cf\u53bb\u6700\u540e\u4e00\u4f4d\u7684next\u5c31\u80fd\u5f97\u5230\u5faa\u73af\u8282\u7684\u957f\u5ea6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int n,m,nxt&#91;1000006],ans=0;\nchar b&#91;1000006];\nint main()\n{\n    \/\/ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);\n    CI m;\n    CI (b+1);\n    m=strlen(b+1);\n    nxt&#91;1]=0;\n    int j=0;\n    for (int i=2;i&lt;=m;i++)\n    {\n        while (b&#91;i]!=b&#91;j+1]&amp;&amp;j&gt;0)\n            j=nxt&#91;j];\n        if (b&#91;i]==b&#91;j+1])\n        {\n            j++;\n            nxt&#91;i]=j;\n        }\n    }\n\n    cout&lt;&lt;m-nxt&#91;m]&lt;&lt;endl;\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Part 2.Codeforces\u9898\u89e3<\/h2>\n\n\n\n<p>\u9898\u76ee\u94fe\u63a5\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/codeforces.com\/contest\/1931\" target=\"_blank\" rel=\"nofollow\" >https:\/\/codeforces.com\/contest\/1931<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">A. Recovering a Small String<\/h3>\n\n\n\n<p>\u96be\u5ea6\uff1a800<\/p>\n\n\n\n<p>\u5c06a\u8bb0\u4e3a1\uff0cb\u8bb0\u4e3a2\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002\u7ed9\u51fa\u4e00\u4e2a3-78\u4e4b\u95f4\u7684\u4e00\u4e2a\u6570\uff0c\u6c42\u51fa\u4e00\u4e2a\u5b57\u5178\u5e8f\u6700\u5c0f\u76843\u4e2a\u5b57\u6bcd\uff0c\u4f7f\u5f97\u8fd93\u4e2a\u5b57\u6bcd\u76f8\u52a0\u7b49\u4e8e\u7ed9\u5b9a\u7684\u6570\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int t,x,a,b,c;\nint main()\n{\n    \/\/ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);\n    CI t;\n    while (t--)\n    {\n        CI x;\n        F(i,1,26)\n            F(j,1,26)\n                F(k,1,26)\n                    if (i+j+k==x)\n                    {\n                        cout&lt;&lt;(char)(i-1+'a')&lt;&lt;(char)(j-1+'a')&lt;&lt;(char)(k-1+'a')&lt;&lt;endl;\n                        goto l;\n                    }\n        l:\n        x++;   \n    }\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">B. Make Equal<\/h3>\n\n\n\n<p>\u96be\u5ea6\uff1a800<\/p>\n\n\n\n<p>\u7ed9\u51fa\u4e00\u4e2a\u6570\u7ec4\uff0c\u6570\u7ec4\u7684\u6bcf\u4e2a\u6570\u90fd\u53ef\u4ee5\u5206\u4e00\u90e8\u5206\u7ed9\u540e\u9762\u7684\u6570\uff0c\u95ee\u6700\u540e\u662f\u5426\u80fd\u591f\u8ba9\u6bcf\u4e2a\u6570\u90fd\u76f8\u7b49\u3002<\/p>\n\n\n\n<p>\u5148\u6c42\u51fa\u6570\u7ec4\u7684\u603b\u548c\u5e76\u6c42\u51fa\u5e73\u5747\u503c\uff0c\u4ece\u5934\u904d\u5386\u6570\u7ec4\uff0c\u540c\u65f6\u7528\u4e00\u4e2a\u53d8\u91cfx\u8bb0\u5f55\u5f53\u524d\u6570\u5b57\u52a0x\u540e\u6bd4\u5747\u503c\u591a\u51fa\u591a\u5c11\uff0c\u7136\u540e\u5c06x\u52a0\u4e0a\u5f53\u524d\u6570\u5b57\u5e76\u51cf\u53bb\u5747\u503c\uff0c\u5982\u679c\u56fe\u4e2d\u51fa\u73b0\u53d8\u91cfx\u52a0\u4e0a\u5f53\u524d\u6570\u5b57\u540e\u4f9d\u7136\u5c0f\u4e8e\u5747\u503c\uff0c\u5219\u6700\u540e\u65e0\u6cd5\u505a\u5230\u6bcf\u4e2a\u6570\u90fd\u76f8\u7b49\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"cpp\">int t,a&#91;200005],sum,n,avg,x,f;\r\nint main()\r\n{\r\n    \/\/ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);\r\n    CI t;\r\n    while (t--)\r\n    {\r\n        sum=x=0;\r\n        f=1;\r\n        CI n;\r\n        F(i,1,n)\r\n        {\r\n            CI a&#91;i];\r\n            sum+=a&#91;i];\r\n        }\r\n        avg=sum\/n;\r\n        F(i,1,n)\r\n        {\r\n            if (a&#91;i]+x&gt;=avg) x=a&#91;i]+x-avg;\r\n            else\r\n            {\r\n                f=0;\r\n                break;\r\n            }\r\n        }\r\n        if (f) CO \"YES\" L;\r\n        else CO \"NO\" L;\r\n    }\r\n    return 0;\r\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">C. Make Equal Again<\/h3>\n\n\n\n<p>\u96be\u5ea6\uff1a1000<\/p>\n\n\n\n<p>\u7ed9\u51fa\u4e00\u4e2a\u6570\u7ec4\uff0c\u4fee\u6539\u8fd9\u4e9b\u6570\u7ec4\u4e2d\u7684\u8fde\u7eed\u7684\u4e00\u4e32\u6570\uff0c\u4f7f\u5f97\u6570\u7ec4\u4e2d\u6bcf\u4e2a\u6570\u90fd\u76f8\u7b49\uff0c\u6c42\u51fa\u6700\u5c0f\u7684\u4fee\u6539\u6570\u91cf\u3002<\/p>\n\n\n\n<p>\u4e3a\u4e86\u5f97\u5230\u6700\u5c0f\u7684\u4fee\u6539\u6570\u91cf\uff0c\u53ef\u4ee5\u5206\u522b\u6c42\u51fa\u8fd9\u7ec4\u6570\u4e2d\u5f00\u5934\u548c\u7ed3\u5c3e\u76f8\u540c\u503c\u6709\u591a\u5c11\uff0c\u5982\u679c\u5f00\u5934\u548c\u7ed3\u5c3e\u76f8\u7b49\uff0c\u5219\u7528\u603b\u957f\u5ea6\u51cf\u53bb\u5f00\u5934\u548c\u7ed3\u5c3e\u76f8\u7b49\u503c\u7684\u957f\u5ea6\uff1b\u5426\u5219\u7528\u603b\u957f\u5ea6\u51cf\u53bb\u5f00\u5934\u548c\u7ed3\u5c3e\u4e2d\u8f83\u957f\u7684\u4e00\u4e2a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int t,n,a&#91;200005];\nint main()\n{\n    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);\n    CI t;\n    while (t--)\n    {\n        CI n;\n        F(i,1,n)\n            CI a&#91;i];\n        int l1=a&#91;1],l2=1,r1=a&#91;n],r2=1;\n        F(i,2,n)\n            if (a&#91;i]==l1) l2++;\n            else break;\n        FD(i,n-1,1)\n            if (a&#91;i]==r1) r2++;\n            else break;\n        if (l1==r1) CO max(0,n-l2-r2) L;\n        else CO min(n-l2,n-r2) L;\n    }\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">D. Divisible Pairs<\/h3>\n\n\n\n<p>\u96be\u5ea6\uff1a1300<\/p>\n\n\n\n<p>\u627e\u5230\u9898\u76ee\u4e2d\u8981\u6c42\u7684\u6570\u7ec4\uff0c\u9700\u8981\u627e\u51fa\u5728\u524d\u9762\u4e2d\u662f\u5426\u5b58\u5728\u4e00\u4e2a\u6570\u6ee1\u8db3(x-a%x)%x\uff0ca%y\u3002<\/p>\n\n\n\n<p>\u7528\u4e00\u4e2a\u5b57\u5178\uff0c\u952e\u4e3apair\uff0c\u5b58\u50a8\u7684\u662f(a%x,a%y\uff09\uff0c\u503c\u4e3a\u5f53\u524dpair\u51fa\u73b0\u7684\u6b21\u6570\u3002\u5982\u679c\u80fd\u627e\u5230((x-a%x)%x,a%y)\uff0c\u5219\u5c06ans\u52a0\u4e0a\u8be5\u952e\u5bf9\u5e94\u7684\u503c\u3002\u7136\u540e\u5c06\u5f53\u524d\u6570(a%x,a%y)\u52a0\u5165\u5230\u5b57\u5178\u4e2d\uff0c\u5982\u679c\u5df2\u5b58\u5728\uff0c\u5219\u5c06\u503c+1\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"cpp\">LL t,n,x,y,a,ans;\r\nint main()\r\n{\r\n    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);\r\n    CI t;\r\n    while (t--)\r\n    {\r\n        ans=0;\r\n        map&lt;pair&lt;LL,LL>,int> s;\r\n        CI n>>x>>y;\r\n        F(i,1,n)\r\n        {\r\n            CI a;\r\n            if (s.find(make_pair((x-a%x)%x,a%y))!=s.end()) ans+=s.find(make_pair((x-a%x)%x,a%y))->second;\r\n            if (s.find(make_pair(a%x,a%y))!=s.end()) s&#91;make_pair(a%x,a%y)]++;\r\n            else s.insert(make_pair(make_pair(a%x,a%y),1));\r\n        }\r\n        CO ans L;\r\n    }\r\n    return 0;\r\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Part 1.\u8bad\u7ec3\u9898\u9898\u89e3 \u5bd2\u5047\u7b97\u6cd5\u8bad\u7ec3\uff08\u4e8c\uff09\u5b57\u7b26\u4e32\u7b97\u6cd5 #Algo0201. \u3010\u6a21\u677f\u3011\u5b57\u7b26\u4e32\u54c8\u5e0c \u9898\u76ee\u63cf\u8ff0 \u9898\u76ee\u9700\u8981\u6c42\u51fa\u7ed9\u5b9a\u5b57\u7b26\u4e32 &#8230;<\/p>","protected":false},"author":1,"featured_media":1419,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28],"tags":[29],"class_list":["post-1420","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-28","tag-29"],"_links":{"self":[{"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/posts\/1420","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/comments?post=1420"}],"version-history":[{"count":1,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/posts\/1420\/revisions"}],"predecessor-version":[{"id":1725,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/posts\/1420\/revisions\/1725"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/media\/1419"}],"wp:attachment":[{"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/media?parent=1420"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/categories?post=1420"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/tags?post=1420"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}