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

Copy

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\n",sum);

    }
    //fclose(stdin);
    //fclose(stdout);
    return 0;
}
时间: 2024-08-08 00:43:40

Skip the Class的相关文章

LINQ系列:LINQ to SQL Take/Skip

1. Take var expr = context.Products .Take(10); var expr = (from p in context.Products select p) .Take(10); SELECT TOP (10) [c].[ProductID] AS [ProductID], [c].[CategoryID] AS [CategoryID], [c].[ProductName] AS [ProductName], [c].[UnitPrice] AS [UnitP

git的提交突出--git rebase之abort、continue、skip

(1)应用实例描述 假设在github或者gitoschina上建立了一个项目,默认分支为master分支,远程master分支上c.sh文件内容: 开发者A.B分别将项目拷贝到自己本地进行开发 某一天,开发者B提交c.sh,并且提交成功, 之后,开发者A在本地代码并没有和远程master分支的代码同步的情况下,对本地的c.sh进行了修改,修改后c.sh内容如下: 修改后,开发者A准备将代码提交到远程master分支上. (2)引入问题 假设开发者A提交过程如下: $ git add c.sh

Linq中Take、TakeWhile、Skip、SkipWhile的比较(转)

参考文章:http://blog.csdn.net/lxfzgg/article/details/20534281 Take() int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; var first3Numbers = numbers.Take(3); //从第一个元素开始,获取三个 return的是前面的数 Console.WriteLine("First 3 numbers:"); foreach (var n in first3N

Xcode升级误点Skip Bundle解决办法!!!

交代一下背景,我电脑上是从AppStore下载的Xcode7.2,后来从网上下载了Xcode7.3安装包,然后安装7.3,电脑上同时存在7.2版本和7.3版本,但是在安装7.3的时候误点了Skip Bundle,然后工程就有一点小问题,下面是解决办法: 第一步:“Finder”--->"应用程序"--->"鼠标右键点击7.3版本Xcode"----->“显示包内容”. 第二步:“Contents”---->"info.plist&q

Gradle Goodness: Skip Building Project Dependencies

If we use Gradle in a multi-module project we can define project dependencies between modules. Gradle uses the information from the project dependencies to determine which tasks need to be run. For example if module B depends on module A and we want

Oracle给Select结果集加锁,Skip Locked(跳过加锁行获得可以加锁的结果集)

1.通过select for update或select for update wait或select for update nowait给数据集加锁 具体实现参考select for update和select for update wait和select for update nowait的区别 2.Skip Locked(跳过加锁行获得可以加锁的结果集) Skip locked是oracle 11g引入的. 通过skip locked可以使select for update语句可以查询出(

Linq分区操作之Skip,SkipWhile,Take,TakeWhile源码分析

Linq分区操作之Skip,SkipWhile,Take,TakeWhile源码分析 二:linq的分区操作 常用的分区操作:Take,TakeWhile,Skip,SkipWhile 三:Take 1. 注释: 从序列的开头返回指定数量的连续元素 2. 实战: var nums = new int[] { 10, 20, 30, 40, 50, 60 }; var query = nums.Take(2).ToList(); // 10,20 3. 探究源码: 四:TakeWhile 1. 注

uwsgi部署到nginx出现invalid request block size: 4161 (max 4096)...skip问题

使用Flask制作一个网页平台之后,登陆使用openid登陆,然后使用uwsgi服务部署到nginx上,运行起来没有什么问题,但是偶尔在登陆的时候出现502的错误,一般登陆成功之后后面的任何操作都不会出错. 查看uwsgi的log之后,发现出现这样的一个错误: invalid request block size: 4161 (max 4096)...skip 之前一个没有去详细搜索过,也没有具体去看错误产生的原因,因为只是偶尔出现,并且有时候重试的时候是可以登陆的,所以没有太多的去关注,今天因

mongodb sort limit和skip用法

http://www.ttlsa.com/mongodb/mongodb-sort-limit-skip-usage/ 1.sort是排序用的.sort({"字段":1}) 2.skip跳过多少条结果 3.limit每次查询返回的最大结果数量: 项目中的用法比较好: 再次记录: 前台传过,page参数:根据page参数确定是第几页: 1 function(cb) { User.find(query).skip(page * 40).limit(40).exec(function(err