• <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>
            Welcome to Leon's Blog  
            日歷
            <2008年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789
            統(tǒng)計
            • 隨筆 - 30
            • 文章 - 0
            • 評論 - 51
            • 引用 - 0

            導(dǎo)航

            常用鏈接

            留言簿(4)

            隨筆分類

            隨筆檔案

            ACM

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

             
                   今天早上終于提交成功了!這道題做了有一個星期多了,老是找不到原因。今天在偶然間發(fā)現(xiàn)了,先將代碼貼出來,還請大家指正!感謝steven和一個匿名網(wǎng)友的建議,謝謝你們!但是程序運行的時間還是過長,希望大家能夠幫助修改。

              1#include <stdio.h>
              2#include <string.h>
              3#include <stdlib.h>
              4
              5
              6int result[4];
              7int reNumber, reCount, tie, reMax;        //result是最終客戶的郵票種類,reCount是客戶郵票總個數(shù),reNumber是客戶不同郵票的個數(shù)
              8                                                    
              9int GetNumber(int *stamp, int *customer, int *stampNumber, int *customerNumber)        //獲取郵票 和 客戶信息。
             10{
             11    int i, n,count[100];    // count在這里起到一個優(yōu)化的作用。
             12    n = 0;
             13    (*stampNumber) = 0;
             14    memset(count, 0 ,sizeof(int)*100);
             15    while(1)        //收集關(guān)于郵票的面值。
             16    {
             17        if(scanf("%d"&n) == EOF)
             18            return -1;
             19        if(n == 0)
             20            break;
             21        if(count[n]++ < 5)
             22            stamp[(*stampNumber)++= n;
             23    }

             24    //stampNumber--;
             25    (*customerNumber) = 0;
             26    while(1)
             27    {
             28        scanf("%d"&n);        //收集關(guān)于客戶需要郵票的總面值數(shù)。
             29        if(n == 0)
             30            break;
             31        customer[(*customerNumber)++= n;
             32    }

             33    return 1;
             34}

             35int NotSame(int *number,const int count, int *m,int *stamp)        //求不同一組郵票類別的個數(shù)和郵票的最大面值。
             36{
             37    int i,j, c,s;
             38    c = 0;
             39    *= stamp[number[0]];
             40    for(i = 0; i < count; i++)
             41    {
             42        if*< stamp[number[i]])        //求最大面值的郵票
             43            *= stamp[number[i]];
             44        s = 0;
             45        for(j = 0; j < i; j++)        //求不同面值郵票的個數(shù)
             46        {
             47            if(number[i] == number [j])
             48            {
             49                s = 1;
             50                break;
             51            }

             52        }

             53        if(0 == s)
             54            c++;
             55    }

             56    return c;
             57}

             58
             59
             60void Divide(int sum, int *number, int *stamp,int n, int *count, int same,int start)
             61{
             62    int i;
             63    int t;
             64    if*count > 4 ) 
             65            return;
             66    else if( sum == 0 && *count <= 4)        //郵票個數(shù)《=4的時候且保存在數(shù)組number中的郵票面值=sum的時候。    
             67    {
             68        same = NotSame(number, *count,&t, stamp);
             69        if( same > reNumber || same == reNumber && reCount > *count || same == reNumber && reCount == *count && reMax < t )//根據(jù)不同的條件來判斷。
             70        {
             71            reMax = t;
             72            reCount = *count;
             73            reNumber = same;
             74            for(i = 0; i < *count; i++)
             75                result[i] = number[i];
             76            tie = 0;
             77        }

             78        else if(same == reNumber && reCount == *count && reMax == t)//當郵票面值的最大值、郵票種類數(shù),郵票個數(shù)相等時。
             79        {
             80            tie = 1;
             81        }

             82
             83        return;
             84    }

             85    for(i = start; i < n; i++)        //遞歸搜索
             86    {
             87        sum -= stamp[i];
             88        if(sum >= 0)
             89        {
             90            number[(*count)++= i;
             91            Divide(sum, number, stamp, n, count,same,i);
             92            (*count)--;
             93        }

             94        sum += stamp[i];
             95    }
                
             96}

             97
             98
             99int main(int argc, char* argv[])
            100{
            101    int stamp[100], customer[100];        //stamp保存郵票的面值,customer保存客戶需要郵票的總面值。
            102    int number[5];        //臨時數(shù)據(jù),記錄滿足條件的臨時結(jié)果。此前提交一直WA的原因是number分配的空間太小了!
            103    int count,stampNumber = -1, customerNumber = -1;//stampNumber是郵票的個數(shù),customerNumber是客戶個數(shù) 
            104    int i,j;
            105
            106    do
            107    {    
            108        memset(stamp, 0100*sizeof(int));
            109        memset(customer, 0100*sizeof(int));
            110        memset(number, 0 ,4);
            111        if(GetNumber(stamp, customer, &stampNumber, &customerNumber) == -1)
            112            break;
            113        for(i = 0; i < customerNumber; i++)
            114        {
            115            reMax = -1;        //對數(shù)據(jù)初始化。
            116            memset(result, 04);
            117            reNumber = -1;
            118            count=0;
            119            tie = 0;
            120            Divide(customer[i], number,stamp, stampNumber/*+1*/,&count, -1,0);
            121            if(reNumber != -1)        //打印。
            122            {
            123                if(tie == 0)        //找到滿足條件的結(jié)果。
            124                {
            125                    printf("%d (%d):", customer[i], reNumber);
            126                    for(j = 0; j <  reCount; j++)
            127                            printf(" %d",stamp[result[j]]);
            128                    printf("\n");
            129                }

            130                else if( tie == 1)    //存在郵票面值的最大值、郵票種類數(shù),郵票個數(shù)相同的答案
            131                {
            132                    printf("%d (%d): tie\n",customer[i], reNumber);
            133                }

            134            }

            135            else        //不滿足條件
            136            {
            137                printf("%d ---- none\n",customer[i]);
            138            }

            139        }

            140    }
            while(1);
            141    return 0;
            142}

            posted on 2008-07-01 09:56 Leon916 閱讀(1943) 評論(4)  編輯 收藏 引用
            評論:

            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


             
            Copyright © Leon916 Powered by: 博客園 模板提供:滬江博客
            一级做a爰片久久毛片毛片| 一本色道久久88精品综合| 久久综合亚洲欧美成人| 国产精品久久久久a影院| 性做久久久久久久久老女人| 精品久久人人做人人爽综合 | 亚洲欧美一级久久精品| 久久久久黑人强伦姧人妻| 狠狠精品干练久久久无码中文字幕| 色综合色天天久久婷婷基地| 国产91久久综合| 天堂无码久久综合东京热| 一本综合久久国产二区| 久久99久久99精品免视看动漫| 久久只有这里有精品4| 狠狠色噜噜色狠狠狠综合久久| 无码国产69精品久久久久网站| 久久精品国产99久久久| 色噜噜狠狠先锋影音久久| 午夜精品久久久久9999高清| 7777精品伊人久久久大香线蕉| 亚洲精品无码久久千人斩| 69久久夜色精品国产69| 久久se这里只有精品| 中文字幕无码久久精品青草| 无码人妻精品一区二区三区久久 | 蜜桃麻豆www久久国产精品| 国产精品美女久久久久网| 久久国产高清一区二区三区| 久久久久高潮综合影院| 99久久国产综合精品麻豆| 久久久久国产一级毛片高清板| 免费无码国产欧美久久18| 精品人妻久久久久久888| 99久久国产综合精品成人影院| 久久毛片一区二区| 日本免费一区二区久久人人澡| 三级片免费观看久久| 欧美日韩中文字幕久久伊人| 色天使久久综合网天天| 国内精品久久久久久中文字幕|