{"id":359,"date":"2010-08-23T23:17:00","date_gmt":"2010-08-23T15:17:00","guid":{"rendered":"http:\/\/localhost\/?p=359"},"modified":"2010-08-23T23:17:00","modified_gmt":"2010-08-23T15:17:00","slug":"zjoi2006_mahjong_mahjong","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/wjmzbmr\/?p=359","title":{"rendered":"[Zjoi2006]Mahjong\u9ebb\u5c06"},"content":{"rendered":"\n<p>[Zjoi2006]Mahjong\u9ebb\u5c06<\/p>\n<p>Time Limit:1000MS&#160; Memory Limit:65536K<br \/>Total Submit:3 Accepted:3<\/p>\n<p><strong>Description <\/strong><\/p>\n<p> <img decoding=\"async\" src=\"http:\/\/61.187.179.132:8080\/JudgeOnline\/images\/1860.jpg\" \/> <\/p>\n<p><strong>Input <\/strong><\/p>\n<p> \u7b2c\u4e00\u884c\u4e00\u4e2a\u6574\u6570N\uff08N&lt;=100\uff09\uff0c\u8868\u793a\u73a9\u4e86N\u6b21\u8d85\u7ea7\u9ebb\u5c06\u3002 <br \/>\u63a5\u4e0b\u6765N\u884c\uff0c\u6bcf\u884c100\u4e2a\u6570a1..a100\uff0c\u63cf\u8ff0\u6bcf\u6b21\u73a9\u724c\u624b\u4e2d\u5404\u79cd\u724c\u7684\u6570\u91cf\u3002ai\u8868\u793a\u6570\u5b57\u4e3ai\u7684\u724c\u6709ai\u5f20\u3002\uff080&lt;=ai&amp; lt;=100\uff09 <\/p>\n<p><strong>Output <\/strong><\/p>\n<p> \u8f93\u51faN\u884c\uff0c\u82e5\u80e1\u4e86\u5219\u8f93\u51faYes\uff0c\u5426\u5219\u8f93\u51faNo\uff0c\u6ce8\u610f\u533a\u5206Yes\uff0cNo\u7684\u5927\u5c0f\u5199\uff01 <\/p>\n<p><strong>Sample Input <\/strong><\/p>\n<p>3<br \/>2 4 0 0 0 0 0 \u2026\u2026 0\uff08\u4e00\u517198\u4e2a0\uff09<br \/>2 4 2 0 0 0 0 \u2026\u2026 0\uff08\u4e00\u517197\u4e2a0\uff09<br \/>2 3 2 0 0 0 0 \u2026\u2026 0\uff08\u4e00\u517197\u4e2a0\uff09<\/p>\n<p><strong>Sample Output <\/strong><\/p>\n<p>Yes<br \/>Yes<br \/>No<\/p>\n<p><strong>Source <\/strong><\/p>\n<p> Day2<\/p>\n<p>\u4e00\u5f00\u59cb\u6211\u770bAC\u4eba\u6570\u8fd9\u4e48\u5c11\u3002\u3002\u4ee5\u4e3a\u662fBT\u7684\u96be\u9898\u3002\u3002\u4e0d\u6562\u505a\u3002\u3002<br \/>\u4e0d\u8fc7\u521a\u521a\u4ed4\u7ec6\u770b\u4e86\u4e0b\u600e\u4e48\u597d\u50cf\u4eff\u4f5b\u3002\u3002\u662f\u6c34\u9898\uff1f<br \/>\u6ce8\u610f\u5230\u4ece\u5de6\u5f80\u53f3\u6d88\u53bb\u6bcf\u4e2a\u9ebb\u5c06\uff0c\u9996\u5148\u5f53\u524d\u7684\u53ea\u80fd\u5f71\u54cd3\u4e2a\u3002\u3002<br \/>\u6240\u4ee5\u8bb0\u5f55\u5f53\u524d3\u4e2a\u7684\u4e2a\u6570\u5c31\u8db3\u591f\u4e86\u56e7\u3002\u3002\u540c\u65f6\u8fd8\u8981\u77e5\u9053\u90a3\u4e00\u5bf9\u6709\u6ca1\u6709\u88ab\u7528\u8fc7\u3002\u3002<br \/>\u6240\u4ee5\u72b6\u6001\u5c31\u662f (pos,Apos,Apos+1,Apos+2,have_pair_used)<br \/>\u5e94\u8be5\u8bf4Dp\u5c31\u53ef\u4ee5\u4e86\u3002\u3002\u4e0d\u8fc7\u6211\u6709\u70b9\u61d2\u3002\u3002\u3002\u6240\u4ee5\u7528\u4e86Hash+set\u3002\u3002\u901f\u5ea6\u5f88\u5feb\u554a\u56e7\u3002\u3002<br \/>Code\uff1a<br \/>#include &lt;cstdio&gt;<br \/>#include &lt;set&gt;<br \/>#include &lt;iostream&gt;<br \/>#define rep(i,n) for(int i=0;i&lt;n;i++)<br \/>#define Debug(x) cout&lt;&lt;#x&lt;&lt;&quot;=&quot;&lt;&lt;x&lt;&lt;endl;<br \/>const int inf=~0U&gt;&gt;1,seed=131,maxn=100;<br \/>using namespace std;<br \/>typedef unsigned long long ull;<br \/>ull P[maxn+1];<br \/>set&lt;ull&gt; S;<br \/>int A[maxn];<br \/>bool ok;<br \/>void dfs(int p,bool can,ull code)<br \/>{<br \/>    if(!S.insert(code).second)return;<br \/>    while(p&lt;maxn&amp;&amp;A[p]==0)p++;<br \/>    if(p==maxn){if(!can)ok=true;return;}<br \/>    \/\/three consecutive<br \/>    if(p+2&lt;maxn&amp;&amp;A[p]&amp;&amp;A[p+1]&amp;&amp;A[p+2])<br \/>    {<br \/>        A[p]&#8211;;A[p+1]&#8211;;A[p+2]&#8211;;<br \/>        ull ncode=code-P[p]-P[p+1]-P[p+2];<br \/>        dfs(p,can,ncode);if(ok)return;<br \/>        A[p]++;A[p+1]++;A[p+2]++;<br \/>    }<br \/>    \/\/three same<br \/>    if(A[p]&gt;=3)<br \/>    {<br \/>        A[p]-=3;<br \/>        ull ncode=code-P[p]*3;<br \/>        dfs(p,can,ncode);if(ok)return;<br \/>        A[p]+=3;<br \/>    }<br \/>    \/\/four same<br \/>    if(A[p]&gt;=4)<br \/>    {<br \/>        A[p]-=4;<br \/>        ull ncode=code-P[p]*4;<br \/>        dfs(p,can,ncode);if(ok)return;<br \/>        A[p]+=4;<br \/>    }<br \/>    \/\/use pair<br \/>    if(A[p]&gt;=2&amp;&amp;can)<br \/>    {<br \/>        A[p]-=2;<br \/>        ull ncode=code-P[p]*2-P[maxn];<br \/>        dfs(p,!can,ncode);if(ok)return;<br \/>        A[p]+=2;<br \/>    }<br \/>}<br \/>void Solve()<br \/>{<br \/>    ull ret=0;<br \/>    rep(i,maxn)<br \/>    {<br \/>        scanf(&quot;%d&quot;,A+i);<br \/>        ret*=seed;ret+=A[i];<br \/>    }<br \/>    ret*=seed;ret+=1;<br \/>    S.clear();<br \/>    ok=false;<br \/>    dfs(0,true,ret);<br \/>    if(ok)puts(&quot;Yes&quot;);<br \/>    else puts(&quot;No&quot;);<br \/>}<br \/>int main()<br \/>{<br \/>    \/\/freopen(&quot;in&quot;,&quot;r&quot;,stdin);<br \/>    P[0]=1;rep(i,maxn)P[i+1]=P[i]*seed;<br \/>    int t;cin&gt;&gt;t;rep(i,t)Solve();<br \/>} <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[Zjoi2006]Mahjong\u9ebb\u5c06 Time Limit:1000MS&#160; Memory Limit:65536KTotal Submit:3 Accepted:3 Description Input \u7b2c\u4e00\u884c\u4e00\u4e2a\u6574\u6570N\uff08N&lt;=100\uff09\uff0c\u8868\u793a\u73a9\u4e86N\u6b21\u8d85\u7ea7\u9ebb\u5c06\u3002 \u63a5\u4e0b\u6765N\u884c\uff0c\u6bcf\u884c100\u4e2a\u6570a1..a100\uff0c\u63cf\u8ff0\u6bcf\u6b21\u73a9\u724c\u624b\u4e2d\u5404\u79cd\u724c\u7684\u6570\u91cf\u3002ai\u8868\u793a\u6570\u5b57\u4e3ai\u7684\u724c\u6709ai\u5f20\u3002\uff080&lt;=ai&amp; lt;=100\uff09 Output \u8f93\u51faN\u884c\uff0c\u82e5\u80e1\u4e86\u5219\u8f93\u51faYes\uff0c\u5426\u5219\u8f93\u51faNo\uff0c\u6ce8\u610f\u533a\u5206Yes\uff0cNo\u7684\u5927\u5c0f\u5199\uff01 Sample Input 32 4 0 0 0 0 0 \u2026\u2026 0\uff08\u4e00\u517198\u4e2a0\uff092 4 2 0 0 0 0 \u2026\u2026 0\uff08\u4e00\u517197\u4e2a0\uff092 3 2 0 0 0 0 \u2026\u2026 0\uff08\u4e00\u517197\u4e2a0\uff09 Sample Output YesYesNo Source Day2 \u4e00\u5f00\u59cb\u6211\u770bAC\u4eba\u6570\u8fd9\u4e48\u5c11\u3002\u3002\u4ee5\u4e3a\u662fBT\u7684\u96be\u9898\u3002\u3002\u4e0d\u6562\u505a\u3002\u3002\u4e0d\u8fc7\u521a\u521a\u4ed4\u7ec6\u770b\u4e86\u4e0b\u600e\u4e48\u597d\u50cf\u4eff\u4f5b\u3002\u3002\u662f\u6c34\u9898\uff1f\u6ce8\u610f\u5230\u4ece\u5de6\u5f80\u53f3\u6d88\u53bb\u6bcf\u4e2a\u9ebb\u5c06\uff0c\u9996\u5148\u5f53\u524d\u7684\u53ea\u80fd\u5f71\u54cd3\u4e2a\u3002\u3002\u6240\u4ee5\u8bb0\u5f55\u5f53\u524d3\u4e2a\u7684\u4e2a\u6570\u5c31\u8db3\u591f\u4e86\u56e7\u3002\u3002\u540c\u65f6\u8fd8\u8981\u77e5\u9053\u90a3\u4e00\u5bf9\u6709\u6ca1\u6709\u88ab\u7528\u8fc7\u3002\u3002\u6240\u4ee5\u72b6\u6001\u5c31\u662f (pos,Apos,Apos+1,Apos+2,have_pair_used)\u5e94\u8be5\u8bf4Dp\u5c31\u53ef\u4ee5\u4e86\u3002\u3002\u4e0d\u8fc7\u6211\u6709\u70b9\u61d2\u3002\u3002\u3002\u6240\u4ee5\u7528\u4e86Hash+set\u3002\u3002\u901f\u5ea6\u5f88\u5feb\u554a\u56e7\u3002\u3002Code\uff1a#include &lt;cstdio&gt;#include &lt;set&gt;#include &lt;iostream&gt;#define rep(i,n) for(int i=0;i&lt;n;i++)#define Debug(x) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[10],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts\/359"}],"collection":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=359"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts\/359\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=359"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=359"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=359"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}