Общий форумprogram airline; const max=50; var map:array[1..max*max,1..2] of longint; cover:array[1..max*max] of boolean; list:array[1..max*max] of longint; n,m:longint; procedure readdata; var i:longint; begin fillchar(map,sizeof(map),0); readln(n,m); for i:=1 to m do readln(map[i][1],map[i][2]); end; procedure print; var i:longint; begin writeln('YES'); for i:=1 to m-1 do write(list[i],' '); writeln(list[m]); halt; end; function zhi(x,p,i:longint):boolean; var j,k,min,t,j1:longint; link:array[1..max*max] of longint; begin fillchar(link,sizeof(link),0); k:=0; min:=maxint; for j:=1 to m do if ((map[j][1]=x)or(map[j][2]=x)) then if (list[j]=0)and(p<>j) then begin zhi:=true; exit; end else if p<>j then begin inc(k); link[k]:=list[j]; if list[j]<min then min:=list[j]; end; inc(k); link[k]:=i; if k=1 then begin zhi:=true; exit; end; for j:=2 to min do begin t:=0; for j1:=1 to k do if link[j1] mod j=0 then inc(t); if t>=k then begin zhi:=false; exit; end; end; zhi:=true; end; procedure search(p:longint); var t,i:longint; begin if p>m then print else begin for i:=1 to n do if not cover[i] then if zhi(map[p][1],p,i) then if zhi(map[p][2],p,i) then begin cover[i]:=true; list[p]:=i; search(p+1); list[p]:=0; cover[i]:=false; end; end; end; procedure main; var i,j:longint; begin fillchar(list,sizeof(list),0); fillchar(cover,sizeof(cover),0); search(1); end; BEGIN readdata; main; writeln('NO'); END. 1. it will be fully translated into english ?? 2. what is this site ? 3. what will be the level of the problems ? > {$R+,Q+,S+} const maxn = 200; var w : array[1..maxn, 0..maxn] of integer; lx, ly : array[1..maxn] of integer; ux, uy : array[1..maxn] of boolean; g : array[1..maxn] of integer; n, d : integer; i, x, y : integer; function can(x, y : integer) : boolean; begin can := lx[x] + ly[y] = w[x, y]; end; function process(k : integer) : boolean; var i : integer; begin if ux[k] then begin process := false; exit; end; ux[k] := true; for i := 1 to n do if can(k, i) then begin uy[i] := true; if (g[i] = 0) or (process(g[i])) then begin g[i] := k; process := true; exit; end; end; process := false; end; begin { assign(input, 'input.txt'); reset(input); assign(output, 'output.txt'); rewrite(output);} fillchar(w, sizeof(w), 0); read(n); for x := 1 to n do for y := 1 to n do begin read(w[x, y]); w[x, 0] := w[x, 0] + w[x, y]; end; fillchar(lx, sizeof(lx), 0); fillchar(ly, sizeof(ly), 0); for x := 1 to n do begin lx[x] := maxint; for y := 1 to n do begin w[x, y] := w[x, 0] - w[x, y]; if w[x, y] < lx[x] then lx[x] := w[x, y]; ly[y] := 0; end; w[x, 0] := 0; end; fillchar(g, sizeof(g), 0); for i := 1 to n do begin fillchar(ux, sizeof(ux), false); fillchar(uy, sizeof(uy), false); while not process(i) do begin d := maxint; for x := 1 to n do if ux[x] then for y := 1 to n do if not uy[y] then begin if w[x, y] - lx[x] - ly[y] < d then d := w[x, y] - lx [x] - ly[y]; end; for x := 1 to n do if ux[x] then lx[x] := lx[x] + d; for y := 1 to n do if uy[y] then ly[y] := ly[y] - d; fillchar(ux, sizeof(ux), false); fillchar(uy, sizeof(uy), false); end; end; d := 0; for i := 1 to n do d := d + w[g[i], i]; writeln(d); end. > {$R+,Q+,S+} > const maxn = 200; > var w : array[1..maxn, 0..maxn] of integer; > lx, ly : array[1..maxn] of integer; > ux, uy : array[1..maxn] of boolean; > g : array[1..maxn] of integer; > n, d : integer; > i, x, y : integer; > > function can(x, y : integer) : boolean; > begin > can := lx[x] + ly[y] = w[x, y]; > end; > > function process(k : integer) : boolean; > var i : integer; > begin > if ux[k] then > begin > process := false; > exit; > end; > ux[k] := true; > > for i := 1 to n do > if can(k, i) then > begin > uy[i] := true; > if (g[i] = 0) or (process(g[i])) then > begin > g[i] := k; > process := true; > exit; > end; > end; > process := false; > end; > > begin > { assign(input, 'input.txt'); reset(input); > assign(output, 'output.txt'); rewrite(output);} > > fillchar(w, sizeof(w), 0); > read(n); > for x := 1 to n do > for y := 1 to n do > begin > read(w[x, y]); > w[x, 0] := w[x, 0] + w[x, y]; > end; > > fillchar(lx, sizeof(lx), 0); > fillchar(ly, sizeof(ly), 0); > for x := 1 to n do > begin > lx[x] := maxint; > for y := 1 to n do > begin > w[x, y] := w[x, 0] - w[x, y]; > if w[x, y] < lx[x] then lx[x] := w[x, y]; > ly[y] := 0; > end; > w[x, 0] := 0; > end; > > fillchar(g, sizeof(g), 0); > for i := 1 to n do > begin > fillchar(ux, sizeof(ux), false); > fillchar(uy, sizeof(uy), false); > while not process(i) do > begin > d := maxint; > for x := 1 to n do > if ux[x] then > for y := 1 to n do > if not uy[y] then > begin > if w[x, y] - lx[x] - ly[y] < d then d := w[x, y] - lx > [x] - ly[y]; > end; > for x := 1 to n do > if ux[x] then lx[x] := lx[x] + d; > for y := 1 to n do > if uy[y] then ly[y] := ly[y] - d; > fillchar(ux, sizeof(ux), false); > fillchar(uy, sizeof(uy), false); > end; > end; > > d := 0; > for i := 1 to n do > d := d + w[g[i], i]; > writeln(d); > end. if it is a hierarchical structure, rooted at the president that means that the strucure is a tree. Well if it is a tree there should be only n-1 connections why does it have to end with 0 0. My program reads only n-1 line after the conviviality ratings. Is thits why i get WA or what is it. Pls help program party; var p,nf :array[1..6000] of integer; {p[i] supervisor of i} {nf number of "sons"} cu,fa :array[1..6000] of longint; {cu[i] maximum conviviality rating when employee i comes to the party fa[i] maximum conviviality rating when employee i stays home} cov :array[1..6000] of integer; nx,cr,n,i,last:integer; {cr current leaf nx next leaf} {every time we analyze a leaf we cut it from the tree} {doing that at a time another node will becom a leaf} begin read(n); fillchar(nf,12000,0); fillchar(fa,24000,0); fillchar(cu,24000,0); fillchar(p ,12000,0); for i:=1 to n do begin read(cov[i]); end; cu[1]:=cov[1]; for i:=2 to n do begin read(cr,nx); inc(nf[nx]); p[cr]:=nx; cu[i]:=cov[i]; end; i:=1; {search for the first leaf} while (nf[i]>0) do inc(i); cr:=i; inc(i); {search for the next if it exists} while (nf[i]>0) and (i<=n) do inc(i); nx:=i; while true do begin if p[cr]>0 then begin cu[p[cr]]:=fa[cr]+cu[p[cr]]; if fa[cr]>cu[cr] then fa[p[cr]]:=fa[p[cr]]+ fa[cr] else fa[p[cr]]:=fa[p[cr]]+ cu[cr]; dec(nf[p[cr]]); cr:=p[cr]; if (cr>nx) or (nf[cr]<>0) then begin {execute if the father doesn't become a leaf or the father is bigger than nx, otherwise process the father} cr:=nx; inc(nx); while (nx<=n) and (nf[nx]>0) do inc (nx); end; end else break; end; {when father of cr is 0 cr is the president} writeln(cu[cr]); end. PS sorry for my english my program read n-1 line and got AC there are something wrong with your program na :) void input(void) { long i; fscanf(fp,"%ld",&n); for(i=1;i<=n;i++) fscanf(fp,"%ld",&rate[i]); for(i=1;i<n;i++) { fscanf(fp,"%ld %ld",&con[i].l,&con[i].k); deg[con[i].l]++; } } ok! mailto:chinaangel007@yahoo.com it's simple! wish you! > var ans:longint; num,i,k,s,x:longint; function c(m,n:longint):longint; var ans:int64; i:longint; begin ans:=1; for i:=1 to m do ans:=ans*(n+1-i); for i:=1 to m do ans:=ans div i; c:=ans; end; function divide(x:longint):longint; var i,tot:longint; begin i:=1; tot:=0; repeat inc(i); if x mod i=0 then begin x:=x div i; if x mod i=0 then begin divide:=0; exit; end; inc(tot); end; until x=1; divide:=tot; end; begin readln(k,s); ans:=0; for i:=2 to s do if (s div i>=k) then begin x:=s div i; num:=divide(i); if num<>0 then begin if num mod 2=1 then inc(ans,c(k,x)) else dec(ans,c(k,x)); end; end; if ans>10000 then ans:=10000; writeln(ans); end. u can get AC in 2.593 sec by only search(like bfs) and bound : ) Help me please!!! ------------------------------------- var s,n,sum,i,j,k,a:longint; procedure solve(i:integer); var j:integer; begin for j:=i to s do readln; end; begin readln(s,n); k:=0; for i:=1 to s do begin read(a); inc(k); if a<>0 then sum:=sum+a else begin if sum>k+n then begin solve(i); write('No'); halt; end else if sum<k then begin sum:=0; k:=0; end end; end; if sum>k+n then write('No') else write('Yes'); end. ---------------------------------- Thank you!!! Just think when it is most likely the inequality won't be true ! When You realize it You'll get AC ! program permutation; var m,p : array [1..1000] of word; N,i,j : integer; k : longint; quit : boolean; Begin readln(N); for i := 1 to N do read(p[i]); for i := 1 to n do m[i]:=p[i]; k:=1; quit := false; while true do begin j:=0; repeat j:=j+1; quit := m[j]=j; until (quit=false) or ((i=n) and (m[i]=i)); if quit then break; k:=k+1; for i := 1 to n do m[i] := p[m[i]]; end; writeln(K); end. here is my code please help me ... ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var n,k,j,k1,k2 : integer; a : array [1..1000,1..1000] of integer; lab : array [1..1000] of boolean; win : array [1..1000] of integer; find : boolean; procedure dfs(w,w1:integer); var i : integer; f,f1 : boolean; begin f:=false;lab[w]:=true; for i:=1 to n do if not lab[i] and (a[i,w]>0) then begin dfs(i,3-w1); f:=true; end; if not f then win[w]:=2 else begin f1:=false; for i:=1 to n do if (a[i,w]>0) and (win[i]=3-w1) then f1:=true; if f1 then win[w]:=w1 else win[w]:=3-w1; end; end; begin find:=false; fillchar(lab,sizeof(lab),False); fillchar(win,sizeof(win),0); readln(n,k); for j:=1 to n-1 do begin read(k1,k2); a[k1,k2]:=1; a[k2,k1]:=1; end; dfs(k,1); for k1:=1 to n do if (a[k1,k]=1) and (win[k1]=2) then begin find:=true; writeln('First player wins flying to airport ',k1); break; end; if not find then writeln('First player loses'); end. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Program funny; var n,k,k1,k2,k3: integer; f : boolean; a : array[1..1000,0..20] of integer; win : array[1..1000] of byte; procedure dfs(w:integer); var i : integer; begin if a[w,0]=0 then begin win[w]:=1; exit; end else begin for i:=1 to a[w,0] do dfs(a[w,i]); win[w]:=1; for i:=1 to a[w,0] do if win[a[w,i]]=1 then win[w]:=2; end; end; begin readln(n,k); for k1:=1 to n-1 do begin readln(k2,k3); inc(a[k2,0]); a[k2,a[k2,0]]:=k3; end; dfs(k);k2:=10001;f:=false; for k1:=1 to a[k,0] do if win[a[k,k1]]=1 then begin f:=true; if a[k,k1]<k2 then k2:=a[k,k1]; end; if f then writeln('First player wins flying to airport ',k2) else writeln('First player loses'); end. > Program funny; > var > n,k,k1,k2,k3: integer; > f : boolean; > a : array[1..1000,0..20] of integer; > win : array[1..1000] of byte; > procedure dfs(w:integer); > var > i : integer; > begin > if a[w,0]=0 then > begin > win[w]:=1; > exit; > end > else > begin > for i:=1 to a[w,0] do > dfs(a[w,i]); > win[w]:=1; > for i:=1 to a[w,0] do > if win[a[w,i]]=1 then > win[w]:=2; > end; > end; > begin > readln(n,k); > for k1:=1 to n-1 do > begin > readln(k2,k3); > inc(a[k2,0]); > a[k2,a[k2,0]]:=k3; > end; > dfs(k);k2:=10001;f:=false; > for k1:=1 to a[k,0] do > if win[a[k,k1]]=1 then > begin > f:=true; > if a[k,k1]<k2 then k2:=a[k,k1]; > end; > if f then > writeln('First player wins flying to airport ',k2) > else > writeln('First player loses'); > end. #include<stdio.h> #include<stdlib.h> #include<math.h> int main(void) { int i; long N; long term; int *a; scanf("%ld",&N); a=(int *)malloc(N*sizeof(int)); for(i=0;i<N;i++){ scanf("%ld",&term); a[i]=(int)(1+(int)(sqrt(8*term-7))-sqrt(8*term-7));
} for(i=0;i<N;i++)printf("%2d",a[i]); return 0; } Thank you! a[i]=(int)(1+(int)(sqrt((float)(8*term-7)))-sqrt((float)(8*term-7))); but long int have 4 bytes and, 2^31*8 = overflow ;) > a[i]=(int)(1+(int)(sqrt((float)(8*term-7)))-sqrt((float)(8*term- 7))); > > but > long int have 4 bytes > and, 2^31*8 = overflow ;) thank you! #include <stdio.h> main(t,_,a)char *a;{return!0<t?t<3?main(-79,-13,a+main(-87,1-_, main(-86,0,a+1)+a)):1,t<_?main(t+1,_,a):3,main(-94,-27+t,a)&&t==2? _<13? main(2,_+1,"%s %d %d\n"):9:16:t<0?t<-72?main(_,t, "@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l+,/n {n+,/+#n+,/#;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l q#'+d'K#!/+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d} rw' i;# ){nl]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#n'wk nw' iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c ;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;#'rdq#w! nr'/ ') }+} {rl#'{n' ')# }'+}##(!!/") :t<-50?_==*a?putchar(31[a]):main(-65,_,a+1):main((*a=='/')+t,_,a+1) :0<t?main(2,2,"%s"):*a=='/'||main(0,main(-61,*a, "!ek;dc i@bK'(q)-[w]*%n+r3#l,{}:\nuwloca- O;m .vpbks,fxntdCeghiry"),a+1);} I have some problem with a type of numbers and get a WA, But now i got AC CONST NMax = 250; VAR Route : ARRAY[1..NMax, 1..NMax] OF LongInt; Used : ARRAY[1..NMax] OF Boolean; Path : ARRAY[0..NMax] OF Integer; N, M, I, T, H, Count : LongInt; Found : Boolean; PROCEDURE DSF(Start, C : LongInt); VAR I : LongInt; BEGIN Used[C] := True; IF (Route[C, Start] = 2) THEN BEGIN Found := True; Used[C] := False; Exit; END; FOR I := 1 TO N DO IF (NOT Used[I]) AND (Route[C, I] = 2) THEN BEGIN Route[C, I] := 0; Route[I, C] := 0; DSF(Start, I); Route[C, I] := 2; Route[I, C] := 2; IF Found THEN Break; END; IF (NOT Found) THEN IF (Route[C, Start] = 1) THEN BEGIN Route[Start, C] := 2; Route[C, Start] := 2; Found := True; END; IF NOT Found THEN FOR I := 1 TO N DO IF (NOT Used[I]) AND (Route[C, I] = 1) THEN BEGIN Route[C, I] := 0; Route[I, C] := 0; DSF(Start, I); IF Found THEN BEGIN Route[C, I] := 2; Route[I, C] := 2; Break; END ELSE BEGIN Route[C, I] := 1; Route[I, C] := 1; END; END; Used[C] := False; END; PROCEDURE DSF2(Start, C, Size : LongInt); VAR I : LongInt; BEGIN Used[C] := True; IF (Route[C, Start] = 1) THEN BEGIN Found := True; Used[C] := False; Path[Size] := C; Path[0] := Size; Exit; END; FOR I := 1 TO N DO IF (NOT Used[I]) AND (Route[C, I] = 1) THEN BEGIN Route[C, I] := 0; Route[I, C] := 0; DSF2(Start, I, Size+1); Route[C, I] := 1; Route[I, C] := 1; IF Found THEN BEGIN Path[Size] := C; Break; END; END; IF (NOT Found) THEN IF (Route[C, Start] = 2) THEN BEGIN Route[Start, C] := 1; Route[C, Start] := 1; Path[Size] := C; Path[0] := Size; Found := True; END; IF NOT Found THEN FOR I := 1 TO N DO IF (NOT Used[I]) AND (Route[C, I] = 2) THEN BEGIN Route[C, I] := 0; Route[I, C] := 0; DSF2(Start, I, Size+1); IF Found THEN BEGIN Route[C, I] := 1; Route[I, C] := 1; Path[Size] := C; Break; END ELSE BEGIN Route[C, I] := 2; Route[I, C] := 2; END; END; Used[C] := False; END; BEGIN FillChar(Route, SizeOf(Route), 0); FillChar(Used, SizeOf(Used), False); ReadLn(N, M); FOR I := 1 TO M DO BEGIN ReadLn(T, H); Route[T, H] := 1; Route[H, T] := 1; END; Count := 0; FOR T := 1 TO N DO FOR H := 1 TO N DO IF Route[T, H] = 1 THEN BEGIN Used[T] := True; Route[T, H] := 0; Route[H, T] := 0; Found := False; DSF(T, H); IF Found THEN BEGIN Route[T, H] := 2; Route[H, T] := 2; Inc(Count); END ELSE BEGIN Route[T, H] := 1; Route[H, T] := 1; END; Used[T] := False; END; WriteLn(Count); IF Count <> 0 THEN BEGIN FOR T := 1 TO N DO FOR H := 1 TO N DO IF Route[T, H] = 2 THEN BEGIN Used[T] := True; Route[T, H] := 0; Route[H, T] := 0; Found := False;
|
|