Общий форум| Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения | | I don't know how to solve it. | Sun-ho, Cho | 1115. Корабли | 31 дек 2001 09:29 | 6 | I don't know how to solve this problem. Give me some hints please. Happy new year. If you want more details,you can email to "hyz12345678@163.com". It is a "multi-knapsack", which is proved to be NP. So, use recursion with some optimizations. (NP = Non Polynomial) -> that means that there is no efficient algorithm (well, not exactly that, but almost the same in this case) > Could you help me?? mail:miguelangelhdz@hotmail.com, or here, i did it, but get time limit exced :| | | P1007(Code words).Please help | mih | 1007. Кодовые слова | 31 дек 2001 01:12 | 1 | what's wrong with this code: #include<iostream.h> #include<string.h> #define MAXN 1006 void solve(); void outp(int a[MAXN]); int N; int main(){ cin>>N; while(cin&&!cin.eof()) solve(); return 0; } void solve(){ int a[MAXN]; char s[MAXN]; int kvo1=0,sum=0,pos=1; cin>>s; int len=strlen(s); for(int i=0;i<len;i++){ if(s[i]=='1') sum+=pos,kvo1++; a[pos-1]=s[i]-'0'; pos++; } if(pos==(N+1)){ if(sum%(N+1)==0){ outp(a); return; } for(int i=0;i<pos;i++) if(a[i]) if((sum-i-1)%(N+1)==0){ a[i]=0; outp(a); return; } } if(pos==N){ int pass=0; for(int i=0;i<=pos;i++){ if((sum+kvo1-pass)%(N+1)==0){ for(int j=pos-1;j>i;j--) a[j]=a[j-1]; a[i]=0; outp(a); return; } if((sum+kvo1-pass+i+1)%(N+1)==0){ for(int j=pos-1;j>i;j--) a[j]=a[j-1]; a[i]=1; outp(a); return; } if(a[i]) pass++; } } if(pos==N+2){ int pass=0; for(int i=0;i<=pos;i++){ if(a[i]){ pass++; if((sum-kvo1+pass-i-1)%(N+1)==0){ for(int j=i;j<=pos;j++) a[j]=a[j+1]; outp(a); return; } } if(!a[i]){ if((sum-kvo1+pass)%(N+1)==0){ for(int j=i;j<=pos;j++) a[j]=a[j+1]; outp(a); return; } } } } } void outp(int a[MAXN]){ for(int i=0;i<N;i++) cout<<a[i]; cout<<"\n"; } | | What is the answer if N=0? ( problem 1149 sinus dances ) | Tomasz Klos | | 30 дек 2001 06:49 | 3 | my accepted program outputs +0)+1 but I do not think that there is such test > my accepted program outputs +0)+1 > but I do not think that there is such test | | What's wrong with my program? Please,help me!!! | Revenger and NSC | 1070. Местное время | 29 дек 2001 18:12 | 1 | My code: program t1070;{$N+} var t1,t2,o1,o2 :extended; Str :string; i,j :integer; procedure makeIt(var x1,x2:extended;S:string); var y1,y2,i :integer; sr :string; begin i:=0; while s[i+1]=' ' do i:=i+1; sr:='';sr:=sr+s[i+1];sr:=sr+s[i+2]; val(sr,y1,i); sr:='';sr:=sr+s[i+4];sr:=sr+s[i+5]; val(sr,y2,i); x1:=y1+y2/60; i:=i+6; while s[i+1]=' ' do i:=i+1; sr:='';sr:=sr+s[i+1];sr:=sr+s[i+2]; val(sr,y1,i); sr:='';sr:=sr+s[i+4];sr:=sr+s[i+5]; val(sr,y2,i); x2:=y1+y2/60; end; Function Time(t1,t2,r:extended):extended; var r1,r2 :extended; begin r1:=t1; r2:=t2+r; if r1>r2 then r2:=r2+24; time:=r2-r1; end; begin Readln(Str);makeIt(t1,t2,str); Readln(Str);makeIt(o1,o2,str); for j:=0 to 5 do for i:=-j to j do begin if abs(time(t1,t2,i)-time(o1,o2,-i))<0.2666667 then begin writeln(abs(i)); halt(0); end; end; end. | | How to solve P1004? When I ran it in my own computer, it was right.But When I submit it, it says that "Access_violation" | Nancy | 1004. Экскурсия | 29 дек 2001 16:52 | 1 | | | I wonder why the inputs don't have linebreaks,it let me get WA several times. | Huang Yizheng | 1129. Покраска дверей | 29 дек 2001 13:35 | 1 | | | Mmm,it's a very interesting problem.(Email:hyz12345678@163.com) | Huang Yizheng | 1125. Классики | 29 дек 2001 12:56 | 6 | Why you keep asking people sending email to you are you asking something/barter with samething. If you really want to help people just answer directly people question directly here in this webboard. We are all learning here, do not play politic/monkey business here. I am impressed with the way Rybak, abc, xyz, Revenger etc helping each other here. They keep update their knowledge by help each other I also notice thay Huang Yizeng's program need to be improved. He still using GOTO in his program. This is not aligned with 'structure programming' concept, difficult to debug during the contest. ~timus observer | | Thanks for abc's help,I improved my program got accepted in 0.03sec. | Huang Yizheng | 1170. Desert | 29 дек 2001 12:43 | 1 | | | Can I use loop from biger number to less number until find the prime number, else print the least trivial number that find. How is the input to make me wrong answer??? | Badd | 1118. Нетривиальные числа | 28 дек 2001 21:56 | 2 | Maybe you didn't think of those cases where lower number is 1? For any test like this: 1 k The answer of your program should be 1. Hope this will help. Good luck! | | Why I get WA? Pelase, help me!!!!!!! | Revenger and NSC | 1133. Последовательность Фибоначчи | 28 дек 2001 20:56 | 2 | my code: Program t1133; Type Fib=record i,Fi :longint end; Var a,b,c,p :fib; i,j,n :longint; l1,l2 :longint; n1,n2,cur :longint; p3,p2,p1 :longint; begin read(a.i,a.fi); read(b.i,b.fi); read(n); if a.i<b.i then begin c:=a; a:=b; b:=c; end; l1:=1; l2:=1; if a.i-b.i>1 then for i:=a.i-2 downto b.i+1 do begin n1:=l1+l2; n2:=l1; l1:=n1; l2:=n2; end; if a.i-b.i>1 then begin p.i:=b.i+1; p.fi:=(a.fi-l2*b.fi) div l1; end else p:=a; if p.i=n then cur:=p.fi else if b.i=n then cur:=b.fi else if a.i=n then cur:=a.fi else if p.i<n then begin p1:=b.fi; p2:=p.fi; for i:=p.i+1 to n do begin p3:=p2+p1; l1:=p2; p2:=p3; p1:=l1; end; cur:=p3; end else if b.i>n then begin p3:=p.fi; p2:=b.fi; for i:=b.i-1 downto n do begin p1:=p3-p2; l1:=p2; p2:=p1; p3:=l1; end; cur:=p1; end; writeln(cur); end. [code deleted] Edited by moderator 20.11.2019 23:18 | | Help! | sillyboy | | 28 дек 2001 19:48 | 2 | Help! sillyboy 28 дек 2001 13:01 Could anybody tell me where p1063 is? {Maybe this is not exact code, but very near to it} Program P1063; Begin Writeln(0); Writeln(0); End. | | Anybody who wants any help on this problem can email to "hyz12345678@163.com". | Huang Yizheng | 1167. Bicolored Horses | 28 дек 2001 16:07 | 5 | hi could you give me some hints on this ques i've got an inefficient n^3 soln tt always tle thanks > hi > could you give me some hints on this ques > i've got an inefficient n^3 soln tt always tle > > thanks Can anyone give me solution which isn't in n^3 time? Alexandar Can anyone give me solution which isn't in n^3 time? Alexandar | | I have to clarificate that I never use "goto" in my program or it's not mine. | Huang Yizheng | 1125. Классики | 28 дек 2001 07:15 | 1 | | | I still cant get a/c | Alyosha Popovich | 1093. Дартс | 28 дек 2001 00:23 | 1 | still cant get that program in the prev. message to work. If anyone has got time to halp me, please mail me at scythe@toughguy.net Thnak you in advance. | | Important! | Nijino Saki | 1048. Сверхдлинные суммы | 27 дек 2001 23:38 | 3 | Note that you mustn't add an Enter to the end of the Output, or you will receive an "Output limit exceeded" error like me!!!!!!!!!!!!!!! > Note that you mustn't add an Enter to the end of the > Output, or you will receive an "Output limit exceeded" > error like me!!!!!!!!!!!!!!! i don't think so. i used.and i got accepted! i got ac 2 with a \n at the end of the line > Note that you mustn't add an Enter to the end of the > Output, or you will receive an "Output limit exceeded" > error like me!!!!!!!!!!!!!!! | | Why do I get wrong answer? What is wrong? | Michael Medvedev | 1029. Министерство | 27 дек 2001 18:01 | 2 | program p1029; const height = 100; width = 500; var m,n,i,j,k,l,ind:integer; s,t,tr,tl:array[1..width] of longint; mn:longint; res:array[1..height,1..width] of 0..2; rl,rr:array[1..width] of 0..2; answer:array[1..height*width] of 0..2; function min(a,b:longint):longint; begin if (a < b) then min := a else min := b; end; begin readln(m,n); for i:=1 to n do begin read(s[i]); res[1][i] := 0; end; for i:=1 to height do for j:=1 to width do res[i][j] := 0; for i:=2 to m do begin for j:=1 to n do read(t[j]); tl[1] := s[1]+t[1]; rl[1] := 0; for j:=2 to n do begin if s[j] < tl[j-1] then begin tl[j] := s[j] + t[j]; rl[j] :=0; end else begin tl[j] := tl[j-1] + t[j]; rl[j] := 1; end; end; tr[n] := s[n]+t[n]; rr[n] := 0; for j:=1 to n-1 do begin if s[n-j] < tr[n-j+1] then begin tr[n-j] := s[n-j] + t[n-j]; rr [n-j] := 0; end else begin tr[n-j] := tr[n-j+1] + t[n-j]; rr[n-j] := 2; end; end; for j:=1 to n do begin s[j] := min(tl[j],tr[j]); if (tl[j] < tr[j]) then res[i][j] := rl[j] else res[i][j] := rr [j]; end; end; mn := 2000000000; for j:=1 to n do if (s[j] < mn) then begin mn := s[j]; ind := j; end; i:=height; k:=1; while(i >= 1) do begin answer[k] := ind; Inc(k); if (res[i][ind] <> 0) then if (res[i][ind] = 2) then Inc(ind) else Dec(ind) else Dec(i); end; for i:=1 to k-1 do writeln(answer[k-i]); end. > program p1029; > const height = 100; > width = 500; > var m,n,i,j,k,l,ind:integer; > s,t,tr,tl:array[1..width] of longint; > mn:longint; > res:array[1..height,1..width] of 0..2; > rl,rr:array[1..width] of 0..2; > answer:array[1..height*width] of 0..2; > > function min(a,b:longint):longint; > begin > if (a < b) then min := a else min := b; > end; > > begin > readln(m,n); > for i:=1 to n do begin read(s[i]); res[1][i] := 0; end; > for i:=1 to height do for j:=1 to width do res[i][j] := 0; > > for i:=2 to m do > begin > for j:=1 to n do read(t[j]); > tl[1] := s[1]+t[1]; rl[1] := 0; > for j:=2 to n do > begin > if s[j] < tl[j-1] then begin tl[j] := s[j] + t[j]; rl[j] :=0; > end > else begin tl[j] := tl[j-1] + t[j]; rl [j] := > 1; end; > end; > tr[n] := s[n]+t[n]; rr[n] := 0; > for j:=1 to n-1 do > begin > if s[n-j] < tr[n-j+1] then begin tr[n-j] := s[n-j] + t[n-j]; rr > [n-j] := 0; end > else begin tr[n-j] := tr[n-j+1] + t[n- j]; > rr[n-j] := 2; end; > end; > for j:=1 to n do > begin > s[j] := min(tl[j],tr[j]); > if (tl[j] < tr[j]) then res[i][j] := rl[j] else res[i][j] := rr > [j]; > end; > end; > > mn := 2000000000; > for j:=1 to n do > if (s[j] < mn) then begin mn := s[j]; ind := j; end; > > i:=height; k:=1; > while(i >= 1) do > begin > answer[k] := ind; Inc(k); > if (res[i][ind] <> 0) then > if (res[i][ind] = 2) then Inc(ind) else Dec(ind) > else Dec(i); > end; > for i:=1 to k-1 do writeln(answer[k-i]); > end. > I think that your program is rigth. But you get WA. Look at this AC program.(May be you'll find bug in your's ) type TBestPath = array [1..25000] of Word; var i, j, n, m, x: LongInt; BestDirection: array [1..100, 1..500] of ShortInt; BestFloor: array [1..500] of LongInt; CurrentFloor: array [1..500] of LongInt; PBestPath: ^TBestPath; BEGIN FillChar(BestDirection, SizeOf(BestDirection), 0); FillChar(BestFloor, SizeOf(BestFloor), 0); Readln( m, n); for i:=1 to m do begin for j:=1 to n do begin Read( CurrentFloor[j]); Inc(BestFloor[j], CurrentFloor[j]); if (BestFloor[j]>1000000000) then BestFloor[j] := 1000000001; end; Readln; for j:=2 to n do if (BestFloor[j-1]+CurrentFloor[j] < BestFloor[j]) then begin BestFloor[j] := BestFloor[j-1] + CurrentFloor[j]; BestDirection[i,j] := -1; end; for j:=n-1 downto 1 do if (BestFloor[j+1]+CurrentFloor[j] < BestFloor[j]) then begin BestFloor[j] := BestFloor[j+1] + CurrentFloor [j]; BestDirection[i,j] := 1; end; end; j := 1; for i:=2 to n do if (BestFloor[i] < BestFloor[j]) then j := i; i := m; x := 0; New(PBestPath); while (i>=1) do begin Inc(x); PBestPath^[x] := j; if (BestDirection[i, j] = 0) then Dec(i) else if (BestDirection[i, j] = -1) then Dec(j) else Inc(j); end; for i:=x downto 1 do Writeln(PBestPath^[i]); Dispose(PBestPath); END. P.S. Please, help me with problem 1132. My e-mail: nsc2001@ramble | | Anybody who have difficulty in this problem can email to "hyz12345678@163.com". | Huang Yizheng | 1153. Суперкомпьютер | 27 дек 2001 15:16 | 2 | | | This problem is tricky,but not difficult.(Email:hyz12345678@163.com) | Huang Yizheng | 1108. Наследство | 27 дек 2001 10:47 | 1 | | | Could somebody help me? | AOY++ | 1148. Building Towers | 27 дек 2001 09:21 | 4 | I am really puzzled about this problem. My alogrithm was too bad and it got Time Limit Exceed using over 800KB memory! And I don't know how to solve it within less than 0.1sec. I wonder if there is a formula, or some good ways to solve this problem. Could someone give me some hints about this problem? Thanks! [deleted by moderator] Edited by moderator 11.04.2004 01:31 I can't understand, what is "InputFile='1148.in'"??? Did you read the rules? You must read information by the KEYBOARD!!! > I can't understand, what is "InputFile='1148.in'"??? Did you read > the rules? You must read information by the KEYBOARD!!! | | Why I get WA? Pelase, help me!!!!!!! | Revenger and NSC | 1127. Кубики | 27 дек 2001 01:57 | 1 | My program: Program t1127; Const P:array[1..24,1..6]of integer= {all combinations} ( (6,4,3,1,5,2), (3,5,4,1,6,2), (4,6,5,1,3,2), (5,3,6,1,4,2), (6,4,5,2,3,1), (3,5,6,2,4,1), (4,6,3,2,5,1), (5,3,4,2,6,1), (1,2,6,3,4,5), (6,4,2,3,1,5), (2,1,4,3,6,5), (4,6,1,3,2,5), (1,2,4,5,6,3), (6,4,1,5,2,3), (2,1,6,5,4,3), (4,6,2,5,1,3), (1,2,3,4,5,6), (3,5,2,4,1,6), (2,1,5,4,3,6), (5,3,1,4,2,6), (1,2,5,6,3,4), (3,5,1,6,2,4), (2,1,3,6,5,4), (5,3,2,6,1,4) ); MaxN=1000; Var Cube :array[1..MaxN,1..6]of char; Tmp :array[1..6]of char; ACube :array[1..MaxN,1..24]of string[4]; yet :array[1..MaxN,1..24]of boolean; N,i,j,k :integer; max,ik,jk :integer; m :integer; ch :char; begin Read(n); for i:=1 to N do for j:=1 to 6 do begin read(ch); while (ch=#10)or(ch=#13)or(ch=#32) do read(ch); Cube[i,j]:=ch; end; for i:=1 to N do for j:=1 to 24 do begin for k:=1 to 6 do tmp[k]:=cube[i,p[j,k]]; ACube[i,j]:=''; ACube[i,j]:=tmp[1]+tmp[2]+tmp[3]+tmp[4]; end; m:=0; for i:=1 to N do for j:=1 to 24 do yet[i,j]:=true; for i:=1 to N do for j:=1 to 24 do if yet[i,j] then begin yet[i,j]:=false; max:=1; for ik:=1 to N do if ik<>i then for jk:=1 to 24 do if ((acube[i,j][1]=acube[ik,jk][1])and(acube[i,j][4]=acube[ik,jk] [4]))or ((acube[i,j][1]=acube[ik,jk][4])and(acube[i,j][4]=acube[ik,jk] [1])) then if ((acube[i,j][2]=acube[ik,jk][2])and(acube[i,j][3]=acube[ik,jk] [3]))or ((acube[i,j][2]=acube[ik,jk][3])and(acube[i,j][3]=acube[ik,jk] [2])) then begin yet[ik,jk]:=false; max:=max+1; break; end; if max>m then m:=max; end; writeln(m); end. |
|
|