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

            oyjpArt ACM/ICPC算法程序設計空間

            // I am new in programming, welcome to my blog
            I am oyjpart(alpc12, 四城)
            posts - 224, comments - 694, trackbacks - 0, articles - 6

            PKU1465 Multiple

            Posted on 2007-01-15 15:11 oyjpart 閱讀(1637) 評論(2)  編輯 收藏 引用 所屬分類: ACM/ICPC或其他比賽

            Multiple
            Time Limit:1000MS? Memory Limit:32768K
            Total Submit:992 Accepted:221

            Description
            a program that, given a natural number N between 0 and 4999 (inclusively), and M distinct decimal digits X1,X2..XM (at least one), finds the smallest strictly positive multiple of N that has no other digits besides X1,X2..XM (if such a multiple exists).

            Input
            The input has several data sets separated by an empty line, each data set having the following format:

            On the first line - the number N
            On the second line - the number M
            On the following M lines - the digits X1,X2..XM.

            Output
            For each data set, the program should write to standard output on a single line the multiple, if such a multiple exists, and 0 otherwise.

            An example of input and output:

            Sample Input

            22
            3
            7
            0
            1
            
            2
            1
            1

            Sample Output

            110
            0
            思路:
            設基數為X
            首先 如果兩個數對bs取模相等(為M) 則
            A = aX + M
            B = bX + M
            那么只要其中一個可以取到結果 即
            (10*(bX + M)+ C)MOD X = 0
            也就是(10*M)MOD X?+ C MOD X = 0
            則另一個必定也可以整除 X
            這樣在搜索的時候如果只需要搜索A (假設A<B) 就可以了
            也就是說如果我們按照BFS擴展 把狀態設置為MOD值 則只需要M的長度的隊列就可以完成這個搜索了
            無解的情況如何?自然就是無法擴展的情況。至于是否要優化最后一層(即搜索到了所有的非0 mod值 我認為沒有必要)
            注意不要把一個5000的字符串和其mod數封裝在一起作為隊列元素 會TLE的 呵呵
            Solution:
            //by Optmistic
            #include <algorithm>
            using namespace std;
            const int N = 5010;
            struct E{char num; int m; E * f;};
            E q[N];
            int cd[10], X;
            bool chk[N];
            void print(const E& e) {
            ?if(e.f)?{
            ??print(*e.f);
            ??printf("%c", e.num);
            ?}
            }
            int main() {
            ?int i, nc;
            ?while(scanf("%d", &X)!=EOF) {
            ??scanf("%d", &nc);
            ??memset(chk, 0, sizeof(chk));
            ??for(i = 0; i<nc; i++)
            ???scanf("%d", cd+i);
            ??if(X == 0) {printf("0\n");continue;}
            ??sort(cd, cd+nc);
            ??int qs = 0, qe = 1;
            ??q[0].m = 0;
            ??q[0].f = NULL;
            ??E * first = &q[0];
            ??while(qs < qe) {
            ???E cur = q[qs];
            ???E now;
            ???now.f = &q[qs];
            ???int m = cur.m;
            ???for(i = 0; i< nc; i++) {
            ????int s = (10*m+cd[i])%X;
            ????if(!chk[s] && (now.f != first || cd[i] > 0) ) {
            ?????now.m = s;
            ?????now.num = cd[i]+'0';
            ?????q[qe++] = now;
            ?????chk[s] = 1;
            ?????if(s == 0) {
            ??????print(now);
            ??????putchar('\n');
            ??????goto HERE;
            ?????}
            ????}
            ???}
            ???qs++;
            ??}
            HERE:??if(qs == qe) printf("0\n");
            ?}
            ?return 0;
            }
            寫這個的時候發現一首很好聽的歌
            《No promises》
            shayne ward

            Hey baby, when we are together, doing things that we love.
            Every time you're near I feel like I’m in heaven, feeling high
            I don’t want to let go, girl.
            I just need you to know girl.
            I don’t wanna run away, baby you’re the one I need tonight,
            No promises.
            Baby, now I need to hold you tight, I just wanna die in your arms
            Here tonight
            Hey baby, when we are together, doing things that we love.
            Everytime you're near I feel like I’m in heaven, feeling high
            I don’t want to let go, girl.
            I just need you you to know girl.
            I don’t wanna run away, baby you’re the one I need tonight,
            No promises.
            Baby, now I need to hold you tight, I just wanna die in your arms
            I don’t want to run away, I want to stay forever, thru Time and Time..
            No promises
            I don’t wanna run away, I don’t wanna be alone
            No Promises
            Baby, now I need to hold you tight, now and forever my love
            No promises
            I don’t wanna run away, baby you’re the one I need tonight,
            No promises.
            Baby, now I need to hold you tight, I just wanna die in your arms
            I don’t wanna run away, baby you’re the one I need tonight,
            No promises.
            Baby, now I need to hold you tight, I just wanna die in your arms
            Here tonight..

            Feedback

            # re: PKU1465 Multiple   回復  更多評論   

            2008-06-23 20:28 by sdfond
            shayne ward的歌有幾首都不錯^^

            # re: PKU1465 Multiple   回復  更多評論   

            2008-10-04 19:57 by
            好像有缺陷
            亚洲国产成人乱码精品女人久久久不卡 | 亚洲日本久久久午夜精品| 久久精品成人欧美大片 | 久久久精品无码专区不卡| 欧美色综合久久久久久| 国内精品久久久久影院薰衣草| 国产情侣久久久久aⅴ免费| 久久久这里有精品中文字幕| 国产精品美女久久福利网站| 99热精品久久只有精品| 亚洲狠狠婷婷综合久久蜜芽| 久久精品一区二区| 久久精品一本到99热免费| 国产精品综合久久第一页 | 亚洲欧美精品一区久久中文字幕| 精品久久久无码人妻中文字幕豆芽 | 欧美精品一本久久男人的天堂| 久久伊人精品一区二区三区| 精品久久久久中文字| 国产午夜福利精品久久2021| 伊人热热久久原色播放www| 7国产欧美日韩综合天堂中文久久久久| 蜜桃麻豆WWW久久囤产精品| 91久久精品视频| 久久精品国产免费| 成人精品一区二区久久久| 久久99国产综合精品免费| 人人妻久久人人澡人人爽人人精品| 国产视频久久| 国产免费久久精品99久久| 久久久国产精品网站| 亚洲国产成人久久精品影视| 欧美亚洲色综久久精品国产| 亚洲精品高清一二区久久| 久久中文字幕视频、最近更新| 久久亚洲欧美日本精品| 亚洲狠狠综合久久| 777久久精品一区二区三区无码| 久久香蕉综合色一综合色88| 中文精品久久久久国产网址| 久久99精品国产麻豆不卡|