Common Board| Show all threads Hide all threads Show all messages Hide all messages | | WAAAAAAAAAAAAA HHHHEEEELLLLPPPP | Oleg | 1056. Centers of the Net | 7 Apr 2003 18:03 | 7 | var i,j,k,n,l,m,m1:longint; a,b,c,r:array [0..10000] of integer; stack :array [0..1,0..10000] of integer; function search(k:integer):integer; var i,j,l:integer; begin l:=0; if k>1 then if c[a[k]]=0 then begin c[a[k]]:=c[k]+1; l:=1; end; for i:=1 to n do begin if a[i]=k then if c[i]=0 then begin c[i]:=c[k]+1; l:=1; end; end; search:=l; end; begin read(n); for i:=2 to n do read(a[i]); for i:=1 to n do b[a[i]]:=1; for k:=1 to n do begin if b[k]=0 then continue; fillchar(stack,sizeof(stack),0); fillchar(c,sizeof(c),0); c[k]:=1; l:=0; while l=0 do begin for i:=1 to n do if c[i]>0 then l:=search(i); l:=1-l; end; l:=0; for i:=1 to n do if c[i]>l then l:=c[i]; if l>m then begin fillchar(r,sizeof(r),0); m1:=0; m:=l; end; inc(m1); r[m1]:=k; end; for i:=1 to m1-1 do write(r[i],' '); writeln(r[m1]); end. TL Oleg 12 Dec 2002 06:51 var i,j,k,n,l,m,m1:longint; a,b,c,r:array [0..10000] of integer; function search(k:integer):integer; var i,j,l:integer; begin l:=0; if k>1 then if c[a[k]]=0 then begin c[a[k]]:=c[k]+1; l:=1; end; for i:=1 to n do if a[i]=k then if c[i]=0 then begin c[i]:=c[k]+1; l:=1; end; search:=l; end; begin read(n); for i:=2 to n do begin read(a[i]); b[a[i]]:=1; end; for k:=1 to n do begin fillchar(c,sizeof(c),0); c[k]:=1; l:=0; while l=0 do begin for i:=1 to n do if c[i]>0 then if search(i)=1 then l:=1; l:=1-l; end; l:=0; for i:=1 to n do if c[i]>l then l:=c[i]; if (l<m) or (m=0) then begin fillchar(r,sizeof(r),0); m1:=0; m:=l; end; if l=m then begin inc(m1); r[m1]:=k; end; end; for i:=1 to m1-1 do write(r[i],' '); writeln (r[m1]); end. my olgoritm is O(n*n*n); int`s bad; Can you give me algoritm var i,j,k,n,m,k1:integer; a,b,c :array [1..10000] of integer; s:array [0..1,0..10000] of integer; procedure push(k,x:integer); begin inc(s[k,0]); s[k,s[k,0]]:=x; end; function pop(k:integer):integer; begin if s[k,0]>0 then begin pop:=s[k,s[k,0]]; dec(s[k,0]); end else pop:=-1; end; function search(k:integer):integer; var i,j,l:integer; begin l:=0; if k>1 then if c[a[k]]=0 then begin c[a[k]]:=c[k]+1; l:=1; push(1-k1,a[k]); end; for i:=1 to n do if a[i]=k then if c[i]=0 then begin c[i]:=c[k]+1; l:=1; push(1-k1,i); end; search:=l; end; procedure Init; var i : integer; begin read(n); b[1] := 0; for i := 2 to n do b[i] := 1; for i := 2 to n do begin read(a[i]); inc(b[a[i]]); end; end; begin Init; k1:=0; for i:=1 to n do if b[i]=1 then begin push(k,i); c[i]:=1; end; if n>2 then repeat while true do begin i:=pop(k1); if i=-1 then break; search(i); end; k1:=1-k1; until (pop(0)=-1) and (pop(1)=-1); j:=0; for i:=1 to n do if j<c[i] then j:=c[i]; k := 0; for i:=1 to n do begin if c[i]=j then begin k:= k+1; b[k] := i; end; end; for i := 1 to k-1 do begin write(b[i],' '); end; write(b[k]); end. i can giv AC program if you give 1013 Tuphanov@eastnet.febras.ru if you give me ac program 1089 or 1189 or 1013 or 1012 or else then i give you 1059 ac I can email you 1013 please email me 1056 and I will reply your email with the solution to 1013. Thanks Email me at drajmsadeq@yahoo.com | | Who knows? When in task 1251 input is complete? | PolterGeits amD (KHSTU) | | 7 Apr 2003 16:05 | 5 | Just with the end of the input file. | | If there aren't any contests - is it possible to set up mine ?? | uuuuuuu | | 7 Apr 2003 12:10 | 2 | Yes it is. Thee must something on "How do I setup my own contest" somewhere her. Anyway, the first action should be to determine the date for the forthcoming contest, and to send me or to atn@timus.ru the contest archive - tasks, tests, solutions. My email is volkov (at) skbkontur.ru | | Witch will win. Juventus or Barselona ? | I am david. Tabo. | | 7 Apr 2003 00:00 | 2 | | | 2 Miguel Angel or any1 who has solved 1254 | uuuuuuu | | 6 Apr 2003 21:12 | 2 | 1. Did You use BFS ? 2. I use improved BFS and my complexity is (k*BFS+seeking for the shortest way which takes the length of the way). But i always get TLE ?! | | Problem 1084 | Wendell | | 6 Apr 2003 20:04 | 1 | I got Compilation Error.But my program works correctly in VC6. Please help me. My program: #include <iostream.h> #include <stdio.h> #include <math.h> int main() { long double gardensize; long double cordlenth; long double s; cin >> gardensize >> cordlenth; if(gardensize*sqrt(2) <= 2*cordlenth) { s = pow(gardensize,2); printf("%.3f", s); } else if(gardensize < 2*cordlenth) { s = sqrt(pow(cordlenth,2) - (pow(gardensize,2)/4.00)) *gardensize*2; s = 3.1415926 * pow(cordlenth,2) - (4 * acos (gardensize/(2*cordlenth))*pow(cordlenth,2)) + s; printf("%.3f", s); } else if(gardensize >= 2*cordlenth) { s = 3.1415926 * cordlenth * cordlenth; printf("%.3f",s); } printf("\n"); return 0; } | | 2 admins ->> couldn't you ban people like ufx or at least delete their solutions ? It's really annoying when you see an AC program in discussion :(( | uuuuuuu | | 5 Apr 2003 22:54 | 2 | | | oh my god i use 32k | leozsu | 1068. Sum | 5 Apr 2003 22:21 | 1 | #include<iostream.h> void main() { int n,sum; cin>>n; if(n<=0){ sum=-n*(n-1)/2+1; }else{ sum=n*(n+1)/2; } cout<<sum<<"\n"; }
| | How to check wheter the necrologue's length is less than 1,000,000 without recursion or just not to get MLE ??? | uuuuuuu | 1253. Necrologues | 5 Apr 2003 20:37 | 8 | DFS modification works very good!: b[i] = 0 when this necrologue was not visited. = 1 when necrologue is beeing processed = 2 when necrologue was processed. TextLen[i] = Length of i-th necrologue. Text[i][j] - j-th letter of i-th necrologue. 1. b[i] = 0, TextLen[i] = 0; for all necrologues i. 2. We call DFS_Visit(1); 1. DFS_Visit(v) v - necrologue 2. b[v] = 1 We are processing this necro 3. TextLen[v] = 0 Just in case 4. Sequently for all character s = 1, 2, 3, ... 5. If this is character of necro. increase TextLen[v] by 1 6. If this is link to other necro (say u) then do next 7. If b[u] = 1 then we gone to a loop write answer and exit 8. If b[u] = 2 then we already processed necro u and we know TextLen[u], so we can increase TextLen[v] by TextLen[u]. 9. If b[u] = 0 then we call DFS_Visit(u) and if it returned increase TextLen[v] by TextLen[u]. 10. b[v] = 0; With each increase of TextLen we must check wether it becomes greater than 1 000 000 if so Stop execution. i just do the dfs and then i write the answer with the recursion... but always TLE var n:array[1..9,0..1001]of char; b:array[1..9]of byte; textlen:array[1..9]of longint; wypisane,ile:longint; procedure wczytaj; var i,k:longint; zn:char; zb:text; begin {assign(zb,'1253.in'); reset(zb);} readln({zb,}ile); for i:=1 to ile do begin k:=0; read({zb,}zn); while zn<>'#'do begin inc(k); n[i,k]:=zn; read({zb,}zn) end; inc(k); n[i,k]:='#'; readln{(zb)} end; {close(zb)} end; procedure dzialaj(x:longint); var i,kt:longint; zn:char; begin i:=1; zn:=n[x,i]; while zn<>'#'do begin if zn='*' then begin kt:=ord(n[x,i+1])-48; i:=i+2; dzialaj(kt) end else begin write(zn); inc(i) end; zn:=n[x,i]; end; end; procedure koniec; begin writeln('#'); halt end; procedure dfsvisit(v:byte); var zn:char; i:integer; begin b[v]:=1; i:=1; textlen[v]:=0; zn:=n[v,i]; while zn<>'#'do begin if ((ord(zn)-48)>0)and((ord(zn)-48)<10)and(n[v,i-1]='*')then begin if b[ord(zn)-48]=1 then begin writeln('#'); halt end else if b[ord(zn)-48]=2 then begin textlen[v]:=textlen[v]+textlen[ord(zn)-48]; if textlen[v]>1000000 then koniec end else if b[ord(zn)-48]=0 then begin dfsvisit(ord(zn)-48); textlen[v]:=textlen[v]+textlen[ord(zn)-48]; if textlen[v]>1000000 then koniec end; inc(i) end else if zn='*'then inc(i) else begin inc(textlen[v]); if textlen[v]>1000000 then koniec; inc(i) end; zn:=n[v,i] end; b[v]:=2; end; procedure dfs; begin fillchar(b,sizeof(b),0); fillchar(textlen,sizeof(textlen),0); dfsvisit(1) end; begin wczytaj; dfs; dzialaj(1); end. It's the "return symbol". In C/C++ "return symbol" is '\n', it is just 1 byte. But in Pascal "return symbol" is #13#10, it is 2 byte. My program made the same mistake as your :-) Good Luck! > It's the "return symbol". > In C/C++ "return symbol" is '\n', it is just 1 byte. > But in Pascal "return symbol" is #13#10, it is 2 byte. > > My program made the same mistake as your :-) > Good Luck! | | Can You explain the sample to me ?? | uuuuuuu | 1254. Die Hard | 5 Apr 2003 20:22 | 1 | I understand the problem like that : The first way is : J 1 0 0 # # 2 0 B 3 0 0 So the time needed is 3 * 1.23 = 3.69 The second : 0 0 0 B # # 2 0 J 1 0 0 Here the time 2 * 1.23 = 2.64 Total = 2.46 + 3.69 = 6.29 The third : 0 0 0 J # # 0 1 0 0 0 B time = 1.23 total = >>>> 7.52 <<<<< ????!!!!! the answer in the sample isn't even a multiple of v ??!!! WOuld You be so kind and explain it to me ?? | | Can anyone give me more test pls, it always WA | BoRN | 1200. Horns and Hoofs | 5 Apr 2003 12:18 | 1 | | | I got AC,here is my program | ufx | 1224. Spiral | 5 Apr 2003 08:17 | 1 | please int64 type or dword ,using longint is wrong. otherwise you will get a over data this is a math method you can prove it,or practise some examples and you will find the orderliness I like these problems ,if you have please send to me. my e-mail : zhuyin_222@hotmail.com // program ex; var a,b:int64; begin readln(a,b); if a<=b then writeln(2*(a-1)) else writeln(2*b-1); end. | | gymn28_Kostya | 1204. Idempotents | 4 Apr 2003 18:38 | 1 | gymn28_Kostya 4 Apr 2003 18:38 Please, Help me with problem #1204! Explane me task in russian, please (e-mail:"KonstantinSkr@Yandex.ru"). | | It's so easy!!!!!!!!!!!! | Krzysztof Drozdz | 1153. Supercomputer | 4 Apr 2003 17:48 | 2 | I won't tell Youu how to do it. But... I'll tell You that You don't need any arrays. Could you tell me your magical way to solve this problem? > I won't tell Youu how to do it. But... I'll tell You that You don't > need any arrays. | | Please, tell me! How solve Problem 1087... And please tell what's game is right... | Evgeny Reshetnikov | 1087. The Time to Take Stones | 4 Apr 2003 15:28 | 2 | In problem said what game is right... What's right game... How must play first if second gave any stones??? I am poor in english, so I can't express well. I try to use completely search, that is search from 0 to n. after getting all state . here is my ac code void computation(int n,int m) { int i,j; a[0]=1; for(i=1;i<=n;i++) { bool sign=false; for(j=1;j<=m;j++) if(i-b[j]>=0&&a[i-b[j]]==2) sign=true; if(sign) a[i]=1; else a[i]=2; } printf("%d\n",a[n]); // for(i=1;i<=n;i++) printf("%d ",a[i]); } | | the one who take the last stone is the failure | coldfeel | 1087. The Time to Take Stones | 4 Apr 2003 15:13 | 2 | you can try twice. one for failure and another for success. You will get it. | | Why TL? | Trofimov Dmitry | 1219. Symbolic Sequence | 4 Apr 2003 03:44 | 1 | Why TL? Trofimov Dmitry 4 Apr 2003 03:44 var i: longint; begin randomize; for i:=1 to 1000000 do write(chr(ord('a')+random(26))); end. | | Why my program got WA? | yellowgreen(*Jane*)^_^ | 1042. Central Heating | 3 Apr 2003 13:07 | 4 | #include<stdio.h> #include<string.h> #define max 251 int n,total,note[max][max],result[max]; void init() { int i,j,t; memset(note,0,sizeof(note)); scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d",&t); while(t!=-1) { note[t][i]=1;note[t][0]=1; scanf("%d",&t); } } } int judge() { int i; for(i=1;i<=n;i++) if(!note[i][0])return 1; return 0; } void change(int a,int b) { int i,temp[max]; for(i=1;i<=n;i++)temp[i]=note[a][i]; for(i=1;i<=n;i++)note[a][i]=note[b][i]; for(i=1;i<=n;i++)note[b][i]=temp[i]; } void find(int a,int s) { int i,j; for(i=s+1;i<=n;i++) if(note[i][a]) { note[i][0]=(note[i][0]+note[s][0])%2; for(j=1;j<=n;j++) note[i][j]=(note[i][j]+note[s][j])%2; } } void work() { int i,j,sum; if(judge()){total=1;return;}else total=0; for(i=1;i<=n;i++) { for(j=i;j<=n;j++)if(note[j][i])break; change(i,j); find(i,j); } for(i=n;i>0;i--) { if(!note[i][i]){total=1;return;} sum=note[i][0]; for(j=i+1;j<=n;j++)if(note[i][j])sum+=result[j]; result[i]=sum%2; } } void out() { int i,j; if(total)printf("No solution\n"); else { for(i=1;i<=n;i++) if(result[i])break; if(result[i])printf("%d",i); for(j=i+1;j<=n;j++) if(result[j]) printf(" %d",j); printf("\n"); } } int main() { init(); work(); out(); return 0; } #include<stdio.h> #include<string.h> #define max 300 int n,total,note[max][max],result[max]; void init() { int i,j,t; memset(note,0,sizeof(note)); scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d",&t); while(t!=-1) { note[t][i]=(note[t][i]+1)%2;note[t][0]=1; scanf("%d",&t); } } } int judge() { int i; for(i=1;i<=n;i++) if(!note[i][0])return 1; return 0; } void change(int a,int b) { int i,temp; for(i=1;i<=n;i++) { temp=note[a][i]; note[a][i]=note[b][i]; note[b][i]=temp; } } void find(int s) { int i,j; for(i=s+1;i<=n;i++) if(note[i][s]) { for(j=0;j<=n;j++) note[i][j]=(note[i][j]+note[s][j])%2; } } void work() { int i,j,sum; if(judge()){total=1;return;}else total=0; for(i=1;i<=n;i++) { for(j=i;j<=n;j++)if(note[j][i])break; change(i,j); find(i); } for(i=n;i>0;i--) { if(!note[i][i]){total=1;return;} sum=note[i][0]; for(j=i+1;j<=n;j++)if(note[i][j])sum+=result[j]; result[i]=sum%2; } } void out() { int i,j; if(total)printf("No solution\n"); else { for(i=1;i<=n;i++) if(result[i])break; if(result[i])printf("%d",i); for(j=i+1;j<=n;j++) if(result[j]) printf(" %d",j); printf("\n"); } } int main() { init(); work(); out(); return 0; } [code deleted] Edited by moderator 09.12.2019 18:47 [code deleted] Edited by moderator 09.12.2019 18:47 | | Anyone who have MSN, I'd like to make friends, &discuss problem! | Li Yao | | 3 Apr 2003 09:59 | 2 | write your MAN follow this, thanks! > write your MAN follow this, thanks! | | Why I got WA? | zealot | 1076. Trash | 3 Apr 2003 08:12 | 1 | My solution here: const max=160; var g:array[1..max,1..max] of integer; x,y:array[1..max] of boolean; link,lx,ly:array[1..max] of longint; n,num:longint; procedure readdata; var i,j:integer; begin readln(n); for i:=1 to n do begin for j:=1 to n-1 do read(g[i,j]); readln(g[i,n]); end; end; function find(i:integer):boolean; var k,p:integer; begin find:=true; x[i]:=true; for k:=1 to n do if not y[k] and (lx[i]+ly[k]=g[i,k]) then begin p:=link[k];link[k]:=i;y[k]:=true; if (p=0) or find(p) then exit; link[k]:=p; end; find:=false; end; procedure main; var i,j,d:integer; begin for i:=1 to n do for j:=1 to n do if g[i,j]>lx[i] then lx[i]:=g[i,j]; for i:=1 to n do repeat fillchar(x,sizeof(x),0);fillchar(y,sizeof(y),0); if find(i) then break; for i:=1 to n do if x[i] then for j:=1 to n do if not y[j] then if lx[i]+ly[j]-g[i,j]<d then d:=lx[i]+ly[j]-g[i,j]; for i:=1 to n do if x[i] then lx[i]:=lx[i]-d; for j:=1 to n do if y[j] then ly[j]:=ly[j]+d; until false; end; function did(a,b:integer):boolean; var k:integer; m:longint; begin k:=a;did:=false;m:=a; while k>1 do begin dec(k);m:=m*k; if m>b then exit; end; if m=b then did:=true; end; procedure print; var i,j:integer; begin for i:=1 to n do for j:=1 to n do if link[j]=i then else begin if (i>=link[j])or(i>=6) then num:=num+g[i,j] else if did(i,link[j]) then else num:=num+g[i,j]; end; writeln(num); end; BEGIN readdata; main; print; END. |
|
|