[SGU]111. Very simple problem
来源:互联网 发布:尔雅网络通识课答案 编辑:程序博客网 时间:2024/04/30 00:54
Analysis
不要被标题迷惑了!没那么看上去简单哟!刚看这题总觉得似曾相识,复习初赛的时候才发现是去年初赛完善程序的第一题……不过把那个程序交上去应当是会TLE的吧……因为它没压位……我的AC程序是二分+压位高精。据说还有笔算开方的算法,我果然小学数学没学好T T……
Accepted Code
var a,l,r,mid,sqrmid,tmp:array[0..1100] of int64; lens,lenl,lenr,lenmid,lensqrmid,i,j:longint; s:ansistring; bo1,bo2:boolean;function comp:boolean;var bo:boolean; i:longint;begin if not bo2 then begin tmp:=l; inc(tmp[1]); i:=1; while tmp[i]>99999999 do begin inc(tmp[i+1]); dec(tmp[i],100000000); inc(i); end; bo2:=true; end; bo:=true; for i:=1 to lenr do begin bo:=bo and (r[i]=tmp[i]); if not bo then break; end; comp:=bo;end;procedure calcsqrmid;var i,j:longint;begin fillchar(sqrmid,sizeof(sqrmid),0); for i:=1 to lenmid do for j:=1 to lenmid do sqrmid[i+j-1]:=sqrmid[i+j-1]+mid[i]*mid[j]; lensqrmid:=lenmid shl 1; for i:=1 to lensqrmid do begin sqrmid[i+1]:=sqrmid[i+1]+sqrmid[i] div 100000000; sqrmid[i]:=sqrmid[i] mod 100000000; end; if sqrmid[lensqrmid]=0 then dec(lensqrmid);end;begin readln(s); lens:=length(s) div 8; if length(s) mod 8<>0 then inc(lens); i:=1; while lens>i do begin val(copy(s,length(s)-7,length(s)),a[i],lenl); delete(s,length(s)-7,8); inc(i); end; val(s,a[i],lenl); fillchar(l,sizeof(l),0); l[1]:=1; lenl:=1; fillchar(r,sizeof(r),0); r[131]:=1; lenr:=131; bo2:=false; repeat fillchar(mid,sizeof(mid),0); for i:=1 to lenr do begin mid[i]:=mid[i]+l[i]+r[i]; if mid[i]>=100000000 then begin mid[i]:=mid[i]-100000000; mid[i+1]:=1; end; end; if mid[lenr+1]>0 then lenmid:=lenr+1 else lenmid:=lenr; for i:=lenmid downto 1 do begin if mid[i] and 1>0 then inc(mid[i-1],100000000); mid[i]:=mid[i] shr 1; end; if mid[lenmid]=0 then dec(lenmid); if (lenmid*2<lens) or (lenmid*2-1>lens) then bo1:=lenmid*2-1>lens else begin calcsqrmid; if lensqrmid<>lens then bo1:=lensqrmid>lens else begin i:=lens; while (i>0) and (sqrmid[i]=a[i]) do dec(i); bo1:=sqrmid[i]>a[i]; end; end; if bo1 then begin r:=mid; lenr:=lenmid; end else begin l:=mid; lenl:=lenmid; bo2:=false; end; if lenl+1<lenr then continue; until comp(); write(l[lenl]); for i:=lenl-1 downto 1 do begin str(l[i],s); while length(s)<8 do s:='0'+s; write(s); end; writeln;end.
- [SGU]111. Very simple problem
- SGU 111 Very simple problem
- SGU 111 Very simple problem
- SGU 111 Very simple problem
- SGU 111 Very simple problem(高精度)
- 111. Very simple problem
- sgu 111 Very simple problem 高精开平方
- SGU 111 Very simple problem(高精度+二分)
- 1166 Very Simple Problem
- [Java]Very simple problem
- sgu111:Very simple problem
- SGU111 Very simple problem
- FOJ 1350 Very Simple Problem
- FZU 1350 Very Simple Problem
- POJ 2535 Very Simple Problem
- poj 2535 Very Simple Problem
- 【FOJ 1350】 Very Simple Problem
- foj 1350 Very Simple Problem
- 折半查找法的两种实现
- c++组件与常见的几种类的类型
- 书单计划
- 软工-结构化分析总结
- 链表的逆转 -- java实现
- [SGU]111. Very simple problem
- 《深入浅出MFC》学习笔记(一)
- asus笔记本升级bios
- windows8开发-使用sqlite数据库的几点小结
- 基于MATLAB的adaboost级联形式的人脸检测实现
- 调试第一个KMDF驱动程序
- 关于CORE DOWN
- 关于Java 23种设计模式的有趣见解
- 再谈外观模式