题解 P1664 【每日打卡心情好】
这题本人提交了十几次才正确,请大家看看我的Pascal题解,神犇勿喷
var n,i,b,m,q,p,j,s:longint;//m为连续遗漏天数,p为总共的积分,s为连续打卡天数;
begin
readln(n);//输入变量n;
for i:=1 to n do
begin
readln(b);//看看这天有没有打卡;
if b=1 then begin if m>0 then begin//这行一直到else q:=0;非常重要!本人之前就一直死在这,m一定要大于0才能进行下面的赋值,
如果不加这条语句,你的s就会不对,详细的请看下面;
q:=1;
for j:=2 to m do
q:=q*2;
end
else q:=0;//不加这条else语句的话,s就会继续加之前q的值;
s:=s-q;//减去q;
m:=0;//遗漏天数m要清零;
if s<0 then s:=0;//这条必须有,没有的话,后面2个点对不了;
inc(s);//连续打卡天数s加1;
inc(p);//积分加1;
if s>=3 then inc(p);//如果s>=3的话,再加1分;
if s>=7 then inc(p);//如果s>=7的话,再加1分;
if s>=30 then inc(p);//如果s>=30的话,再加1分;
if s>=120 then inc(p);//以此类推;
if s>=365 then inc(p);
end
else inc(m);//如果b=0那么m+1;
end;
writeln(p);//输出p;
end.