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

  1. 2
  2. 5
  3. english 1
  4. english 2
  5. english 3
  6. math 10
  7. cook 100
  8. 2
  9. a 1
  10. a 2
Sample Output
  1. 115
  2. 3
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <queue>
  5. #include <cstring>
  6. #include <algorithm>
  7. #include <cstdlib>
  8. #define FOR(i,x,n) for(int i=x;i<n;i++)
  9. #define ll long long int
  10. #define INF 0x3f3f3f3f
  11. #define MOD 1000000007
  12. #define MAX_N 50005
  13.  
  14. using namespace std;
  15.  
  16. struct node{
  17. char course[];
  18. int v;
  19. };
  20.  
  21. node no[];
  22.  
  23. int compar(char a[],char b[]){
  24. int aa=strcmp(a,b);
  25. if(aa>){
  26. return ;
  27. }
  28. return ;
  29. }
  30.  
  31. int compar2(char a[],char b[]){
  32. int aa=strcmp(a,b);
  33. if(aa==){
  34. return ;
  35. }
  36. return ;
  37. }
  38.  
  39. int cmp(node a,node b){
  40. return compar(a.course,b.course)||compar2(a.course,b.course)&&a.v>b.v;
  41. }
  42.  
  43. int main()
  44. {
  45. //freopen("data.txt", "r", stdin);
  46. //freopen("data.out", "w", stdout);
  47. int T;
  48. int n;
  49. scanf("%d",&T);
  50. while(T--){
  51. scanf("%d",&n);
  52. FOR(i,,n){
  53. scanf("%s ",&no[i].course);
  54. scanf("%d",&no[i].v);
  55. }
  56. sort(no,no+n,cmp);
  57. int cou;
  58. int sum=;
  59. sum+=no[].v;
  60. cou=;
  61. FOR(i,,n){
  62. if(compar2(no[i].course,no[i-].course)){
  63. if(cou==){
  64. sum+=no[i].v;
  65. cou++;
  66. }else{
  67. continue;
  68. }
  69. }else{
  70. sum+=no[i].v;
  71. cou=;
  72. }
  73. }
  74. printf("%d\n",sum);
  75.  
  76. }
  77. //fclose(stdin);
  78. //fclose(stdout);
  79. return ;
  80. }

Skip the Class的更多相关文章

  1. LINQ系列:LINQ to SQL Take/Skip

    1. Take var expr = context.Products .Take(); var expr = (from p in context.Products select p) .Take( ...

  2. EntityFramework 7 OrderBy Skip Take-计算排序分页 SQL 翻译

    先解释一下这个标题的意思,OrderBy 在 Linq 语句中,我们经常使用,比如 OrderBy(b => b.BlogId) 就是对 BlogId 字段进行升序排序,这是针对一个字段的排序, ...

  3. 【记录】AutoMapper Project To OrderBy Skip Take 正确写法

    AutoMapper:Queryable Extensions 示例代码: using (var context = new orderEntities()) { return context.Ord ...

  4. Xcode插件安装 错选了Skip Bundle解决办法

    1.首先找到Xcode的UUID,在终端运行defaults read /Applications/Xcode.app/Contents/Info DVTPlugInCompatibilityUUID ...

  5. ASP.NET泛型List的各种用法Skip、Take等

    List在.NET里面使用得非常频繁,但有好多人不了解它各种小用法.我就一直记不大住... asp.net中List的简单用法,例如: 1 2 3 4 5 6 7 List<int> li ...

  6. mongodb-$type、limit、skip、sort方法、索引、聚合

    一.$type操作符 $type操作符是基于BSON类型来检索集合中匹配的数据类型,并返回结果. MongoDB 中可以使用的类型如下表所示: 类型 数字 备注 Double 1   String 2 ...

  7. Xcode安装插件,错误选择了Skip Bundles,重新出现Load Bundles方法

    Xcode安装插件经常会遇到这样的问题,出现提示性选择,还是英文提示,所以没仔细看就习惯性的选择了右侧的按钮 点击了Skip Bundle,结果悲剧的发现,发现插件完全失效了,以后不管怎么打开Xcod ...

  8. [Android Pro] InputStream.skip方法的思考

    参考 : http://blog.csdn.net/gsyzhu/article/details/8102286 在java.io.InputStream类中定义了skip这个方法.在API中的描述如 ...

  9. 跳跃表Skip List的原理和实现

    >>二分查找和AVL树查找 二分查找要求元素可以随机访问,所以决定了需要把元素存储在连续内存.这样查找确实很快,但是插入和删除元素的时候,为了保证元素的有序性,就需要大量的移动元素了.如果 ...

  10. 转MongoDB 使用Skip和limit分页

    关于MongoDB 数据分页和排序 limit,skip用户的一些基础语句,介绍MongoDB 数据分页和排序实例方法. 使用Skip和limit可以如下做数据分页: Code: page1 = db ...

随机推荐

  1. 在图像上增加文字 C#

    using (Image i = Image.FromFile(inputPath)) { using (Graphics g = Graphics.FromImage(i)) { g.DrawStr ...

  2. MySQL中exists和in的区别及使用场景

    exists和in的使用方式: 1 #对B查询涉及id,使用索引,故B表效率高,可用大表 -->外小内大 1 select * from A where exists (select * fro ...

  3. CSS魔法堂:display:none与visibility:hidden的恩怨情仇

    前言  还记得面试时被问起"请说说display:none和visibility:hidden的区别"吗?是不是回答完display:none不占用原来的位置,而visibilit ...

  4. [Web 前端] 我不再使用React.setState的3个原因

    copy from : https://blog.csdn.net/smk108/article/details/85237838 从几个月前开始,我在新开发的React组件中不再使用setState ...

  5. C# Barrier 实现

    当您需要一组任务并行地运行一连串的阶段,但是每一个阶段都要等待所有其他任务都完成前一阶段之后才能开始,你一通过Barrier实例来同步这一类协同工作.Barrier初始化后,将等待特定数量的信号到来, ...

  6. HTTPS之acme.sh申请证书

    1.关于let's encrypt和acme.sh的简介 1.1 let's encrypt Let's Encrypt是一个于2015年三季度推出的数字证书认证机构,旨在以自动化流程消除手动创建和安 ...

  7. Libreoffice 各类文件转换的filtername

    LIBREOFFICE_DOC_FAMILIES = [ "TextDocument", "WebDocument", "Spreadsheet&qu ...

  8. 阿里云服务器CentOS7 vsftp安装、设置及后台端口的设置

    查看是否安装vsftp,我这个是已经安装的. [root@localhost vsftpd]# rpm -qa |grep vsftpd vsftpd-3.0.2-11.el7_2.x86_64 如果 ...

  9. 【C语言天天练(三)】typedef具体解释

    引言: typedef能够看作type define的缩写,顾名思义就是类型定义,也就是说它仅仅是给已有的类型又一次定义了一个方便使用的别名.并没有产生新的数据类型. typedef与define的不 ...

  10. python3 + flask + sqlalchemy +orm(3):多对多关系

    一篇文章有多个tag,一个tag也可以属于多篇文章,文章和tag存在多对多关系 config.py DEBUG = True #dialect+driver://root:1q2w3e4r5t@127 ...