关闭

2016长城信息杯中国大学生程序设计竞赛中南邀请赛 xtu 1246 Heartstone

1267人阅读 评论(0) 收藏 举报
分类:

http://www.dengwenhuo.cn/?id=201

Bobo is playing Heartstone. There arenminions in the battlefield. Thei-th minion hashihit points (HP).

Bobo uses two kinds of magic. The one is Arcane Shot and the other is Frostbolt. Arcane Shot can deal twopoints damage to a minion (that is to decrease the minion's HP by two), while Frostbolt can deal three points damage. A minion is killed when its HP is less or equal to zero.

Letf(a)be the minimum number of Frostbolt(s) required to kill all minions, if no more thanaArcane Shot(s) are used. Bobo would like to find outf(0)+f(1)++f(m)modulo(109+7).

Input

The input contains at most30sets. For each set:

The first line contains2integersn,m(1n105,0m105).

The second line containsnintegersh1,h2,,hn(1hi104).

Output

For each set, an integer denotesf(0)+f(1)++f(m)modulo(109+7).

Sample Input

3 2
1 2 3
3 2
2 2 2

Sample Output

6
6

参考了一下别人  自己写了一个 有挫的 没有写完 测试了几波输出都一样

用个优先队列维护~~~时间充足

#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
#define mod 1000000007
 
struct p
{
    int x;
    bool friend operator <(p a,p b)
    {
        return a.x%3<b.x%3 || a.x%3==b.x%3&&a.x<b.x;
    }
};
 
int main()
{
    int n,m;
    ll ans,sum;
    p t;
    while(~scanf("%d %d",&n,&m))
    {
        priority_queue<p>q;
        sum=0;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&t.x);
            q.push(t);
            sum+=t.x/3+(t.x%3==0?0:1);
        }
        ans=sum;printf("%lld\n",sum);
        while(m--)
        {
            if(!q.empty())
            {
                t=q.top();
                q.pop();
                sum-=t.x/3+(t.x%3==0?0:1);
                t.x-=2;
                if(t.x>0)
                {
                    sum+=t.x/3+(t.x%3==0?0:1);
                    q.push(t);
                }
                ans=(ans+sum)%mod;
            }
        }
        printf("%lld\n",ans);
    }
    return 0;
}



0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:57502次
    • 积分:2161
    • 等级:
    • 排名:第19707名
    • 原创:160篇
    • 转载:30篇
    • 译文:0篇
    • 评论:1条
    文章分类
    最新评论