• <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>
            算法學(xué)社
            記錄難忘的征途
            posts - 141,comments - 220,trackbacks - 0
            題目描述:
               平面上有N<300個(gè)點(diǎn)。每個(gè)兩個(gè)點(diǎn)如果距離小于R且之間沒(méi)有共線的另一個(gè)點(diǎn),則這兩點(diǎn)之間有一條邊。求這個(gè)圖的生成樹的個(gè)數(shù)mod 10007。

            算法分析:
               用O(N*NlogN)的方法建圖。即枚舉每個(gè)點(diǎn)然后極角排序來(lái)判斷是否存在共線的點(diǎn)。
               
               建圖之后的任務(wù)是統(tǒng)計(jì)生成樹的個(gè)數(shù),方法是求這個(gè)圖的Krichhoof矩陣的n-1主行列式的值。
               Krichhoof矩陣G是這樣的:
                  Gii等于點(diǎn)i的度數(shù)
                  當(dāng)i和j有邊時(shí),Gij = -1。否則Gij等于0。
               
               然后行列式求值。方法是高斯消元求上三角陣。行列式的值等于對(duì)角線元素的積。
               由于是整數(shù)然后再mod。我們?cè)傧獣r(shí)需要求最小公倍數(shù)。還需要拓展歐幾里得算法求逆元。
               總之是比較綜合的一道好題。

            #include<iostream>
            #include<algorithm>
            #include<cassert>
            #include<cstdio>
            #include<complex>
            #include<cmath>
            using namespace std;
            // geometry
            const double eps = 1e-9;
            const int N = 300 + 10;
            #define X real
            #define Y imag
            typedef complex <double> pnt;
            pnt num[N];
            static double cross (const pnt &a, const pnt &b) { return Y(conj(a) * b);}
            pair <double,int> hash[N];
            int tp;
            bool cmp(const pair<double,int> &a , const pair<double,int> &b){
                #define  ff first
                #define  ss second
                return (a.ff - b.ff) < eps ? abs(num[a.ss] - num[tp]) < abs(num[b.ss] - num[tp]): a.ff < b.ff;
            }
            // lcm
            const int mod = 10007;
            int G[N][N],vis[N];
            int gcd(int a,int b) { return b ? gcd(b , a%b) : a;}
            int lcm(int a,int b){
                return a * b / gcd(a,b);
            }
            // exgcd
            int res[mod];
            void exgcd(int a,int b,int &x,int &y){
                if( b== 0) {
                    x = 1; y = 0; return ;
                }
                exgcd(b, a%b, x, y);
                int t = y; y = x - a/b*y; x = t;
            }
            int cal_res(int v) {
                int x, y;
                exgcd(v, mod, x, y);
                return (x + mod) % mod;
            }
            // main
            int main(){
                int test;
                cin >> test ;
                for(int i=1;i<mod;i++) res[i] = cal_res(i);
                while(test -- ){
                    int n,r;
                    scanf("%d%d",&n,&r);
                    for(int i=0;i<n;i++){
                        int x,y;
                        scanf("%d%d",&x,&y);
                        num[i] = pnt(x,y);
                    }
                    for(int i=0;i<n;i++) for(int j=0;j<n;j++) G[i][j] = 0;
                    for(tp=0;tp<n;tp++) {
                        int len = 0;
                        for(int j=0; j< n;j ++) if(tp != j) 
                            hash[len ++] = make_pair(arg(num[j] - num[tp]),j);
                        sort(hash, hash + len);
                        for(int j=0; j<len; j++) if(!j || abs(hash[j].first - hash[j-1].first) > eps) {
                            int v = hash[j].second;
                            if(abs(num[tp] - num[v]) < r + eps){
                                G[tp][v] = mod - 1;
                                G[tp][tp] ++;
                            }
                        }
                    }
                    // gauss
                    n --;
                    int ans = 1;
                    for(int i=0;i<n;i++) vis[i] = 0;
                    for(int i=0;i<n;i++) {
                        int s = -1;
                        for(int j=0;j<n;j++) if(!vis[j] && G[j][i]){
                            s = j; break;
                        }
                        if(s == -1) {
                            ans = 0;
                            break;
                        }
                        ans = (ans * G[s][i]) % mod;
                        vis[s] = 1;
                        for(int j=0;j<n;j++) if(!vis[j] && G[j][i]) {
                            int c = lcm(G[j][i], G[s][i]);
                            int t = c / G[j][i];
                            int p = c / G[s][i];
                            assert(t < mod);
                            ans = (ans * res[t]) % mod;
                            for(int k = i; k< n; k++) {
                                G[j][k] = (G[j][k] * t - G[s][k] * p) % mod;
                                G[j][k] = (G[j][k] + mod) % mod;
                            }
                        }
                    }
                    cout << (ans == 0 ? -1 : ans) << endl;
                }
            }
            posted on 2012-07-29 22:29 西月弦 閱讀(440) 評(píng)論(0)  編輯 收藏 引用 所屬分類: 解題報(bào)告
            国产叼嘿久久精品久久| 久久人妻少妇嫩草AV蜜桃| 久久久噜噜噜www成人网| 久久九九久精品国产免费直播| 久久天天躁狠狠躁夜夜不卡| 日产精品久久久久久久性色| 狠狠人妻久久久久久综合蜜桃 | 亚洲精品无码久久久久| 国产精品久久国产精麻豆99网站| 国内精品久久久久影院免费| 欧美伊人久久大香线蕉综合69| 精品免费久久久久久久| 性做久久久久久久久浪潮| 久久国产精品久久久| 久久久久久久久无码精品亚洲日韩| 国产午夜电影久久| 999久久久免费国产精品播放| 亚洲αv久久久噜噜噜噜噜| 久久综合鬼色88久久精品综合自在自线噜噜| 国产成人久久AV免费| 久久精品中文字幕久久| 国产精品一久久香蕉产线看 | 色综合久久88色综合天天| 精品伊人久久久| 精品久久久久久成人AV| 亚洲国产精品一区二区久久hs| 国产免费久久精品99re丫y| 97精品依人久久久大香线蕉97 | 亚洲国产二区三区久久| 国产精品成人精品久久久| 久久精品这里热有精品| 亚洲欧美一区二区三区久久| 久久久久亚洲AV无码观看| 麻豆一区二区99久久久久| 久久国产乱子精品免费女| 久久精品国产黑森林| 久久精品无码一区二区无码| 久久噜噜久久久精品66| 久久综合给合久久国产免费| 99久久免费国产精品| 久久久久AV综合网成人|