题解 P1664 【每日打卡心情好】

· · 题解

这道题纯模拟就好,要注意的就是一个是连续天数如果是负数,那么要变成0。所有减去的天数是在连续漏签结束之后一起结算的,结算一次就够了。其余见代码注释吧

program wan;
     var a,n,i,j,lx,yl,sum,p,q:longint;
begin
     readln(n);
     p:=1;q:=1;yl:=0;lx:=0;//yl是遗漏,lx是连续
     for i:=1 to n do 
     begin
         readln(a);
         if a=1 then 
         begin
             if yl=1 then begin  q:=1;lx:=lx-q;end;//q表示减去的连续天数
             if yl>1 then begin  for j:=1 to (yl-1) do q:=q*2;lx:=lx-q;end;
             if lx<0 then lx:=0;
             yl:=0;q:=1;
             lx:=lx+1;
             if lx>=3 then p:=2;//p表示连续签到时增加的积分
             if lx>=7 then p:=3;
             if lx>=30 then p:=4;
             if lx>=120 then p:=5;
             if lx>=365 then p:=6;
             sum:=sum+p;
         end
         else
         begin    
             p:=1;
             yl:=yl+1;
         end;
     end;
     writeln(sum);
     readln;
end.