<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 36,  comments - 3,  trackbacks - 0
    Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
    Total Submission(s) : 18   Accepted Submission(s) : 13
    Problem Description
    Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every teacher gives him a deadline of handing in the homework. If Ignatius hands in the homework after the deadline, the teacher will reduce his score of the final test. And now we assume that doing everyone homework always takes one day. So Ignatius wants you to help him to arrange the order of doing homework to minimize the reduced score.
     

    Input
    The input contains several test cases. The first line of the input is a single integer T that is the number of test cases. T test cases follow.
    Each test case start with a positive integer N(1<=N<=1000) which indicate the number of homework.. Then 2 lines follow. The first line contains N integers that indicate the deadlines of the subjects, and the next line contains N integers that indicate the reduced scores.
     

    Output
    For each test case, you should output the smallest total reduced score, one line per test case.
     

    Sample Input
    3
    3
    3 3 3
    10 5 1
    3
    1 3 1
    6 2 3
    7
    1 4 6 4 2 4 3
    3 2 1 7 6 5 4
     

    Sample Output
    0
    3
    5
     
    該題首先是要排序,將所有項按天數從小到大排序,如果天數一樣的,按照分數從高到低排,排序好后就是貪心了,假如選中的就標記好,每次假如有相同天數的,要分數最小的。具體分析代碼如下:


     1 #include<iostream>
     2 #include<algorithm>
     3 using namespace std;
     4 struct homework
     5 {
     6     int day;
     7     int score;
     8 };
     9 bool cmp(homework a,homework b)
    10 {
    11     if(a.day==b.day)
    12         return a.score>b.score;//假如天數一樣,就比較分數大小,大的放前面
    13     else
    14         return a.day<b.day;
    15 }
    16 int main()
    17 {
    18     int T,i,j,min;
    19     int sign[1001];
    20     homework a[1001];
    21     int n,sum,temp,d;
    22     scanf("%d",&T);
    23     while(T--)
    24     {
    25         scanf("%d",&n);
    26         for(i=0;i<n;i++)
    27             scanf("%d",&a[i].day);
    28         for(i=0;i<n;i++)
    29             scanf("%d",&a[i].score);
    30         sum=0;
    31         sort(a,a+n,cmp);//排序
    32         memset(sign,0,sizeof(sign));
    33         d=1,temp=0;
    34         for(i=0;i<n;i++)
    35         {
    36             if(a[i].day>=d)//假如該天沒作業,把a[i]定在該天完成
    37             {
    38                 sign[i]=1;
    39                 d++;
    40             }
    41             else //假如有已經有作業了,則找出分數最小的與之交換
    42             {
    43                 min=a[i].score;
    44                 temp=i;//temp為最小的分數的位置
    45                 for(j=i-1;j>=0;j--)
    46                     if(sign[j]==1&&a[j].score<min)
    47                     {
    48                         min=a[j].score;
    49                         temp=j;
    50                 
    51                     }
    52                 sum+=a[temp].score;//sum相加
    53                 a[temp].score=a[i].score;//交換
    54         
    55             }
    56         }
    57         printf("%d\n",sum);
    58     }
    59 }
    60 
    61     
    posted on 2013-01-12 23:04 天YU地___PS,代碼人生 閱讀(860) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    <2013年1月>
    303112345
    6789101112
    13141516171819
    20212223242526
    272829303112
    3456789

     一定要好好學習,天天向上!

    常用鏈接

    留言簿

    隨筆分類(8)

    隨筆檔案(35)

    文章分類

    文章檔案(1)

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 四虎永久免费影院在线| 亚洲视频免费一区| 国产成人免费ā片在线观看| 亚洲国产午夜精品理论片| 99re在线视频免费观看| 亚洲成色999久久网站| a级毛片免费全部播放无码| 亚洲人成网站18禁止一区| 一级黄色毛片免费看| 亚洲精品麻豆av| 一个人看的www视频免费在线观看 一个人看的免费观看日本视频www | 免费国产在线精品一区 | 在线观看亚洲成人| 中文字幕手机在线免费看电影| 亚洲日韩激情无码一区| 久久免费国产视频| 亚洲不卡中文字幕| 国产三级免费观看| 9久热精品免费观看视频| 亚洲产国偷V产偷V自拍色戒| 99re在线精品视频免费| 在线a亚洲老鸭窝天堂av高清| 日本a级片免费看| 本道天堂成在人线av无码免费| 亚洲免费观看视频| 天天影院成人免费观看| 亚洲国产精品成人AV在线| 亚洲国产精品激情在线观看| 在线成人精品国产区免费| 亚洲国产成人精品久久| 免费看一级做a爰片久久| 91精品成人免费国产| 亚洲午夜精品在线| 深夜国产福利99亚洲视频| 精品国产麻豆免费人成网站| 亚洲国产精品白丝在线观看| 国产一级理论免费版| 无码日韩精品一区二区三区免费| 亚洲最大的成人网| 亚洲精品无码MV在线观看 | 日韩一区二区三区免费播放|