这题做起来有些烦躁,可能是题意没有理解清楚吧。
题意:造出来的士兵第一天没有攻击力,但可以采样,且要消耗一天的生命,共 d 天生命。造一个士兵需要 k 天,k + 1 天时可以有攻击力,造到 k 天时相当于成活士兵的第一天。刚开始的士兵为第一天的士兵,没有攻击力,但可以采样。总共模拟 x 天。数据较大,采用 __int64。
ps: 这题应该有数学公式,但难的推导,直接模拟了。
#include <stdio.h> #include <string.h> #define M 102 int n,d,k,a,x; __int64 live[M],grow[M],all; void add_day() { __int64 A = 0; live[0] = grow[k]; for(int i=d; i>0; i--) { all += live[i] * 5; if(i <= a) A += live[i]; live[i] = live[i-1]; } for(i=k; i>1; i--) { grow[i] = grow[i-1]; } grow[1] = A; } int main() { // freopen("in.txt","r",stdin); int t; scanf("%d",&t); while(t--) { scanf("%d%d%d%d%d",&n,&d,&a,&k,&x); memset(live,0,sizeof(live)); memset(grow,0,sizeof(grow)); all = 0; live[1] = n; while(x--) { add_day(); } printf("%I64d ",all); } return 0; }