{"id":66,"date":"2023-03-02T22:24:43","date_gmt":"2023-03-02T14:24:43","guid":{"rendered":"https:\/\/solost.cn\/?p=66"},"modified":"2023-03-02T22:24:43","modified_gmt":"2023-03-02T14:24:43","slug":"153","status":"publish","type":"post","link":"https:\/\/solost.cn\/?p=66","title":{"rendered":"D &#8211; Flip Cards"},"content":{"rendered":"<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/11\/image-5.png\" alt=\"image.png\" title=\"image.png\"><\/p>\n<h2>solution<\/h2>\n<p>\u8fd9\u9053\u9898\u521a\u5f00\u59cb\u60f3\u7684\u662f\u6240\u6709\u7684\u724c\u5411\u4e0a\u7684\u90a3\u4e00\u9762\u90fd\u4e0d\u4e00\u6837\uff0c\u7136\u540e\u5c31\u4e0d\u77e5\u9053\u600e\u4e48\u505a\u4e86\uff0c\u540e\u6765\u8bfb\u9898\u662f\u65c1\u8fb9\u7684\u724c\u4e0d\u4e00\u6837\u5c31\u884c\u3002\u7136\u540e\u60f3\u7684\u662f\u8fd9\u4e2a\u9b3c\u6837\u5b50<\/p>\n<pre><code class=\"lang-cpp\">f[1][0] = f[1][1] = 0;\n    int p1 = q[1].x, p2 = q[1].y;\n    for(int i = 2; i &lt;= n; i++){\n        auto &amp;t = q[i];\n        if(p1 != t.x) f[i][0] = (f[i - 1][0] + 1) % p;\n        if(p2 != t.x) f[i][0] = (f[i - 1][1] + 1) % p;\n        if(p1 != t.y) f[i][1] = (f[i - 1][0] + 1) % p;\n        if(p2 != t.y) f[i][1] = (f[i - 1][1] + 1) % p;\n        p1 = t.x, p2 = t.y;\n    }\n    ll sum = (f[n][0] % p + f[n][1] % p) % p;<\/code><\/pre>\n<p>\u8fd9\u4e2a\u5730\u65b9\u7684\u95ee\u9898\u662f\u6bcf\u589e\u52a0\u4e00\u4e2a\u6570\uff0c\u591a\u7684\u4e0d\u662f1\u4e2a\uff0c\u7136\u662f\u524df[i - 1]\u4e2a\uff0c\u6240\u4ee5\u8fd9\u91cc\u6709\u95ee\u9898\u3002<\/p>\n<p>\u6b63\u89e3\u5e94\u8be5\u662ff\u6570\u7ec4\uff0c\u7b2c\u4e00\u7ef4\u5ea6\u662f\u7b2c\u51e0\u5f20\u5361\u7247\uff0c\u7b2c\u4e8c\u7ef4\u5ea6\u662f\u6b63\u53cd\u9762\uff0c\u90a3\u4e48\u6574\u4f53\u610f\u601d\u5c31\u662ff\u6570\u7ec4\u4ee3\u8868\u7b2ci\u5f20\u5361\u7247\u7684\u65f6\u5019\u7ec4\u5408\u51fa\u6765\u7684\u79cd\u7c7b\u6570\uff0c\u8f6c\u79fb\u65b9\u7a0b\u5c31\u662f<code>f[i][0] = (a[i] != a[i - 1]) * f[i - 1][0],f[i][0] = (a[i] != b[i - 1]) * f[i - 1][1]<\/code>,\u5982\u679c\u6b64\u65f6\u5361\u7247\u662f\u6b63\u9762\uff0c\u90a3\u4e48\u5b83\u53ef\u4ee5\u7531\u4e24\u79cd\u60c5\u51b5\u8f6c\u79fb\u8fc7\u6765\uff0c\u7b2c\u4e00\u79cd\u662f\u548c\u4e0a\u4e00\u5f20\u5361\u7247\u7684\u6b63\u9762\u4e0d\u4e00\u6837\u6765\u8f6c\u79fb\uff0c\u7b2c\u4e8c\u79cd\u662f\u548c\u4e0a\u4e00\u5f20\u5361\u7247\u7684\u53cd\u9762\u4e0d\u4e00\u6837\u8f6c\u79fb\uff0c\u7136\u540e\u5c31\u662f\u8fd9\u5f20\u5361\u7247\u7684\u6b63\u9762\u7684\u60c5\u51b5\uff0c\u53cd\u9762\u4ea6\u662f\u5982\u6b64\u3002<\/p>\n<pre><code class=\"lang-cpp\">#include&lt;map&gt;\n#include&lt;set&gt;\n#include&lt;stack&gt;\n#include&lt;queue&gt;\n#include&lt;cmath&gt;\n#include&lt;vector&gt;\n#include&lt;bitset&gt;\n#include&lt;cstdio&gt;\n#include&lt;cstring&gt;\n#include&lt;fstream&gt;\n#include&lt;cstdlib&gt;\n#include&lt;iostream&gt;\n#include&lt;algorithm&gt;\n#include&lt;unordered_map&gt;\n\nusing namespace std;\n#define x first\n#define y second\n#define endl &#039;\\n&#039;\n#define IOS                       \\\n    ios_base::sync_with_stdio(0); \\\n    cin.tie(0);                   \\\n    cout.tie(0);\ntypedef long long ll;\ntypedef pair&lt;int,int&gt; PII;\ntypedef unsigned long long ull;\nconst int INF = 0x3f3f3f3f, p = 998244353;\nconst int N = 2e5 + 10;\n\nint qmi(int n, int k, int p){\n    int res = 1 % p;\n    while(k){\n        if(k &amp; 1) res = 1ll * res * n % p;\n        n = 1ll * n * n % p;\n        k &gt;&gt;= 1;\n    }\n    return res;\n}\nint f[N][2];\nvoid solve(){\n    int n;\n    cin &gt;&gt; n;\n    vector&lt;PII&gt; q(n + 10);\n    for(int i = 1; i &lt;= n; i++){\n        int x, y;\n        cin &gt;&gt; x &gt;&gt; y;\n        q[i] = {x, y};\n    }\n    f[1][0] = f[1][1] = 0;\n    int p1 = q[1].x, p2 = q[1].y;\n    for(int i = 2; i &lt;= n; i++){\n        auto &amp;t = q[i];\n        if(p1 != t.x) f[i][0] = (f[i - 1][0] + 1) % p;\n        if(p2 != t.x) f[i][0] = (f[i - 1][1] + 1) % p;\n        if(p1 != t.y) f[i][1] = (f[i - 1][0] + 1) % p;\n        if(p2 != t.y) f[i][1] = (f[i - 1][1] + 1) % p;\n        p1 = t.x, p2 = t.y;\n    }\n    ll sum = (f[n][0] % p + f[n][1] % p) % p;\n    cout &lt;&lt; sum &lt;&lt; endl;\n}\nint main(){\n    IOS;\n    int t = 1;\n    \/\/ cin &gt;&gt; t;\n    while(t--){\n        solve();\n    }\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>solution \u8fd9\u9053\u9898\u521a\u5f00\u59cb\u60f3\u7684\u662f\u6240\u6709\u7684\u724c\u5411\u4e0a\u7684\u90a3\u4e00\u9762\u90fd\u4e0d\u4e00\u6837\uff0c\u7136\u540e\u5c31\u4e0d\u77e5\u9053\u600e\u4e48\u505a\u4e86\uff0c\u540e\u6765\u8bfb\u9898\u662f\u65c1\u8fb9\u7684\u724c\u4e0d\u4e00\u6837\u5c31\u884c\u3002\u7136\u540e\u60f3\u7684\u662f\u8fd9\u4e2a\u9b3c\u6837\u5b50 f[1][0] = f[1][1] = 0; int p1 = q[1].x, p2 = q[1].y; for(int i = 2; i &lt;= n; i++){ auto &amp;t = q[i]; if(p1 != t.x) f[i][0] = (f[i - 1][0] + 1) % p; if(p2 != t.x) f[i][0] = (f[i - 1][1] + 1) % p; if(p1 != t.y) f[i][1] = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[18],"class_list":["post-66","post","type-post","status-publish","format-standard","hentry","category-solution","tag-18"],"_links":{"self":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/66","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=66"}],"version-history":[{"count":0,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/66\/revisions"}],"wp:attachment":[{"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=66"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=66"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=66"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}