您的位置:首页 > 其它

【NOIP2016提高A组模拟10.15】打膈膜

2016-10-24 19:23 417 查看

【NOIP2016提高A组模拟10.15】打膈膜

(File IO): input:game.in output:game.out

Time Limits: 1000 ms Memory Limits: 524288 KB

Description



Input



Output



Sample Input

Input1:

2 1
2 1


Input2:

3 4
2 4 4


Sample Output

Output1:

1


Output2:

6


Data Constraint



Solution

贪心?是的就是贪心。

如果当前怪的生命值为1或场上不止两个怪,必然放群攻,否则放重击。如果魔法值用完了就一个个普通攻击。

时间复杂度 O(n log n)

为何就不细讲了

codes:

#include<cstdio>
#include<cstring>
using namespace std;
long long n,ans,all=0,h[100001];
int m,k[1000001];
int main()
{
freopen("game.in","r",stdin);
freopen("game.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
int x;
scanf("%d",&x);
++h[x];
}
int temp=0,t=1;
for(int i=1;i<=m;i++)
{
while(t<=100000 &&(!h[t] || t<=temp))t++;
if(t>100000)break;
if(n>2 || h[temp+1])
{
temp+=1;
n-=h[temp];
}else
{
h[t]--;
h[t-2]++;
if(t-2<=temp)n--;else t-=2;
}
ans+=n;
}
for(int i=temp+1;i<=100000;i++)
{
if(h[i])
{
while(h[i]--)
{
k[++k[0]]=i-temp;
}
}
}
for(int i=1;i<=k[0];i++)ans+=n*k[i]-1,n--;
printf("%lld",ans);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: