zoukankan      html  css  js  c++  java
  • Skip the Class

    BestCoder Round #92

    Skip the Class

     
     Accepts: 678
     
     Submissions: 1285
     Time Limit: 2000/1000 MS (Java/Others)
     
     Memory Limit: 65536/65536 K (Java/Others)
    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
    #include <iostream>
    #include <cstdio>
    #include <vector>
    #include <queue>
    #include <cstring>
    #include <algorithm>
    #include <cstdlib>
    #define FOR(i,x,n) for(int i=x;i<n;i++)
    #define ll long long int
    #define INF 0x3f3f3f3f
    #define MOD 1000000007
    #define MAX_N 50005
    
    using namespace std;
    
    struct node{
        char course[20];
        int v;
    };
    
    node no[150];
    
    int compar(char a[],char b[]){
        int aa=strcmp(a,b);
        if(aa>0){
            return 1;
        }
        return 0;
    }
    
    int compar2(char a[],char b[]){
        int aa=strcmp(a,b);
        if(aa==0){
            return 1;
        }
        return 0;
    }
    
    int cmp(node a,node b){
        return compar(a.course,b.course)||compar2(a.course,b.course)&&a.v>b.v;
    }
    
    int main()
    {
        //freopen("data.txt", "r", stdin);
        //freopen("data.out", "w", stdout);
        int T;
        int n;
        scanf("%d",&T);
        while(T--){
            scanf("%d",&n);
            FOR(i,0,n){
                scanf("%s ",&no[i].course);
                scanf("%d",&no[i].v);
            }
            sort(no,no+n,cmp);
            int cou;
            int sum=0;
            sum+=no[0].v;
            cou=1;
            FOR(i,1,n){
                if(compar2(no[i].course,no[i-1].course)){
                    if(cou==1){
                        sum+=no[i].v;
                        cou++;
                    }else{
                        continue;
                    }
                }else{
                    sum+=no[i].v;
                    cou=1;
                }
            }
            printf("%d
    ",sum);
    
        }
        //fclose(stdin);
        //fclose(stdout);
        return 0;
    }
  • 相关阅读:
    springboot运行时该注意的地方
    建立第一个SpringBoot小列子(碰到的错误)
    mysql建表基本语法
    两层c:forEach循环嵌套
    git-------基础知识(本地推送项目版本---github上)
    《生活的邀请函》___ 奥雷阿
    输入路径(包括盘符),打印层级目录(隐藏文件也会打印出来)
    输入两个文件夹路径,把其中一个文件夹中(包含内容)拷贝到另一个文件夹中
    用java实现歌曲串烧高速版(SequenceInputStream的使用)
    Java中InputStream装饰器模式的大家族
  • 原文地址:https://www.cnblogs.com/TWS-YIFEI/p/6443119.html
Copyright © 2011-2022 走看看