• <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 - 7,comments - 3,trackbacks - 0
            傳送門:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3726

            一道看似博弈論的題,其實就是模板題而已。

            分析:
            平面上N個點,兩個人輪流取點,而且規定當前取的點和上一個取的點的曼哈頓距離要小于L,所以,點可以看成兩兩成對消去。
            這也就轉成了一般圖匹配,如果存在完美匹配,那么后手的人總可以取完,如果不存在,那么先手的人可以拿一個孤立點,這樣第二個人要么沒有匹配點,要么只能拆到一個匹配對,但這樣又造成了孤立點。

            網上有個人拿二分圖匹配過了....看來數據很弱.....
            代碼:
            #include <cstdio>
            #include 
            <cstring>
            #include 
            <algorithm>
            #include 
            <iostream>
            #include 
            <cmath>
            #define MAXN 450
            using namespace std;

            int x[MAXN], y[MAXN];

            struct Graph
            {
                
            bool mat[MAXN + 1][MAXN + 1];
                
            int n;

                
            bool inque[MAXN + 1];
                
            int que[MAXN], head, tail;

                
            int match[MAXN + 1], father[MAXN + 1], base[MAXN + 1];

                
            void init(int _n)
                {
                    n 
            = _n;
                    
            for (int i = 1; i <= n; ++i)
                    {
                        match[i] 
            = 0;
                        
            for (int j = 1; j <= n; ++j)
                            mat[i][j] 
            = false;
                    }
                }

                
            int pop()
                {
                    
            return que[head++];
                }

                
            void push(int x)
                {
                    que[tail
            ++= x;
                    inque[x] 
            = true;
                }

                
            void add_edge(int a, int b)
                {
                    mat[a][b] 
            = mat[b][a] = true;
                }

                
            int inpath[MAXN + 1];
                
            static int pcnt;

                
            int find_ancestor(int u, int v)
                {
                    
            ++pcnt;
                    
            while (u)
                    {
                        u 
            = base[u];
                        inpath[u] 
            = pcnt;
                        u 
            = father[match[u]];
                    }

                    
            while (true)
                    {
                        v 
            = base[v];
                        
            if (inpath[v] == pcnt)
                            
            return v;
                        v 
            = father[match[v]];
                    }
                }

                
            int inblossom[MAXN + 1];
                
            static int bcnt;

                
            void reset(int u, int anc)
                {
                    
            while (u != anc)
                    {
                        
            int v = match[u];
                        inblossom[
            base[v]] = bcnt;
                        inblossom[
            base[u]] = bcnt;
                        v 
            = father[v];
                        
            if (base[v] != anc) father[v] = match[u];
                        u 
            = v;
                    }
                }

                
            void contract(int u, int v)
                {
                    
            int anc = find_ancestor(u, v);
                    
            ++bcnt;
                    reset(u, anc);
                    reset(v, anc);
                    
            if (base[u] != anc) father[u] = v;
                    
            if (base[v] != anc) father[v] = u;
                    
            for (int i = 1; i <= n; ++i)
                        
            if (inblossom[base[i]] == bcnt)
                        {
                            
            base[i] = anc;
                            
            if (!inque[i]) push(i);
                        }
                }

                
            int find_augment(int start)
                {
                    
            for (int i = 1; i <= n; ++i)
                    {
                        father[i] 
            = 0;
                        inque[i] 
            = false;
                        
            base[i] = i;
                    }
                    head 
            = 0, tail = 0, push(start);
                    
            while (head < tail)
                    {
                        
            int u = pop();
                        
            for (int v = 1; v <= n; ++v)
                            
            if (mat[u][v] && base[v] != base[u] && match[v] != u)
                            {
                                
            if (v == start || (match[v] && father[match[v]]))
                                    contract(u, v);
                                
            else
                                {
                                    
            if (father[v] == 0)
                                    {
                                        
            if (match[v])
                                        {
                                            push(match[v]);
                                            father[v] 
            = u;
                                        }
                                        
            else
                                        {
                                            father[v] 
            = u;
                                            
            return v;
                                        }
                                    }
                                }
                            }
                    }
                    
            return 0;
                }

                
            void augment(int finish)
                {
                    
            int u = finish, v, w;
                    
            while (u)
                    {
                        v 
            = father[u];
                        w 
            = match[v];
                        match[u] 
            = v;
                        match[v] 
            = u;
                        u 
            = w;
                    }
                }

                
            int graph_max_match()
                {
                    
            int ans = 0;
                    
            for (int i = 1; i <= n; ++i)
                        
            if (match[i] == 0)
                        {
                            
            int finish = find_augment(i);
                            
            if (finish)
                            {
                                augment(finish);
                                ans 
            += 2;
                            }
                        }
                    
            return ans;
                }
            } g;

            int Graph :: bcnt = 0, Graph :: pcnt = 0;

            int dis(int i, int j, int l)
            {
                
            int d;
                d 
            = abs(x[i] - x[j]) + abs(y[i] - y[j]);
                
            if (d <= l) return 1;
                
            else return 0;
            }

            int main()
            {
                
            int n;
                
            while (scanf("%d"&n) != EOF)
                {
                    
            int l;
                    g.init(n);
                    
            for (int i = 1; i <= n; ++i)
                        scanf(
            "%d%d"&x[i], &y[i]);
                    scanf(
            "%d"&l);
                    
            for (int i = 1; i < n; ++i)
                        
            for (int j = i + 1; j <= n; ++j)
                        {
                            
            if (dis(i, j, l)) g.add_edge(i, j);
                        }
                    
            int sum;
                    sum 
            = g.graph_max_match();
                    
            if (sum == n) puts("YES");
                    
            else puts("NO");
                }
                
            return 0;
            }
            posted on 2011-10-15 22:17 LLawliet 閱讀(164) 評論(0)  編輯 收藏 引用 所屬分類: 圖論
            日韩精品无码久久久久久| 狠狠精品久久久无码中文字幕| 久久se这里只有精品| 欧美久久久久久午夜精品| 伊人久久无码精品中文字幕| 性做久久久久久久久浪潮| 亚洲午夜久久久久久久久电影网 | 久久热这里只有精品在线观看| 亚洲国产视频久久| 久久国产精品77777| 久久93精品国产91久久综合| 国内精品伊人久久久久影院对白| 国产精品美女久久久久AV福利 | 久久91精品国产91| 久久精品国产亚洲AV久| 久久久亚洲AV波多野结衣| 无码伊人66久久大杳蕉网站谷歌| 欧美日韩久久中文字幕| 狠狠色狠狠色综合久久| 色偷偷久久一区二区三区| 亚洲精品tv久久久久| 欧美精品乱码99久久蜜桃| 久久香蕉超碰97国产精品| 日韩一区二区久久久久久| 久久九色综合九色99伊人| 久久精品国产AV一区二区三区 | 少妇人妻综合久久中文字幕| 亚洲AV无码久久精品蜜桃| 久久精品国产亚洲综合色| 国产日韩久久免费影院| 久久99九九国产免费看小说| 国产精品久久久福利| 久久久久亚洲AV综合波多野结衣| 久久亚洲AV成人无码软件| 免费国产99久久久香蕉| 污污内射久久一区二区欧美日韩| 久久精品青青草原伊人| 久久精品国产亚洲综合色| 狠狠人妻久久久久久综合| 欧美日韩中文字幕久久久不卡| 亚洲va久久久久|