【NOIP2017练习】溢出(模拟)

题意:

思路:

a*b<=c <====> b<=c div a

 1 var ch,maxs,s:ansistring;
 2     v,k,i,maxl,l,len,cnt,cas:longint;
 3     now,tmp,max:qword;
 4     flag:boolean;
 5 
 6 begin
 7  assign(input,'overflow.in'); reset(input);
 8  assign(output,'overflow.out'); rewrite(output);
 9  readln(cas);
10  for v:=1 to cas do
11  begin
12   readln(ch); len:=length(ch);
13   max:=1; k:=0;
14   for i:=1 to len do
15    if (ch[i]>='0')and(ch[i]<='9') then k:=k*10+ord(ch[i])-ord('0');
16    if k=8 then maxl:=3;
17   if k=16 then maxl:=5;
18   if k=32 then maxl:=10;
19   if k=64 then
20    if ch[1]='i' then maxl:=19
21      else maxl:=20;
22   if ch[1]='i' then dec(k);
23   for i:=1 to k-1 do max:=max*2;
24   max:=max-1+max;
25   str(max,maxs);
26   readln(ch); len:=length(ch);
27   flag:=false;
28   i:=0; now:=1; cnt:=0;
29   while (not flag)and(i<=len) do
30   begin
31    inc(i); tmp:=0; l:=0; s:=''; inc(cnt);
32    while (i<=len)and(ch[i]>='0')and(ch[i]<='9') do
33    begin
34     inc(l); s:=s+ch[i];
35     if (l>maxl)or(l=maxl)and(s>maxs) then
36     begin
37      flag:=true; break;
38     end;
39     tmp:=tmp*10+ord(ch[i])-ord('0');
40     inc(i);
41    end;
42    if flag then break;
43    if now>max div tmp then
44    begin
45     flag:=true; break;
46    end;
47    now:=now*tmp;
48   end;
49   if flag then writeln(cnt)
50    else writeln('never');
51  end;
52 
53  close(input);
54  close(output);
55 end.

 

posted on 2017-11-07 09:41  myx12345  阅读(200)  评论(0编辑  收藏  举报

导航