• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            算法學社
            記錄難忘的征途
            posts - 141,comments - 220,trackbacks - 0
            題目描述:
               給一個(N<10,000)的有向無環(huán)圖,有M個物體坐落在若干個點上。A和B每次可以將某物體沿著某條邊移動一次。多個物體可以重合。不能移動者算輸。
            算法分析:
               SG定理,可以先拓撲排序然后再SG。
             1 #include<algorithm>
             2 #include<cstdio>
             3 #include<iostream>
             4 #include<bitset>
             5 using namespace std;
             6 int n,m;
             7 const int N = 10005;
             8 const int M = 100005;
             9 int head[N],nxt[M],pnt[M],e,dp[N];
            10 inline void add(int u,int v){
            11     nxt[e] = head[u]; head[u] = e; pnt[e++] = v;
            12 }
            13 struct node{int id,pre;} tmp[N];
            14 int tim,vis[N];
            15 void dfs(int u){
            16     vis[u] =1;
            17     for(int i = head[u]; i!= -1; i=nxt[i]){
            18         if(!vis[pnt[i]]) dfs(pnt[i]);
            19     }
            20     tmp[u].id = u;
            21     tmp[u].pre=tim++;
            22 }
            23 bool cmp(node a,node b){return a.pre < b.pre;}
            24 void process(){
            25     tim =0;
            26     for(int i = 1; i <= n; i++) vis[i] = 0;
            27     for(int i = 1; i <= n; i++) if(!vis[i]) dfs(i);
            28     sort(tmp+1,tmp+n+1,cmp);
            29     bitset<2*N> mp;
            30     for(int p = 1; p <= n; p++) {
            31         int u = tmp[p].id;
            32         mp.reset();
            33         for(int i = head[u]; i!=-1; i=nxt[i]){
            34             int v = pnt[i];
            35             mp[dp[v]] = 1;
            36         }
            37         for(int i = 0; i < mp.size(); i++) if(!mp[i]){
            38             dp[u] = i;
            39             break;
            40         }
            41     }
            42 }
            43 int main(){
            44     int ctest = 1;
            45     while(scanf("%d",&n)!=EOF){
            46         for(int i = 1; i <= n; i++) head[i] = -1;
            47         e = 0;
            48         for(int i = 1; i < n; i++ ){
            49             int t,v;
            50             scanf("%d",&t);
            51             while(t--){
            52                 scanf("%d",&v);
            53                 add(i,v);
            54             }
            55         }
            56         process();
            57         int t; scanf("%d",&t);
            58         printf("Case %d:\n",ctest++);
            59         while(t--){
            60             int val = 0,c,v;
            61             scanf("%d",&c);
            62             while(c--) {
            63                 scanf("%d",&v);
            64                 val ^= dp[v];
            65             }
            66             puts(val?"Alice":"Bob");
            67         }
            68     }
            69 }
            70 
            posted on 2012-12-23 14:04 西月弦 閱讀(425) 評論(0)  編輯 收藏 引用
            久久久精品2019免费观看| 国产无套内射久久久国产| 久久久久久久91精品免费观看| 天堂无码久久综合东京热| 亚洲级αV无码毛片久久精品 | 久久精品中文字幕有码| A级毛片无码久久精品免费| 久久精品夜夜夜夜夜久久| 亚洲国产精品无码久久青草 | 久久www免费人成精品香蕉| 亚洲欧美成人久久综合中文网| 久久午夜羞羞影院免费观看| 久久一区二区免费播放| 久久久久99精品成人片试看 | 思思久久好好热精品国产| 久久精品国产99久久久| 伊人久久亚洲综合影院| 国产精品亚洲综合专区片高清久久久| 亚洲中文字幕无码一久久区| 久久人人爽人人爽人人片AV东京热| 久久丫精品国产亚洲av不卡 | 亚洲AV无码久久寂寞少妇| 内射无码专区久久亚洲| 亚洲国产精品久久久久久| 久久精品毛片免费观看| 亚洲午夜无码久久久久小说| 狠狠久久综合| 久久99国产精一区二区三区| 久久久精品国产sm调教网站| 亚洲精品无码久久久久去q| 久久综合偷偷噜噜噜色| 中文成人无码精品久久久不卡 | 亚洲国产精品无码久久九九| 久久人人爽人人精品视频| 久久影视国产亚洲| 久久精品成人免费国产片小草| 热久久这里只有精品| 日本久久久精品中文字幕| 久久电影网2021| 91精品国产高清久久久久久国产嫩草| 久久精品国产影库免费看|