Skip the Class

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 253    Accepted Submission(s): 146

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
  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
  3.  

中文版:

Skip the Class

 Accepts: 678
 Submissions: 1285
 Time Limit: 2000/1000 MS (Java/Others)
 Memory Limit: 65536/65536 K (Java/Others)
问题描述
  1. 终于又开学啦。呃喵最喜欢的就是开学了,因为这样她又可以愉快地翘课了(啊?)
  2. 呃喵接下来有n节课程需要上(换句话说,可以翘。)
  3. 每节课程有相应的课程类型与课程翘课价值。
  4. 有一点需要注意的是,呃喵不可以翘同一类课程超过两次,就是如果这类课已经翘了两次,接下来就一定要上。
  5. 问你在这个条件下,呃喵可以获得的最大翘课价值。
输入描述
  1. 第一行为一个整数T,代表数据组数。
  2. 接下来,对于每组数据——
  3. 第一行一个整数n,表示接下来需要依次上的课程数量,
  4. 接下来有n行,每行包括一个仅由'a'~'z'构成的长度不超过10的字符串s与一个正整数v
  5. 其中字符串表示课程的类型,相同的字符串代表相同的课程。
  6.  
  7. 数据保证——
  8. 1 <= T <= 1000
  9. 对于每组数据,1 <= n <= 1001 <= |s| <= 10, 1 <= v <= 1000
输出描述
  1. 对于每组数据,输出一行。
  2. 该行有1个整数,表示呃喵可以获得的最大翘课价值。
输入样例
  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
输出样例
  1. 115
  2. 3

代码:

  1. //注意本题说的是逃课价值
  2. #include<queue>
  3. #include<stack>
  4. #include<math.h>
  5. #include<stdio.h>
  6. #include<numeric>//STL数值算法头文件
  7. #include<stdlib.h>
  8. #include<string.h>
  9. #include<iostream>
  10. #include<algorithm>
  11. #include<functional>//模板类头文件
  12. using namespace std;
  13.  
  14. const int INF=1e9+7;
  15. const int maxn=1000+10;
  16.  
  17. int t,n;
  18. struct node
  19. {
  20. int v;
  21. string s;
  22. } a[maxn];
  23.  
  24. int cmp(node A,node B)//将课程名按照字典序排序,对于字典序相同的课程,按其价值从大到小排序
  25. {
  26. if(A.s==B.s)
  27. return A.v>B.v;
  28. return A.s>B.s;
  29. }
  30. int main()
  31. {
  32. scanf("%d",&t);
  33. while(t--)
  34. {
  35. int i,j,flag=0,ans=0;
  36. scanf("%d",&n);
  37. for(i=0; i<n; i++)
  38. cin>>a[i].s>>a[i].v;
  39. sort(a,a+n,cmp);
  40. ans+=a[0].v;//每次取相同名字课程的前两项即可
  41. for(i=1; i<n; i++)
  42. {
  43. if(a[i].s!=a[i-1].s)
  44. {
  45. flag=0;
  46. ans+=a[i].v;
  47. }
  48. else if(!flag)
  49. {
  50. flag=1;
  51. ans+=a[i].v;
  52. }
  53. }
  54. printf("%d\n",ans);
  55. }
  56. return 0;
  57. }

