noip2004-虫食算 2008.11.5
2016-02-05 13:25
295 查看
noip2004-虫食算 2008.11.5
Program 1:辛苦了半天敲上去的程序,结果发现,忘了考虑一列中有相同的字母的情况—一定要想到没有下次再开始敲
Program 1:辛苦了半天敲上去的程序,结果发现,忘了考虑一列中有相同的字母的情况—一定要想到没有下次再开始敲
program alpha;{分了好多种情况} const fin='alpha.in';fout='lapha.out'; var f1,f2:text; n,i,j,nn:longint; c:array['A'..'Z']of longint; b:array[0..26]of boolean; x1,x2,x:string; procedure init; var i:longint;ch:char; begin fillchar(b,sizeof(b),true); assign(f1,fin);reset(f1); assign(f2,fout);rewrite(f2); readln(f1,n); readln(f1,x1); readln(f1,x2); readln(f1,x); for ch:='A' to 'Z' do c[ch]:=-1; nn:=n+1; end; procedure print; var ch:char; begin for ch:='A' to 'Z' do write(f2,c[ch]); close(f1);close(f2);halt; end; procedure deal(p,y:longint); var i,r,t1,t2,k1,k2,k3,k4,k5,k6:longint;s1,s2,s3:boolean; begin if p=n+1 then begin print;exit;end; r:=nn-p; if c[x1[r]]=-1 then s1:=false else s1:=true; if c[x2[r]]=-1 then s2:=false else s2:=true; if c[x[r]]=-1 then s3:=false else s3:=true; if (s1)and(s2)and(s3) and((c[x1[r]]+c[x2[r]]+y)mod n=c[x[r]]) then deal(p+1,(c[x1[r]]+c[x2[r]]+y)div n); if (s1) and (s2) and (not(s3)) then begin t1:=c[x1[r]]+c[x2[r]]; t2:=t1 mod n; if b[t2] then begin c[x[r]]:=t2;y:=t1 div n; b[t2]:=false; deal(p+1,y); b[t2]:=true; c[x[r]]:=-1; end end; if (s1) and (not(s2)) and (s3) then begin t1:=c[x[r]]-c[x1[r]]; if t1<0 then begin t1:=t1+n;y:=1;end else y:=0; if b[t1] then begin c[x2[r]]:=t1; b[t1]:=false; deal(p+1,y); c[x2[r]]:=-1; b[t1]:=true; end end; if (not(s1))and (s2) and (s3) then begin t1:=c[x[r]]-c[x2[r]]; if t1<0 then begin t1:=t1+n;y:=1;end else y:=0; if b[t1] then begin c[x1[r]]:=t1; b[t1]:=false; deal(p+1,y); c[x1[r]]:=-1; b[t1]:=true; end end; if (s1) and (not(s2))and (not(s3)) then for k1:=0 to n do if b[k1] then begin b[k1]:=false; t1:=c[x1[r]]+k1; t2:=t1 mod n; if b[t2] then begin c[x2[r]]:=k1; c[x[r]]:=t2; y:=t1 div n; b[t2]:=false; deal(p+1,y); b[t2]:=true; c[x[r]]:=-1; c[x2[r]]:=-1; end; b[k1]:=true; end; if (not(s1))and (s2) and (not(s3)) then for k3:=0 to n do if b[k3] then begin b[k3]:=false; t1:=c[x2[r]]+k3; t2:=t1 mod n; if b[t2] then begin c[x1[r]]:=k3; c[x[r]]:=t2; y:=t1 div n; b[t2]:=false; deal(p+1,y); b[t2]:=true; c[x[r]]:=-1; c[x1[r]]:=-1; end; b[k3]:=true; end; if (not(s1)) and (not(s2)) and (s3) then for k4:=0 to n do if b[k4] then begin b[k4]:=false; t1:=c[x[r]]-k4; if t1<0 then begin t1:=t1+n;y:=1;end else y:=0; if b[t1] then begin c[x1[r]]:=k4; c[x2[r]]:=t1; b[t1]:=false; deal(p+1,y); c[x1[r]]:=-1; c[x2[r]]:=-1; b[t1]:=true; end; b[k4]:=true; end; if (not(s1))and (not(s1)) and (not(s3)) then for k5:=0 to n do if b[k5] then begin b[k5]:=false; for k2:=0 to n do if b[k2] then begin b[k2]:=false; t1:=k5+k2; t2:=t1 mod n; if b[t2] then begin c[x1[r]]:=k5; c[x2[r]]:=k2; c[x[r]]:=t2; y:=t1 div n; b[t2]:=false; deal(p+1,y); c[x1[r]]:=-1; c[x2[r]]:=-1; c[x[r]]:=-1; b[t2]:=true; end;{if b[t2]} b[k2]:=true; end;{if b[k2]} b[k5]:=true; end; end;{deal} begin init; deal(1,0); close(f1); close(f2); end.
相关文章推荐
- time stamp in javascript
- 表头无权限分组构件
- 【动态规划】[BZOJ1037][ZJOI2008]生日聚会Party
- jQuery工具函数
- Activity,ContextImpl,PhoneWindow对象创建总结
- noip2002字串变换 2008.11.5
- Atom packages installing error gyp trubingshot
- POJ 2777 线段树区间查询区间更新
- MmGetSystemRoutineAddress routine
- Tomcat配置环境变量
- 关于[NSNull length]: unrecognized selector sent to instance的问题
- noip2002-均分纸牌 2008.11.5
- noip2001-一元三次方程 2008.11.5
- C++多线程编程——线程的挂起、唤醒与终止
- noip2001-统计单词个数2008.11.5
- 解决CocoaPods在OS X 10.11出现问题While executing gem ... (Errno::EPERM) Operation not permitted - /usr/bin/
- POJ 2828 线段树单点插入
- BZOJ 2707: [SDOI2012]走迷宫( tarjan + 高斯消元 )
- SolarWinds 2002
- textarea如何实现高度自适应