HDU 6015 Skip the Class【BestCoder Round #92】map
来源:互联网 发布:sql server清空数据库 编辑:程序博客网 时间:2024/05/16 04:56
Skip the Class
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 374 Accepted Submission(s): 222
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.
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
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.
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
25english 1english 2english 3math 10cook 1002a 1a 2
Sample Output
1153
Source
BestCoder Round #92
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=6015
中文版题目:http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=748&pid=1001
开学第一场BC。
翘课的话肯定是翘价值最大的那两节。
注意:上课的顺序就是输入的顺序,所以用map保存每门课的最大价值和第二大价值,然后求和就可以了。
AC代码:
#include <cstdio>#include <iostream>#include <map>#include <string>using namespace std;int main(){ int T,n; cin>>T; while(T--) { cin>>n; map<string,int>first,second; first.clear(); second.clear(); string name; int length; for(int i=0;i<n;i++) { cin>>name>>length; if(first[name]<length) { second[name]=first[name]; first[name]=length; } else if(second[name]<length) { second[name]=length; } } int ans=0; map<string,int>::iterator it; for(it=first.begin();it!=first.end();it++) { ans+=it->second; } for(it=second.begin();it!=second.end();it++) { ans+=it->second; } cout<<ans<<endl; } return 0;}
此题题解及代码。
#include<stdio.h>#include<iostream>#include<string.h>#include<string>#include<ctype.h>#include<math.h>#include<set>#include<map>#include<vector>#include<queue>#include<bitset>#include<algorithm>#include<time.h>using namespace std;void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }#define MS(x, y) memset(x, y, sizeof(x))#define ls o<<1#define rs o<<1|1typedef long long LL;typedef unsigned long long UL;typedef unsigned int UI;template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b > a)a = b; }template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b < a)a = b; }const int N = 0, M = 0, Z = 1e9 + 7, inf = 0x3f3f3f3f;template <class T1, class T2>inline void gadd(T1 &a, T2 b) { a = (a + b) % Z; }int casenum, casei;int n;void datamaker_pre(){srand(time(0));freopen("Skip the Class_pre.in", "w", stdout);casenum = 1000; printf("%d\n", casenum);for (casei = 1; casei <= casenum; ++casei){int n = rand() % 10 + 1; printf("%d\n", n);for (int i = 1; i <= n; ++i){int l = rand() % 3 + 1;for (int j = 0; j < l; ++j)printf("%c", rand() % 5 + 'a');int v = rand() % 1000 + 1;printf(" %d\n", v);}}}void datamaker(){srand(time(0));freopen("Skip the Class.in", "w", stdout);casenum = 1000; printf("%d\n", casenum);for (casei = 1; casei <= casenum; ++casei){int n = rand() % 100 + 1; printf("%d\n", n);for (int i = 1; i <= n; ++i){int l = rand() % 3 + 1;for (int j = 0; j < l; ++j)printf("%c", rand() % 5 + 'a');int v = rand() % 1000 + 1;printf(" %d\n", v);}}}int main(){//datamaker_pre(); return 0;//freopen("Skip the Class_pre.in", "r", stdin); freopen("Skip the Class_pre.out", "w", stdout);//datamaker(); return 0;//freopen("Skip the Class.in", "r", stdin); freopen("Skip the Class.out", "w", stdout);scanf("%d", &casenum);for (casei = 1; casei <= casenum; ++casei){map<string, int> first, second;first.clear();second.clear();scanf("%d", &n);for (int i = 1; i <= n; ++i){char s[12]; int v;scanf("%s%d", s, &v);gmax(second[s], v);if (second[s] > first[s])swap(second[s], first[s]);}int sum = 0;for (auto it : first)sum += it.second;for (auto it : second)sum += it.second;printf("%d\n", sum);}return 0;}/*【分析】这道题其实就是对每种字符串保留最大的两个价值就好。这里用map实现比较方便。*/
0 1
- HDU 6015 Skip the Class【BestCoder Round #92】map
- BestCoder Round #92A Skip the Class(map)
- HDU 6015 bestcoder #92 Skip the Class
- 6015 Skip the Class(BestCoder Round #92)
- BestCoder Round #92 Skip the Class(STL中map的应用)
- BestCoder Round #92 1001 Skip the Class —— trie树 or map容器
- BestCoder Round #92 1001 Skip the Class【HDU6015】【STL】
- HDU:6015 Skip the Class(map)
- HDU 6015 Skip the Class【贪心】【map】
- HDU 6015 Skip the Class (map)
- 【HDU-oj】-6015-Skip the Class(map string vector)
- HDU 6015 Skip the Class 优先队列 map的使用
- 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
- 将磁盘文本数据导入数据表
- 深拷贝 浅拷贝 内存零拷贝
- 紫书章三习题5——UVA 227 Puzzle
- CUDA 编程 之 配置cache函数
- Intel TBB简介及在Windows7 VS2013上源码的编译过程
- HDU 6015 Skip the Class【BestCoder Round #92】map
- 201403第一届CCF第二题 窗口
- Combination Sum
- A2DP & AVRCP,蓝牙音频协议的兄弟组合(1)
- 算法相关——Java排序算法之选择排序(六)
- Ubuntu搭建开发openchannelssd的qemu的虚拟机
- Arrays.copyOf() 用法:
- leetcode 345. Reverse Vowels of a String [EASY]
- 常见的RuntimeException异常总结