• map


    Skip the Class

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 1886    Accepted Submission(s): 1045


    Problem Description
    Finally term begins. luras loves school so much as she could skip the class happily again.(wtf?)

    Luras will take n lessons in sequence(in another word, to have a chance to skip xDDDD).

    For every lesson, it has its own type and value to skip.

    But the only thing to note here is that luras can't skip the same type lesson more than twice.

    Which means if she have escaped the class type twice, she has to take all other lessons of this type.

    Now please answer the highest value luras can earn if she choose in the best way.
     
    Input
    The first line is an integer T which indicates the case number.

    And as for each case, the first line is an integer n which indicates the number of lessons luras will take in sequence.

    Then there are n lines, for each line, there is a string consists of letters from 'a' to 'z' which is within the length of 10,
    and there is also an integer which is the value of this lesson.

    The string indicates the lesson type and the same string stands for the same lesson type.

    It is guaranteed that——

    T is about 1000

    For 100% cases, 1 <= n <= 100,1 <= |s| <= 10, 1 <= v <= 1000
     
    Output
    As for each case, you need to output a single line.
    there should be 1 integer in the line which represents the highest value luras can earn if she choose in the best way.
     
    Sample Input
    2 5 english 1 english 2 english 3 math 10 cook 100 2 a 1 a 2
     
    Sample Output
    115 3
     
    http://acm.hdu.edu.cn/showproblem.php?pid=6015
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<map>
    #include<set>
    #include<list>
    #include<vector>
    #include<stack>
    #include<queue>
    #define ll long long
    #define inf 0x3f3f3f3f;
    using namespace std;
    
    struct node{
        char cl[103];
        int val;
    }nn[103];
    
    int t,n,sum;
    
    bool cmp(node a,node b){
        return a.val>b.val;
    }
    
    map<string,int>m;
    
    int main(){
        scanf("%d",&t);
        while(t--){
            scanf("%d",&n);
            sum=0;
            m.clear();
            for(int i=0;i<n;i++){
                scanf("%s%d",&nn[i].cl,&nn[i].val);
                m[nn[i].cl]=0;
            }
            sort(nn,nn+n,cmp);
            for(int i=0;i<n;i++){
                if(m[nn[i].cl]<2){
                    sum+=nn[i].val;
                    m[nn[i].cl]++;
                }
            }
            printf("%d
    ",sum);
        }
        return 0;
    }
  • 相关阅读:
    data:image/png;base64
    需要去了解的知识
    【转】react的高阶组件
    几个css问题
    antd中form中resetFields清空输入框
    react中map循环中key取值问题
    react中父组件调用子组件的方法
    hive 初始化 时间问题 The server time zone value 'EDT' is unrecognized
    centos7安装MySQL8 无法修改密码 无法修改密码策略
    虚拟机 Linux 不能连 xshell 不能上网
  • 原文地址:https://www.cnblogs.com/qqshiacm/p/10753305.html
Copyright © 2020-2023  润新知