• <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算法程序設(shè)計(jì)空間

            // 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 閱讀(1638) 評論(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
            思路:
            設(shè)基數(shù)為X
            首先 如果兩個(gè)數(shù)對bs取模相等(為M) 則
            A = aX + M
            B = bX + M
            那么只要其中一個(gè)可以取到結(jié)果 即
            (10*(bX + M)+ C)MOD X = 0
            也就是(10*M)MOD X?+ C MOD X = 0
            則另一個(gè)必定也可以整除 X
            這樣在搜索的時(shí)候如果只需要搜索A (假設(shè)A<B) 就可以了
            也就是說如果我們按照BFS擴(kuò)展 把狀態(tài)設(shè)置為MOD值 則只需要M的長度的隊(duì)列就可以完成這個(gè)搜索了
            無解的情況如何?自然就是無法擴(kuò)展的情況。至于是否要優(yōu)化最后一層(即搜索到了所有的非0 mod值 我認(rèn)為沒有必要)
            注意不要把一個(gè)5000的字符串和其mod數(shù)封裝在一起作為隊(duì)列元素 會(huì)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;
            }
            寫這個(gè)的時(shí)候發(fā)現(xiàn)一首很好聽的歌
            《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   回復(fù)  更多評論   

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

            # re: PKU1465 Multiple   回復(fù)  更多評論   

            2008-10-04 19:57 by
            好像有缺陷
            麻豆久久久9性大片| 日本福利片国产午夜久久| 亚洲成av人片不卡无码久久| 丰满少妇人妻久久久久久4| 久久e热在这里只有国产中文精品99 | 久久久久亚洲精品日久生情| 久久婷婷五月综合成人D啪 | 亚洲欧洲精品成人久久奇米网| 99精品国产99久久久久久97| 狠狠人妻久久久久久综合| 香蕉久久av一区二区三区| 国产叼嘿久久精品久久| 伊人久久大香线蕉av一区| 久久久久久久国产免费看| 久久天堂AV综合合色蜜桃网| 久久青青国产| 久久香蕉一级毛片| 午夜欧美精品久久久久久久| 人妻无码久久精品| 日本精品久久久久中文字幕8| 国产欧美久久久精品影院| 国产精品美女久久久网AV| 久久香蕉超碰97国产精品| 免费精品久久天干天干| 久久久久亚洲AV无码专区网站| 久久久久综合网久久| 色综合久久久久久久久五月| 久久午夜免费视频| 久久久久无码精品| 国产精品欧美亚洲韩国日本久久| 91久久精品91久久性色| 无码AV波多野结衣久久| 国内精品久久久久影院薰衣草| 久久精品亚洲男人的天堂| 99久久精品免费看国产一区二区三区 | 久久精品国产久精国产果冻传媒 | 国产精品久久久久久久久久影院 | 久久亚洲精品无码AV红樱桃| 四虎国产精品成人免费久久| 久久人妻少妇嫩草AV蜜桃| 久久精品免费一区二区|