zoukankan      html  css  js  c++  java
  • Doing Homework again

     Doing Homework again
    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
    Submit Status

    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 <stdio.h>
     3 #include <string.h>
     4 #include <map>
     5 #include <algorithm>
     6 using namespace std;
     7 typedef struct abcd
     8 {
     9     int w,l;
    10 }abcd;
    11 abcd a[1200];
    12 bool cmp(abcd x,abcd y)
    13 {
    14     if(x.w==y.w)return x.l>y.l;
    15     return x.w>y.w;
    16 }
    17 map<int,int> m;
    18 int main()
    19 {
    20     int t,n,i,j,ans;
    21     scanf("%d",&t);
    22     while(t--)
    23     {
    24         scanf("%d",&n);
    25         for(i=0;i<n;i++)
    26         scanf("%d",&a[i].l);
    27         for(i=0;i<n;i++)
    28         scanf("%d",&a[i].w);
    29         sort(a,a+n,cmp);
    30         m.clear();
    31         ans=0;
    32         for(i=0;i<n;i++)
    33         {
    34             if(m[a[i].l]==0)
    35             {
    36                 m[a[i].l]=1;
    37             }
    38             else
    39             {
    40                 while(a[i].l>0&&m[a[i].l])a[i].l--;
    41                 if(a[i].l>0)m[a[i].l]=1;
    42                 else ans+=a[i].w;
    43             }
    44         }
    45         cout<<ans<<endl;
    46     }
    47 }
    View Code
     
     
     
  • 相关阅读:
    jquery两个滚动条样式
    js双层动画幻灯
    漂浮QQ
    js物理弹性窗口
    js抽奖跑马灯程序
    经典算法
    判断手机浏览器终端设备
    javascript判断手机旋转横屏竖屏
    【转】处理百万级以上的数据提高查询速度的方法
    Linux -- Centos 下配置LNAMP 服务器环境
  • 原文地址:https://www.cnblogs.com/ERKE/p/3842038.html
Copyright © 2011-2022 走看看