• <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>

            TOJ 2551 Stargates

             1 /*
             2  * File:   F.cpp
             3  * Author: GongZhi
             4  *
             5  * Created on 2009年7月27日, 下午12:19
             6  */
             7 
             8 #include <stdlib.h>
             9 #include <string.h>
            10 #include <stdio.h>
            11 /*
            12  *
            13  */
            14 const int MAX = 6100000;
            15 int uset[MAX];
            16 int n;
            17 int root(int k) {
            18     int t = k;
            19     while (uset[t] != t)
            20         t = uset[t];
            21     while (uset[k] != k) {
            22         int p = uset[k];
            23         uset[k] = t;
            24         k = p;
            25     }
            26     return uset[k];
            27 }
            28 
            29 int init(int n) {
            30     for (int i = 0; i <= n; ++i)
            31         uset[i] = i;
            32     return 0;
            33 }
            34 
            35 int query(int src, int dst, int ss, int ds, int nnn) {
            36     int ans=0;
            37     for (int i = 0; src<=&& dst<=&& i < nnn; ++i) {
            38         int a = root(src);
            39         int b = root(dst);
            40         if (a == b)
            41             ++ans;
            42         src += ss;
            43         dst += ds;
            44     }
            45     printf("%d - %d\n", ans, nnn - ans);
            46     return 0;
            47 }
            48 
            49 int join(int src, int dst, int ss, int ds, int nnn) {
            50     int ans = 0;
            51     for (int i = 0; src<=&& dst<=&& i < nnn; ++i) {
            52         int a = src;//root(src);
            53         int b = root(dst);
            54         uset[b] = a;
            55         src += ss;
            56         dst += ds;
            57     }
            58     return 0;
            59 }
            60 
            61 int get(char* s)
            62 {
            63     int i=0;
            64     char c;
            65     while(true)
            66     {
            67         c=getchar();
            68         if(c==-1)return -1;
            69         if(c=='\n')break;
            70         s[i]=c;
            71         ++i;
            72     }
            73     s[i]=0;
            74     return 1;
            75 }
            76 
            77 int main(int argc, char** argv) {
            78     char line[1024];
            79     //freopen("in.txt","r",stdin);
            80     while (gets(line)!=NULL) {
            81         int src = 0, dst = 0;
            82         int nnn = 1, ss = 0, ds = 1;
            83         char tmp[100];
            84         if (line[0== 'D' || line[0== 'd') {
            85             sscanf(line, "%s%d", tmp, &n);
            86             init(n);
            87         } else {
            88             int i;
            89             sscanf(line,"%s%d%d%d%d%d",tmp,&src,&dst,&nnn,&ds,&ss);
            90             if (line[0== 'Q' || line[0== 'q')
            91                 query(src, dst, ss, ds, nnn);
            92             else
            93                 join(src, dst, ss, ds, nnn);
            94         }
            95     }
            96     return (EXIT_SUCCESS);
            97 }
            98 

            posted on 2009-07-27 15:58 gong 閱讀(963) 評論(1)  編輯 收藏 引用

            評論

            # re: TOJ 2551 Stargates 2009-07-28 15:20 個性藝術簽名

            這些從現(xiàn)在才  回復  更多評論   

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導航

            統(tǒng)計

            常用鏈接

            留言簿(6)

            隨筆檔案

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            久久久久久曰本AV免费免费| 久久综合久久综合久久| 欧美一级久久久久久久大片| 亚洲美日韩Av中文字幕无码久久久妻妇 | 久久久久亚洲?V成人无码| 国产欧美久久久精品影院| 99久久综合狠狠综合久久止| 久久伊人色| 日本精品久久久中文字幕| 久久成人国产精品免费软件| 精品精品国产自在久久高清| 久久精品国产亚洲AV不卡| www亚洲欲色成人久久精品| 伊人久久综合成人网| 久久久久18| 久久91精品国产91久久麻豆| 久久AV高潮AV无码AV| 99热都是精品久久久久久| 久久久噜噜噜www成人网| 香蕉99久久国产综合精品宅男自 | 久久久久久亚洲精品不卡| 婷婷五月深深久久精品| 日韩中文久久| 九九久久精品国产| 91性高湖久久久久| 国产高潮国产高潮久久久| 久久人人爽人人爽人人片AV东京热| 99久久夜色精品国产网站| 99久久成人国产精品免费| 久久亚洲精品国产精品| 色综合久久夜色精品国产| 久久天天日天天操综合伊人av| 日韩精品久久久久久| 久久精品国产半推半就| 日韩精品久久久久久| 久久综合狠狠综合久久激情 | 久久伊人精品青青草原高清| 久久久久夜夜夜精品国产| 国产精品视频久久| 9191精品国产免费久久| 国产精品久久久久一区二区三区|