2016长城信息杯中国大学生程序设计竞赛中南邀请赛 xtu 1246 Heartstone
2016-06-20 13:37
330 查看
http://www.dengwenhuo.cn/?id=201
Bobo is playing Heartstone. There aren
![](http://www.dengwenhuo.cn/?id=201)
minions
in the battlefield. Thei
![](http://www.dengwenhuo.cn/?id=201)
-th
minion hash
![](http://www.dengwenhuo.cn/?id=201)
i
![](http://www.dengwenhuo.cn/?id=201)
![](http://www.dengwenhuo.cn/?id=201)
hit
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)
![](http://www.dengwenhuo.cn/?id=201)
be
the minimum number of Frostbolt(s) required to kill all minions, if no more thana
![](http://www.dengwenhuo.cn/?id=201)
Arcane
Shot(s) are used. Bobo would like to find outf(0)+f(1)+⋯+f(m)
![](http://www.dengwenhuo.cn/?id=201)
modulo(10
![](http://www.dengwenhuo.cn/?id=201)
9
![](http://www.dengwenhuo.cn/?id=201)
+7)
![](http://www.dengwenhuo.cn/?id=201)
.
The input contains at most30
![](http://www.dengwenhuo.cn/?id=201)
sets.
For each set:
The first line contains2
![](http://www.dengwenhuo.cn/?id=201)
integersn,m
![](http://www.dengwenhuo.cn/?id=201)
(1≤n≤10
![](http://www.dengwenhuo.cn/?id=201)
5
![](http://www.dengwenhuo.cn/?id=201)
,0≤m≤10
![](http://www.dengwenhuo.cn/?id=201)
5
![](http://www.dengwenhuo.cn/?id=201)
![](http://www.dengwenhuo.cn/?id=201)
).
The second line containsn
![](http://www.dengwenhuo.cn/?id=201)
integersh
![](http://www.dengwenhuo.cn/?id=201)
1
![](http://www.dengwenhuo.cn/?id=201)
,h
![](http://www.dengwenhuo.cn/?id=201)
2
![](http://www.dengwenhuo.cn/?id=201)
,…,h
![](http://www.dengwenhuo.cn/?id=201)
n
![](http://www.dengwenhuo.cn/?id=201)
![](http://www.dengwenhuo.cn/?id=201)
(1≤h
![](http://www.dengwenhuo.cn/?id=201)
i
![](http://www.dengwenhuo.cn/?id=201)
≤10
![](http://www.dengwenhuo.cn/?id=201)
4
![](http://www.dengwenhuo.cn/?id=201)
![](http://www.dengwenhuo.cn/?id=201)
).
For each set, an integer denotesf(0)+f(1)+⋯+f(m)
![](http://www.dengwenhuo.cn/?id=201)
modulo(10
![](http://www.dengwenhuo.cn/?id=201)
9
![](http://www.dengwenhuo.cn/?id=201)
+7)
![](http://www.dengwenhuo.cn/?id=201)
.
参考了一下别人 自己写了一个 有挫的 没有写完 测试了几波输出都一样
用个优先队列维护~~~时间充足
#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;
}
Bobo is playing Heartstone. There aren
minions
in the battlefield. Thei
-th
minion hash
i
hit
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 thana
Arcane
Shot(s) are used. Bobo would like to find outf(0)+f(1)+⋯+f(m)
modulo(10
9
+7)
.
Input
The input contains at most30sets.
For each set:
The first line contains2
integersn,m
(1≤n≤10
5
,0≤m≤10
5
).
The second line containsn
integersh
1
,h
2
,…,h
n
(1≤h
i
≤10
4
).
Output
For each set, an integer denotesf(0)+f(1)+⋯+f(m)modulo(10
9
+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;
}
相关文章推荐
- Servlet过滤器——创建过滤器
- xshell连接虚拟机中的linux
- Java算法 归并排序
- 2016长城信息杯中国大学生程序设计竞赛中南邀请赛 xtu 1252 Defense Tower
- love~LBJ,奥布莱恩神杯3
- love~LBJ,奥布莱恩神杯3
- 由FutureTask的get方法靠什么机制来阻塞引发的思考
- iOS 单例对象创建
- android HttpURLConnection网络请求数据
- android线程管理
- 详解 Android 性能优化
- C语言指针和链表的体会
- memcached 失效的数据去了哪里了
- Java的String、StringBuffer和StringBuilder的区别
- 第15章 css样式设置小技巧
- 加入购物车动画
- Next Permutation
- HTTP 代理原理及实现(二)
- 浅谈iOS中MVVM的架构设计
- 富文本点击事件(链接)