Common BoardThis problem seem to be easy,but I can pass it.Who can tell me how to do it? Thank you. My e-mail is 'frfangrun@21cn.com'. This problem seem to be easy,but I can pass it.Who can tell me how to do it? Thank you. My e-mail is 'frfangrun@21cn.com'. 1. change each '\' into #1 2. sort the strings in lexicographic order 3. print, and make some changes but i'm still wa, who can tell me why? const maxn=100; maxl=8; type words=string[maxl]; var vocabulary:array [1..maxn] of words; mispell,i,n,l,k,s:byte; bf:char; now:words; mistake:word; procedure judge; begin if l>0 then begin now[0]:=char(l);s:=0; for i:=1 to n do if l=byte(vocabulary[i,0]) then begin mispell:=0; for k:=1 to l do if now[k]<>vocabulary[i,k] then begin inc(mispell); if mispell>1 then break; end; if mispell=0 then begin s:=0;break;end else if mispell=1 then s:=i; end; if s=0 then write(now) else begin write(vocabulary[s]); inc(mistake); end; l:=0; end;{if} end; begin n:=1; readln(vocabulary[n]); while (vocabulary[n]<>'#') do begin inc(n); readln(vocabulary[n]); end; dec(n);l:=0;mistake:=0; while not eof(input) do begin read(bf); case bf of 'a'..'z': begin inc(l); now[l]:=bf; end else begin judge; write(bf); end;{else} end;{case} end;{while} judge; writeln(mistake); end. I have written the simple O(n) approach and I think that there is no test case that it fails at. But, I get WA. Also, it's written that if there are more than one solution- to ouput what I prefer. Is that right? Do they check just if the ouput is correct or the have an exact output file? my program is very easy: Const InFile = '1116.in'; Limit = 3000; LimitLen = 30001; nodomain = 127; Type Tline = array[-LimitLen..LimitLen] of shortint; Var A , B , C : Tline; procedure init; var N , i , x , y , F , t : integer; begin for i := -LimitLen to LimitLen do begin A[i] := nodomain; B[i] := nodomain; end; { assign(INPUT , InFile); ReSet(INPUT);} read(N); for i := 1 to N do begin read(x , y , F); for t := x to y - 1 do A[t] := F; end; readln; read(N); for i := 1 to N do begin read(x , y , F); for t := x to y - 1 do B[t] := F; end; readln; { Close(INPUT);} end; procedure work; var i : integer; begin for i := -LimitLen to LimitLen do if A[i] = nodomain then C[i] := A[i] else if B[i] = nodomain then C[i] := A[i] else C[i] := nodomain; end; procedure out; var result : array[1..Limit , 1..3] of integer; all , i : integer; begin i := -Limit; all := 0; while i <= Limit do if C[i] = nodomain then inc(i) else begin inc(all); result[all , 1] := i; inc(i); while C[i] = C[i - 1] do inc(i); result[all , 2] := i; result[all , 3] := C[i - 1]; end; write(all); for i := 1 to all do write(' ' , result[i , 1] , ' ' , result[i , 2] , ' ' , result[i , 3]); writeln; end; Begin init; work; out; End. program ural1008; const walk:array[1..4] of integer=(10,1,-10,-1); ss:array[1..4] of char=('R','T','L','B'); var a:array[0..100] of integer; map:array[0..100] of boolean; n,x,y,i,j,k:integer; s:string; w:integer; function strtoint(s:string):integer; var i,j:integer; begin val(s,i,j); strtoint:=i; end; procedure work1(n:integer); var i,x,y,st,la,j,k:integer; begin for i:=1 to n do begin readln(x,y); map[x*10-10+y-1]:=true; end; fillchar(a,sizeof(a),0); for i:=0 to 100 do if map[i]=true then break; if map[i]=false then begin writeln('.');exit;end; map[i]:=false; writeln(i div 10+1,' ',i mod 10+1); a[1]:=i; st:=0; la:=1; repeat st:=st+1; for i:=1 to 4 do if (map[a[st]+walk[i]])and(a[st]+walk[i] in [0..99]) then begin map[a[st]+walk[i]]:=false; la:=la+1; a[la]:=a[st]+walk[i]; write(ss[i]); end; if st<la then writeln(',') else writeln('.'); until st=la; end; procedure work2(xx,yy:integer); var i,t,st,la,j,k:integer; begin t:=0; { repeat } fillchar(a,sizeof(a),0); map[xx*10-10+yy-1]:=true; a[1]:=xx*10-10+yy-1; st:=0; la:=1; t:=t+1; repeat st:=st+1; readln(s); if s='.' then break; t:=t+length(s)-1; for j:=1 to length(s)-1 do for i:=1 to 4 do if ss[i]=s[j] then begin map[a[st]+walk[i]]:=true; la:=la+1; a[la]:=a[st]+walk[i]; end; until st=la; { readln(S); if s='.' then break else begin xx:=strtoint(copy(s,1,pos(' ',s)-1)); delete(s,1,pos(' ',s)); yy:=strtoint(s); end;} { until true=false;} writeln(t); for i:=1 to 10 do for j:=1 to 10 do if map[i*10-10+j-1] then writeln(i,' ',j); end; begin readln(s); k:=0; for i:=1 to length(s) do if s[i]=' ' then break; if i=length(s) then begin n:=strtoint(s); work1(n); end else begin if s='.' then begin writeln(0);exit;end else begin x:=strtoint(copy(s,1,pos(' ',s)-1)); delete(s,1,pos(' ',s)); y:=strtoint(s); work2(x,y); end; end; end. Yes,I admit that hard work is necessary and important,but for this single problem 1077,I thoght the algorithm for a whole day,nothing valuable was found.I must say that efficency is also need to be attached importance to.I wish somebody with kindness and eagerness will help me,I'll thank him(or her) a lot. > Yes,I admit that hard work is necessary and important,but > for this single problem 1077,I thoght the algorithm for a > whole day,nothing valuable was found.I must say that > efficency is also need to be attached importance to.I wish > somebody with kindness and eagerness will help me,I'll > thank him(or her) a lot. > Please, help! I've got 'Output limit'. What can be wrong? There's some suxx. I've got 'accepted' for this problem at our institute ACM training (AFAIK there's the same tests), but here's WA. What can be wrong? Then it turned out that he forgot to initialize some vasriable. So his program worked on his machine and did not work here. > There's some suxx. > I've got 'accepted' for this problem at our institute ACM training (AFAIK there's the same tests), but here's WA. What can be wrong? Моэет Анрдрей не может нормально скачать тесты? May be he is a LAMER?!! =) Type Arr = Array[1..32000] of Byte; Var A : Arr; C : Arr; N : Integer; i,j,k : Integer; Last : Integer; First : Integer; L : Integer; P : Longint; P1 : Integer; Begin Readln(N); A[1] := 1; For i := 1 to N-1 do Begin Fillchar(C,Sizeof(C),0); For L := 32000 downto 1 do If A[L]<>0 then Break; C := A; For j := 1 to L*2-1 do Begin Last := (j+1) Div 2; If (j+1) Mod 2=0 then Begin Inc(P,A[(j+1) div 2]*A[(j+1) Div 2]); Dec(Last); End; If j<=L then First := 1 else First := j-L; For k := First to Last do Inc(P,A[k]*A[j+1-k]*2); Inc(P,C[j]); C[j] := P Mod 10; P := P Div 10; End; P1 := L*2-1; While P<>0 do Begin Inc(P1); P := C[P1]+P; C[P1] := P Mod 10; P := P Div 10; End; P := 1; P1 := 1; Repeat P := P+A[P1]; A[P1] := P Mod 10; P := P Div 10; Until P=0; For j := 32000 downto 1 do If A[j]<>0 then Break; For k := j downto 1 do Write(A[k]); Writeln; A := C; End; P := 1; P1 := 1; Repeat P := P+A[P1]; A[P1] := P Mod 10; P := P Div 10; Until P=0; For L := 32000 downto 1 do If A[L]<>0 then Break; For j := L downto 1 do Write(A[j]); End. I think the floyd algorithm is very simple and can't be imporved,and I have to do it (N-2) times (because k>2,so the loop consists of at least 3 nodes,(N-2) is enough and also it's nessary,I think it's difficult to let it be quicker.My program uses over 8 secs,I wonder why so many people make their program so fast that cost nearly no time. Can you tell me how to DP? thank you. const fi = ''; fo = ''; maxn = 100; type dt = record d,c : longint; end; var f,g : text; n : longint; a : array[1..maxn] of dt; d : array[1..maxn] of longint; truoc : array[1..maxn] of longint; max : longint; li : longint; procedure nhap; var i,tg : longint; begin assign(f,fi); reset(f); readln(f,n); for i := 1 to n do begin readln(f,a[i].d,a[i].c); if a[i].d > a[i].c then begin tg := a[i].d; a[i].d := a[i].c; a[i].c := tg; end; end; close(f); end; procedure sapxep; var i,j : longint; tg : dt; begin for i := 1 to n - 1 do for j := i + 1 to n do if a[i].d > a[j].d then begin tg := a[i]; a[i] := a[j]; a[j] := tg; end; end; procedure qhd; var i,j : longint; begin max := -1; for i := 1 to n do begin d[i] := 1; truoc[i] := 0; for j := i - 1 downto 1 do if (a[j].c <= a[i].d) and (d[j] + 1 > d[i]) then begin d[i] := d[j] + 1; truoc[i] := j; end; if d[i] > max then begin max := d[i]; li := i; end; end; end; procedure truy( i : integer ); begin if truoc[i] <> 0 then truy(truoc[i]); writeln(g,a[i].d,' ',a[i].c); end; procedure ghi; begin assign(g,fo); rewrite(g); writeln(g,max); truy(li); close(g); end; BEGIN nhap; sapxep; qhd; ghi; END. Some notes : I write this program in Vietnamese. So here are some translations : nhap : read_data; sapxep : sort; qhd : DP; ghi : write_output; Hope you understand !!! mailto : trungduck@yahoo.com > Can you tell me how to DP? > thank you. I think we should better post ideas, and not solutions. > I think we should better post ideas, and not solutions. I wrote a program for 1068 "Sum" - the code is really very easy. Judge program says always me "wrong answer". Where is my mistake? Could anybody help me? program p; var i,n:longint; res:longint; begin read(n); res := 0; if (n >=1) then for i:=1 to n do res := res + i else for i:=1 downto n do res := res + i; write(res); end. I just took your solution and changed loop downto a little. This will be accepted: (has already been:). Mind that you don't have to use loop at all - just using formula n*(n+1)/2 seperately for n>=1 and n<1 :) I can post my solution here if you want, or send it by email program p; var i,n:longint; res:longint; begin read(n); res := 0; if (n >=1) then for i:=1 to n do res := res + i else begin res:=1; for i:=1 to -n do res := res - i; end; write(res); end. Since you know the solution,why don't you tell me or give me a reference program? > Since you know the solution,why don't you tell me or give > me a reference program? |
|