[Rqnoj-148][NOIP1999]回文数
2012-01-06 17:32
106 查看
回文数
高精度,比较水,好像我的代码有点长,不过我觉得这种题套模版是个好习惯~
代码:
高精度,比较水,好像我的代码有点长,不过我觉得这种题套模版是个好习惯~
代码:
type hp=array[0..10000] of longint; var n,ans:longint; a:hp; function d(c:char):longint; begin case c of '0':d:=0; '1':d:=1; '2':d:=2; '3':d:=3; '4':d:=4; '5':d:=5; '6':d:=6; '7':d:=7; '8':d:=8; '9':d:=9; 'A':d:=10; 'B':d:=11; 'C':d:=12; 'D':d:=13; 'E':d:=14; 'F':d:=15; end; end; function ok(a:hp):boolean; var i,j:longint; begin i:=1; j:=a[0]; ok:=true; while i<j do begin if a[i]<>a[j] then begin ok:=false; break; end; inc(i); dec(j); end; end; function fan(a:hp):hp; var b:hp; i:longint; begin fillchar(b,sizeof(b),0); b[0]:=a[0]; for i:=1 to a[0] do b[a[0]-i+1]:=a[i]; fan:=b; end; procedure h_jia(a,b:hp;var c:hp); var i,len:longint; begin if a[0]>b[0] then len:=a[0] else len:=b[0]; fillchar(c,sizeof(c),0); for i:=1 to len do begin c[i]:=c[i]+a[i]+b[i]; c[i+1]:=c[i+1]+c[i] div n; c[i]:=c[i] mod n; end; if c[len+1]<>0 then inc(len); c[0]:=len; end; procedure main; var s:string; i:longint; begin readln(n); readln(s); fillchar(a,sizeof(a),0); a[0]:=length(s); for i:=1 to a[0] do a[a[0]-i+1]:=d(s[i]); ans:=-1; for i:=0 to 30 do begin if ok(a) then begin ans:=i; break end; h_jia(a,fan(a),a); end; if ans=-1 then write('Impossible') else write(ans); end; begin main; end.
相关文章推荐
- rqnoj[NOIP1999]拦截导弹
- rqnoj[NOIP1999]拦截导弹
- codevs 1045 NOIP 1999 回文数 高精度算法
- NOIP 1999 普及组 复赛 回文数
- 【BZOJ】1999 [Noip2007]Core树网的核 树的直径+DFS
- [NOIP1999]邮票面值设计
- [Rqnoj-574][NOIP1998]连接多位数
- 洛谷1020拦截导弹(NOIP1999)
- RQNOJ PID302 / [NOIP2001]统计单词个数 (动态规划)
- 【原创】【NOIP2016普及组】回文日期
- [NOIP1999]旅行家的预算
- [NOIP1999提高] CODEVS 1047 邮票面值设计(dfs+dp)
- DP 拦截导弹(Noip1999)
- luogu1014 Cantor表(NOIP1999普及组第1题)
- 贪心(洛谷1016 vijos1253旅行家的预算noip1999提高组)
- RQNOJ 311 [NOIP2000]乘积最大:划分型dp
- rqnoj-314-[NOIP2000]方格取数-多线程dp
- NOIP1999 旅行家的预算
- [NOIP1999]导弹拦截NlogN做法
- 【NOIP1999】旅行家的预算