BestCoder Round #92 1001 Skip the Class【HDU6015】【STL】

32 篇文章 0 订阅
16 篇文章 0 订阅

题目链接: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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值