zoukankan      html  css  js  c++  java
  • XTU 1246 Heartstone

    $2016$长城信息杯中国大学生程序设计竞赛中南邀请赛$D$题

    贪心。

    我是这样贪的:开三个优先队列$q[0]$,$q[1]$,$q[2]$,$q[i]$存储对$3$取余之后为$i$的数。

    首先看看还有没有$x\% 3 = 2$的$x$存在,如果有,那么这一次的$Arcane$ $Shot$就用在这个$x$上,更新答案与队列的情况。

    如果$x\%3=2$的$x$不存在,那么看看$x\%3=1$的$x$是否存在,如果有,那么这一次的$Arcane$ $Shot$就用在这个$x$上,更新答案与队列的情况。

    如果$x\%3=1$的$x$不存在,那么看看$x\%3=0$的$x$是否存在,如果有,那么这一次的$Arcane$ $Shot$就用在这个$x$上,更新答案与队列的情况。

    具体看代码:

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<vector>
    #include<map>
    #include<set>
    #include<queue>
    #include<stack>
    #include<iostream>
    using namespace std;
    typedef long long LL;
    const double pi=acos(-1.0),eps=1e-8;
    
    const int maxn=100010;
    int n,m,f[maxn],mod=1e9+7;
    
    int main()
    {
    
        while(~scanf("%d%d",&n,&m))
        {
            priority_queue<int>q[3]; memset(f,0,sizeof f);
    
            for(int i=1;i<=n;i++)
            {
                int x; scanf("%d",&x);
                q[x%3].push(x); f[0]=(f[0]+x/3)%mod;
                if(x%3!=0) f[0]=(f[0]+1)%mod;
            }
    
            bool flag=0;
            for(int i=1;i<=m;i++)
            {
                if(!q[2].empty())
                {
                    int h=q[2].top(); q[2].pop();
                    f[i]=f[i-1]-1; if(h-2>0) q[0].push(h-2);
                }
    
                else if(!q[1].empty())
                {
                    int h=q[1].top(); q[1].pop();
                    f[i]=f[i-1]-1; if(h-2>0) q[2].push(h-2);
                }
    
                else if(!q[0].empty())
                {
                    if(flag==0) f[i]=f[i-1], flag=1;
                    else
                    {
                        int h=q[0].top(); q[0].pop();
                        f[i]=f[i-1]-1; if(h-4>0)  q[2].push(h-4);
                        flag=0;
                    }
                }
    
                else f[i]=f[i-1];
            }
    
            int ans=0;
            for(int i=0;i<=m;i++) ans=(ans+f[i])%mod;
            cout<<ans<<endl;
        }
        return 0;
    }
  • 相关阅读:
    tensorflow RNN和简单例子
    推荐系统理论及实战(转)附个人的理解和实战
    mysql 中 case when then .... else end 的简单使用
    动态规划最常见的习题 (最长公共子串、最长公共子序列、最短编辑距离)
    神经网络中 梯度消失、梯度爆炸的问题分析
    深度学习基础(转)
    用户兴趣的模型 浅析
    20190317 A
    pkuwc2019游记
    练习题16
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5818983.html
Copyright © 2011-2022 走看看