{"id":112,"date":"2010-08-29T08:28:08","date_gmt":"2010-08-29T00:28:08","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=112"},"modified":"2012-03-03T08:28:24","modified_gmt":"2012-03-03T00:28:24","slug":"zoj-2612-stable-sets","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/zoj-2612-stable-sets\/","title":{"rendered":"ZOJ 2612. Stable Sets"},"content":{"rendered":"<h3>Brief description :<\/h3>\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u6a21 r \u6574\u6570\u73af\uff0c\u5b50\u96c6 A \u5728\u591a\u9879\u5f0f p \u4e0b\u88ab\u79f0\u4e3a\u662f\u7a33\u5b9a\u7684\uff0c\u5f53\u4e14\u4ec5\u5f53\u96c6\u5408\u4e2d\u7684\u6570\u5b57\u4ee3\u5165 p \u4ee5\u540e\u7684\u8fd0\u7b97\u7ed3\u679c\uff0c\u521a\u597d\u4e5f\u662f A \u5b50\u96c6\u3002<br \/>\n\u9898\u76ee\u7ed9\u5b9a\u4e24\u7ec4\u591a\u9879\u5f0f p\u3001q\uff0c\u6c42\u540c\u65f6\u5728 p \u548c q \u4e0b\u90fd\u7a33\u5b9a\u7684\u5b50\u96c6\u7684\u7ec4\u6570\u3002<br \/>\n<!--more--><\/p>\n<h3>Analyse :<\/h3>\n<p>\u8fd9\u4e2a\u9898\uff0c\u4e0d\u96be\u60f3\u8c61\u6210\u4e00\u4e2a\u56fe\u8bba\u95ee\u9898\uff0c\u8003\u5bdf\u591a\u9879\u5f0f p\uff0c\u5bf9\u4e8e\u6bcf\u4e00\u7ec4 (i, p(i))\uff0c\u6211\u4eec\u8fde\u4e00\u6761 i \u5230 p(i) \u7684<br \/>\n\u6709\u5411\u8fb9\uff0c\u4e8e\u662f\u6c42\u4e00\u7ec4\u6781\u5c0f\u7684\u7a33\u5b9a\u96c6\u7b49\u4ef7\u4e8e\u56fe\u4e2d\u7684\u4e00\u7ec4\u5f3a\u8fde\u901a\u5206\u91cf\uff0c\u5982\u679c\u6700\u540e\u5b58\u5728 n \u4e2a component\uff0c\u90a3\u4e48\u6700\u540e\u7684\u7ed3\u679c\u4e0d\u96be\u5f97\u5230\u662f 2^n\u3002<\/p>\n<p>\u89c2\u5bdf\u56fe\u5f62\uff0c\u53d1\u73b0\u672c\u9898\u4e2d\u6240\u6709\u7684\u7ed3\u70b9\u51fa\u5ea6\u90fd\u4e3a 1\uff0c\u5373\u7531\u6b64\u53ef\u4ee5\u8bbe\u8ba1\u51fa\u4e00\u79cd\u7b80\u6613\u7684\u65b9\u6cd5\u6c42\u53d6\u5f3a\u8fde\u901a\u5206\u91cf\u7684\u65b9\u6cd5\uff0c\u6bcf\u6b21\u627e\u5230\u4e00\u4e2a\u5165\u5ea6\u4e3a 0 \u7684\u70b9\uff0c\uff08\u5219\u6b64\u70b9\u4e0d\u53ef\u80fd\u5728\u4e00\u4e2a\u73af\u7ed3\u6784\u7c7b\uff09<br \/>\n\u7528\u4e00\u4e2a\u961f\u5217\u548c\u5e76\u67e5\u96c6\u4e0d\u65ad\u7ef4\u62a4\u5373\u53ef\u3002\u53e6\u5916\u9700\u8981\u6ce8\u610f\u7684\u5219\u662f\u9700\u8981\u5728 p, q \u4e0b\u4fdd\u6301\u6781\u5c0f\u7a33\u5b9a\u6838\u4fdd\u6301\u76f8\u540c\uff0c\u800c\u8fd9\u79cd\u65b9\u6cd5\u5219\u53ef\u4ee5\u65b9\u4fbf\u7684\u5c06\u90a3\u4e9b\u5df2\u7ecf\u4e0d\u53ef\u80fd\u6784\u6210\u73af\u7ed3\u6784\u7684\u70b9\u4e22\u5f03\u5230\u4e00\u4e2a\u54d1\u7c7b\u4e2d\u3002\uff08\u5177\u4f53\u6b64\u5904\u7684\u5b9e\u73b0\u5462\u8fd8\u662f\u6709\u8bb8\u591a\u503c\u5f97\u5546\u8ba8\u7684\u5730\u65b9\u7684\u3002\uff09<\/p>\n<pre lang=\"cpp\" file=\"ZOJ_2612.cpp\">\r\n\/*\r\n    Author: xiaodao\r\n    Prog: ZOJ 2612. Stable Sets\r\n    Status: Accepted\r\n    Last modifiy: GMT +8 Aug. 29th 17:49\r\n*\/\r\n#include <iostream>\r\n#include <cstdio>\r\n#include <cstring>\r\n#include \"bignum.h\"\r\nusing namespace std;\r\nconst int N = 101;\r\nint A[N], n; int P[N];\r\nint r; bignum ans;\r\n\r\n\r\n\r\nint Find(int x){\r\n    if ( P[x] != x ) P[x] = Find(P[x]) ;\r\n    return P[x];\r\n}\r\n\r\nvoid Union(int x,int y){\r\n    x = Find(x); y = Find(y);\r\n    if (x < y) P[x] = y ; \/\/ # \r\n    else P[y] = x;\r\n}\r\n\r\n\r\nint p(int x){\r\n    int res = 0;\r\n    for (int i=n;i>=0;i--)\r\n        res = ((res * x) + A[i]) % r;\r\n    return res;\r\n}\r\n\r\nvoid input(){\r\n    scanf(\"%d\", &n);\r\n    for (int i=n;i>=0;i--)\r\n        scanf(\"%d\", &A[i]);\r\n\r\n    int in[N];\r\n    memset(in, 0, sizeof(in));\r\n    for (int i=0;i<r;i++) in[p(i)]++;\r\n\r\n    int L = 0, R = 0, Q[N];\r\n    for (int i=0;i<r;i++)\r\n        if (in[i]==0) Q[R++] = i;\r\n    while (L<R){\r\n        int x = p(Q[L]); in[x]--;\r\n        if (in[x]==0) Q[R++] = x;\r\n        L++;\r\n    }\r\n\r\n    for (int i=0;i<R;i++)\r\n        Union(Q[i], r);\r\n    for (int i=0;i<r;i++)\r\n        if (in[i]!=0 &#038;&#038; Find(i)!=r) Union(i, p(i));\r\n}\r\n\r\nvoid stat(){\r\n    int component = 0;\r\n    for (int i=0;i<r;i++ )\r\n        if (P[i]==i) component++;\r\n    ans = pow(2, component);\r\n}\r\n\r\nvoid init(){\r\n    for (int i=0;i<=r;i++)\r\n        P[i] = i;\r\n}\r\n\r\nint main(){\r\n    while (cin >> r && r>0){\r\n        init(); input(); input(); stat();\r\n        cout << ans << endl;\r\n    }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Brief description : \u7ed9\u5b9a\u4e00\u4e2a\u6a21 r \u6574\u6570\u73af\uff0c\u5b50\u96c6 A \u5728\u591a\u9879\u5f0f p \u4e0b\u88ab\u79f0\u4e3a\u662f\u7a33\u5b9a\u7684\uff0c\u5f53\u4e14\u4ec5\u5f53\u96c6\u5408\u4e2d\u7684\u6570\u5b57\u4ee3\u5165 p \u4ee5\u540e\u7684\u8fd0\u7b97\u7ed3\u679c\uff0c\u521a\u597d\u4e5f\u662f A \u5b50\u96c6\u3002 \u9898\u76ee\u7ed9\u5b9a\u4e24\u7ec4\u591a\u9879\u5f0f p\u3001q\uff0c\u6c42\u540c\u65f6\u5728 p \u548c q \u4e0b\u90fd\u7a33\u5b9a\u7684\u5b50\u96c6\u7684\u7ec4\u6570\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1],"tags":[],"class_list":["post-112","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-1O","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/112","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/comments?post=112"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/112\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=112"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}