HDU-6015 Skip the Class
来源:互联网 发布:淘宝开店怎样装修店铺 编辑:程序博客网 时间:2024/05/24 04:09
Skip the Class
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<stdio.h>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;
struct ha
{
string s;
int a;
}he[108];
int cmp(ha x,ha y)
{
if(x.s==y.s)
return x.a>y.a;
else
return x.s>y.s;
}
int main()
{
int T;
cin>>T;
while(T--)
{
map<string,int>c;
int n;
cin>>n;
int i,sum=0;
for(i=0;i<n;i++)
{
cin>>he[i].s>>he[i].a;
}
sort(he,he+n,cmp);
for(i=0;i<n;i++)
{
c[he[i].s]++;
if(c[he[i].s]<=2)
{
sum+=he[i].a;
}
//printf("%d\n",sum);
//printf("%d\n",flag[i]);
}
cout<<sum<<endl;
}
return 0;
}
题意:
终于又开学啦。luras最喜欢的就是开学了,因为这样她又可以愉快地翘课了(啊?)
luras接下来有n节课程需要上(换句话说,可以翘。)
每节课程有相应的课程类型与课程翘课价值。
有一点需要注意的是,luras不可以翘同一类课程超过两次,就是如果这类课已经翘了两次,接下来就一定要上。
问你在这个条件下,luras可以获得的最大翘课价值。
解题思路:最开始我想到了背包,但是当把题读完了发现,其中的课名称(字符串)和价值(整型)相对应,很明显map容器
map<string,int>cnt
我们把课程名和相对应的价值保存在这个map容器所构造出来的cnt数组里,这样我们就可以完美的对他们进行筛选了。
- HDU-6015 Skip the class
- HDU 6015 Skip the Class
- HDU 6015 Skip the Class
- HDU 6015 Skip the Class
- HDU 6015 Skip the Class
- hdu 6015 Skip the Class
- HDU:6015 Skip the Class
- hdu 6015 Skip the Class
- HDU-6015 Skip the Class
- Hdu 6015 Skip the Class【水题】
- HDU 6015 Skip the Class 中文翻译
- HDU 6015 Skip the Class (枚举)
- HDU 6015 bestcoder #92 Skip the Class
- HDU:6015 Skip the Class(map)
- HDU 6015 Skip the Class【贪心】【map】
- HDU 6015 Skip the Class (map)
- 【STL】hdu 6015 Skip the Class
- 【STL】hdu 6015 Skip the Class
- python导入opencv解决no module named cv2问题
- JMX之Mbean
- (M)Backtracking:60. Permutation Sequence
- 计算单词个数
- 按照“1 1 2 3 5 8 13 21”这个规律算出第五十个数是多少;
- HDU-6015 Skip the Class
- ubuntu防火墙操作
- AndroidStudio 中开启Java8语法和Retrolambda库的使用
- 单链表的反转
- 如何新建java项目
- C++的标准输出和读写文件
- Effective C++ 3. Use const whenever posible
- 设计模式之二:Builder模式
- HDU-6019 MG loves gold