BestCoder Round #92 1001 Skip the Class【HDU6015】【STL】
来源:互联网 发布:闪讯mac怎么连接 编辑:程序博客网 时间:2024/04/29 15:18
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6015
【思路分析】首先每个名字最多只能用两次课程翘课价值。然后我们可以用STL存储这个名字的翘课次数,然后再用两个map记录最大的两次翘课值。然后进行不断更新就好了,很简单。
【AC代码】
#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<map>#include<queue>#include<stack>using namespace std;int main(){ int t,n; scanf("%d",&t); while(t--) { scanf("%d",&n); char str[15]; int sum=0,v; map<string ,int >ma;//记录名字翘课次数 map<string ,int >ma1;//最大的翘课价值或次大的翘课价值 map<string ,int >ma2;//最大的翘课价值或次大的翘课价值 for(int i=1; i<=n; i++) { scanf("%s %d",str,&v); if(ma[str]==0) { ma[str]++; ma1[str]=v; sum+=v; } else if(ma[str]==1) { ma[str]++; ma2[str]=v; sum+=v; } else if(ma[str]==2) { if(v>min(ma1[str],ma2[str])) { if(ma1[str]==ma2[str]) { sum-=ma1[str]; sum+=v; ma1[str]=v; } else if(ma1[str]>ma2[str]) { sum-=ma2[str]; sum+=v; ma2[str]=v; } else { sum-=ma1[str]; sum+=v; ma1[str]=v; } } } } printf("%d\n",sum); } return 0;}
0 0
- BestCoder Round #92 1001 Skip the Class【HDU6015】【STL】
- HDU6015 Skip the Class
- HDU6015 Skip the Class
- BestCoder Round #92 1001 hdu6015
- BestCoder Round #92 Skip the Class(STL中map的应用)
- BestCoder Round #92A Skip the Class(map)
- HDU 6015 Skip the Class【BestCoder Round #92】map
- 6015 Skip the Class(BestCoder Round #92)
- HDU6015 Skip the Class (Map)
- BestCoder Round #92 1001 Skip the Class —— trie树 or map容器
- HDU 6015 bestcoder #92 Skip the Class
- BESTCODER ROUND92 1001.Skip the Class
- Best Coder #92 1001 Skip The Class
- 【STL】hdu 6015 Skip the Class
- 【STL】hdu 6015 Skip the Class
- 【结构体排序】HDU6015Skip the Class【BestCoder Round #92】
- 【杭电6015】Skip the Class-map-STL
- Skip the Class
- leetcode题解-508. Most Frequent Subtree Sum
- javax mail发送邮件
- Java就业指导
- 数据结构学习 栈与队列(二)
- 用dom4j来修改xml文档
- BestCoder Round #92 1001 Skip the Class【HDU6015】【STL】
- Android LitePal让数据库使用so easy(译)
- Android中的单位和尺寸
- python之匿名函数lambda
- 统计学习方法第四章
- webpack入门与解析(一)
- 412. Fizz Buzz(C++)
- 【数据库】编程规范与安全
- jieba 结巴分词 常用说明