(bc 1001) hdu 6015 skip the class的更多相关文章

  1. Emscripten实现把C/C++文件转成wasm,wast(wasm的可读形式),llvm字节码(bc格式),ll格式(llvm字节码的可读形式)并执行wasm

    <一>˙转换 Emscripten实现把C/C++文件转成wasm,wast(wasm的可读形式),llvm字节码(bc格式),ll格式(llvm字节码的可读形式)的步骤: 最新版本的Em ...

  2. 2016"百度之星" - 初赛(Astar Round2A)HDU 5695 拓扑排序+优先队列

    Gym Class Time Limit: 6000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total S ...

  3. hdu 1573 x问题(中国剩余定理)HDU 2007-1 Programming Contest

    只是套模板而已(模板其实也不懂). 留着以后好好学的时候再改吧. 题意—— X = a[i] MOD b[i]; 已知a[i],b[i],求在[1, n]中存在多少x满足条件. 输入—— 第一行一个整 ...

  4. 舒适的路线(codevs 1001)

    题目描述 Description Z小镇是一个景色宜人的地方,吸引来自各地的观光客来此旅游观光.Z小镇附近共有N(1<N≤500)个景点(编号为1,2,3,…,N),这些景点被M(0<M≤ ...

  5. 线段树(区间合并)HDU - 1540

    题意:输入n,m,给定n个相互连通的村庄,有m个操作,D x,表示破坏x村庄使其与相邻的两个村庄不相通,R 表示修复上一个被破坏的村庄,与相邻的两个村庄联通.Q x表示与x相连的村庄有多少个. 思路: ...

  6. (重刷)HDU 1874 畅通工程续 + HDU 2544 最短路 最短路水题,dijkstra解法。

    floyd解法 今天初看dijkstra,先拿这两题练手,其他变形题还是不是很懂. 模版题,纯练打字... HDU 1874: #include <cstdio> #define MAXN ...

  7. HDU 6015 Skip the Class 优先队列 map的使用

    Skip the Class Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tota ...

  8. HDU 6015 Skip the Class

    Skip the Class 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define l ...

  9. (水题)HDU - 1077 - Catching Fish - 计算几何

    http://acm.hdu.edu.cn/showproblem.php?pid=1077 很明显这样的圆,必定有两个点在边界上.n平方枚举圆,再n立方暴力判断.由于没有给T,所以不知道行不行.

随机推荐

  1. 【BZOJ】1176: [Balkan2007]Mokia

    [题意]n*n的矩阵,初始值为0(题面有误),m次操作,增加一个格子的权值,或查询子矩阵和.n<=2*10^6.(m应该较题面所述偏大). [算法]CDQ分治(算法知识见数据结构) [题解]三维 ...

  2. 飘雪效果的swf

    //第一帧动作 import flash.events.Event; ;k<;k++) { var xuehua:xue= new xue(); xuehua.alpha = Math.rand ...

  3. python3爬虫.1.简单的网页爬虫

    此为记录下我自己的爬虫学习过程. 利用url包抓取网页 import urllib.request #url包 def main(): url = "http://www.douban.co ...

  4. C++学习之路(九):从菱形继承引入的对象模型

    一.单继承 class A {int a;}; class B : public A {int b;}; 普通的单继承关系,类的大小是由其虚表指针和非静态成员函数大小决定.故上述sizeof(A)的大 ...

  5. MySQL常见错误代码说明

    附:MySQL常见错误代码说明 1005:创建表失败 1006:创建数据库失败 1007:数据库已存在,创建数据库失败 1008:数据库不存在,删除数据库失败 1009:不能删除数据库文件导致删除数据 ...

  6. 【题解】BZOJ 3600: 没有人的算术——替罪羊树、线段树

    题目传送门 题意 具体的自己去上面看吧...反正不是权限题. 简单来说,就是定义了一类新的数,每个数是0或者为 \((x_L, x_R)\) ,同时定义比较大小的方式为:非零数大于零,否则按字典序比较 ...

  7. Python中的raw_input()和input()

    raw_input()和input()都是python中的内建函数,用于读取控制台用户的输入,但有所区别: [nr@localhost conf]$ python Python 2.7.5 (defa ...

  8. 2017百度春招<不等式排列>

    题目: 度度熊最近对全排列特别感兴趣,对于1到n的一个排列,度度熊发现可以在中间根据大小关系插入合适的大于和小于符号(即 '>' 和 '<' )使其成为一个合法的不等式数列.但是现在度度熊 ...

  9. leetcode 之trap water(8)

    这题不太好想.可以先扫描找到最高的柱子,然后分别处理两边:记录下当前的局部最高点,如果当前点小于局部最高点,加上, 反则,替换当前点为局部最高点. int trapWater(int A[], int ...

  10. hdu 4726(贪心)

    Kia's Calculation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...