<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,代碼人生 閱讀(852) 評論(0)  編輯  收藏

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


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

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

    常用鏈接

    留言簿

    隨筆分類(8)

    隨筆檔案(35)

    文章分類

    文章檔案(1)

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 最近中文字幕免费大全| 亚洲欧美自偷自拍另类视| 精品97国产免费人成视频| 国产一区在线观看免费| 亚洲成AV人片高潮喷水| 香蕉高清免费永久在线视频| 亚洲熟女www一区二区三区| 在线观看免费成人| 99亚洲乱人伦aⅴ精品| 亚洲人午夜射精精品日韩| 久久久精品视频免费观看 | 亚洲欧洲中文日韩av乱码| 一个人晚上在线观看的免费视频| 亚洲国产一区明星换脸| 国产免费区在线观看十分钟| 亚洲三级电影网址| 日本三级2019在线观看免费| 亚洲欧美日韩中文字幕一区二区三区| 国产福利免费在线观看| 大片免费观看92在线视频线视频 | 中国一级毛片免费看视频| 亚洲av无码一区二区三区乱子伦 | 亚洲一区二区三区免费视频| 天天拍拍天天爽免费视频| 日韩在线观看免费| 亚洲gv白嫩小受在线观看| 免费人成网站在线观看10分钟| 亚洲精品女同中文字幕| 久久影视综合亚洲| www.免费在线观看| 国产精品亚洲综合| 久久亚洲精品成人777大小说| 在线看片无码永久免费视频| 免费人成视频在线播放| 亚洲久本草在线中文字幕| 天天看片天天爽_免费播放| 光棍天堂免费手机观看在线观看| 亚洲91精品麻豆国产系列在线| 免费在线观看a级毛片| 久久综合给合久久国产免费| 亚洲成av人片在www鸭子|