Common Board| Show all threads Hide all threads Show all messages Hide all messages | | to Cristopher Moh, Help 1143 (+) | Miguel Angel | | 28 Jun 2002 10:04 | 1 | Hi, i saw your comments, but i think that maybe i don't understand well, cause i'm getting WA. My idea was the same as you, except the way of keeping track of the movements. I save them as x[i][j], where "i" and "j" are the points of the right and left of a starting point "s", so "path starting at s" = min(c(s,r)+x[right(r)][l],c(s,l) +x[r][left(l)]). Here's my method: --------------------------------------------------------- double minPath(int r, int l, int dad) { if (r==l) { if (m[r][l] < 0) m[r][l] = c(dad, r); return m[r][l]; } if (m[r][l] < 0) { double right = c(dad, r) +minPath(prev(r), l, r); double left = c(dad, l) +minPath(r, next(l), l); if (right < left) m[r][l] = right; else m[r][l] = left; } return m[r][l]; } -------------------------------------------------------- I try to do the your's, but get WA. -------------------------------------------------------- for (l=1; l<n-1; l++) for (s=0; s<n; s++) { x[s][next(s,l)] = min( c(s,next(s,1)) + x[next(s,1)][next(s,l)], c(s,next(s,l)) + x[next(s,l)][next(s,1)]); x[s][prev(s,l)] = min( c(s,prev(s,1)) + x[prev(s,1)][prev(s,l)], c(s,prev(s,l)) + x[prev(s,l)][prev(s,1)]); } MIN = 0.0; for (s=0; s<n-1; s++) MIN += c(s,s+1); for (s=0; s<n; s++) { if ( c(s,next(s,1)) + x[next(s,1)][prev(s,1)]<MIN ) MIN = c(s,next(s,1)) + x[next(s,1)][prev(s,1)]; if ( c(s,prev(s,1)) + x[prev(s,1)][next(s,1)]<MIN ) MIN = c(s,prev(s,1)) + x[prev(s,1)][next(s,1)]; } I hope you can help me :). email: miguelangelhdz@hotmail.com | | To Christopher Moh or anyone who has solved problem 1143 with DP (+) | Miguel Angel | | 26 Jun 2002 22:27 | 2 | I think that idea is make DP over a something like a Binary Tree which is: function minPath(to_the_right, to_the_left, point):float; begin if to_the_right=to_the_left then begin mtx[to_the_right,to_the_left]=d(to_the_right,point); end if not processed(mtx[to_the_right,to_the_left]) then begin right_branch = d(point, to_the_right) + minPath(shift_right(to_the_right),to_the_left, right); left_branch = d(point, to_the_left) + minPath(to_the_right,shift_left(to_the_left), left); mtx[to_th_right,to_the_left]=min(right_branch,left_branch); end; return mtx[to_the_right,to_the_left]; end; I mean, the optimal route must not cross itself, so for that shift_right and shift_left functions. But I get WA, could anyone help me? Thanks... mail: miguelangelhdz@hotmail.com #include<iostream.h> #include<math.h> #include<stdio.h> #define MaxN 200 struct point { double x, y;}; int n; double m[MaxN][MaxN]; point p[MaxN]; double c(int a, int b) { double xx = (p[a].x-p[b].x)*(p[a].x-p[b].x); double yy = (p[a].y-p[b].y)*(p[a].y-p[b].y); return sqrt(xx + yy); } int next(int i) { if (i+1<n) return i+1; return 0; } int prev(int i) { if (i ==0) return n-1; return i-1; } double minPath(int r, int l, int dad) { if (r==l) { if (m[r][l] < 0) m[r][l] = c(dad, r); return m[r][l]; } if (m[r][l] < 0) { double right = c(dad, r) +minPath(prev(r), l, r); double left = c(dad, l) +minPath(r, next(l), l); if (right < left) m[r][l] = right; else m[r][l] = left; } return m[r][l]; } void main() { double min, tot; int i, j, k; cin >>n; for (i=0; i<n; i++) cin >>p[i].x >>p[i].y; min = 0.0; for (i=0; i<n-1; i++) min = min + c(i, i+1); for (j=0; j<n; j++) for (k=0; k<n; k++) m[j][k] = -1.0; for (i=0; i<n; i++) { tot = minPath(prev(i), next(i), i); if (tot < min) min = tot; } printf("%.3f", min); } My idea is as follows: Suppose we have computed a partial path a1, a2, a3, ... ai and we want to add the next point a(i+1) to this path. There can only be two points that should be considered for the next point to this path: The two points adjacent to a1 or ai (one adjacent to a1, the other adjacent to ai) that have not already been chosen in the path. Why? Because choosing any other point would lead at some point to the path crossing itself, because the polygon is convex (draw a diagram to convince yourself). Then the recurrence is as follows: Let x[a][b] be the weight of the best path starting at vertex a and ending at vertex b (b can be bigger => counterclockwise path, or a can be bigger => clockwise path). Below I assume that b >= a. x[a][b] = 0 if a == b. x[a][b] = distance(a,b) if b == a + 1. x[a][b] = MIN(x[a+1][b]+distance(a,a+1), x[b][a+1]+distance(a,b)) | | help me, disk tree | raxtinhac | 1067. Disk Tree | 26 Jun 2002 21:57 | 3 | Here is my program. It gets wrong answer const max1 = 500; max2 = 80; fi = 'disk.inp'; type xau = string[max2]; var a :array[0..max1] of xau; n :longint; f :text; procedure input; var i :longint; st :string; begin { assign(f, fi); reset(f);} readln({f,} n); for i := 1 to n do begin readln({f,} st); while st[1] = ' ' do delete(st,1,1); while st[ length(st) ] = ' ' do delete(st, length(st), 1); a[i] := st; end; { close(f);} end; function ma( t :char) :byte; begin if t = '\' then ma := 2 else ma := ord(t); end; function be(x,y :xau) :boolean; var i :longint; begin be := true; x := x + char(1); y := y + char(1); for i := 1 to length(x) do if x[i] <> y[i] then break; if ma(x[i]) < ma(y[i]) then exit; be := false; end; procedure doi(i,j :longint); var x :xau; begin x := a[i]; a[i] := a[j]; a[j] := x; end; procedure sort(l,r :longint); var i,j :longint; x :xau; begin i := l; j := r; x := a[ l + random(r-l+1) ]; repeat while be( a[i] , x ) do inc(i); while be( x , a[j] ) do dec(j); if i <= j then begin doi(i,j); inc(i); dec(j); end until i > j; if l < j then sort(l,j); if i < r then sort(i,r); end; procedure tim_cho_khac(i :longint; var k,bac :longint); var j :longint; begin a[i-1] := a[i-1] + char(1); bac := 0;k := 1; for j := 1 to length( a[i-1] ) do begin if a[i][j] = '\' then begin inc(bac); k := j+1; end; if a[i-1][j] <> a[i][j] then exit; end; end; procedure viet(x :xau; bac :longint) ; var i :longint; begin for i := 1 to bac do write(' '); writeln(x); end; procedure ghi(s :xau; k,bac :longint); var t,j :longint; x :xau; begin s := s + '\'; t := length(s); j := k; x := ''; while j <= t do begin if s[j] = '\' then begin viet( x, bac ); inc( bac ); x := ''; end else x := x + s[j]; inc(j); end; end; procedure out; var i,k,bac :longint; begin a[0] := ''; for i := 1 to n do begin tim_cho_khac(i,k,bac); ghi(a[i],k,bac); end; end; begin input; sort(1,n); out; end. this test you're wrong ( I think so ! ) 3 a\b a\b\c b\c\d
My answer is : a b c d your answer differs from me . for test 3 a\b a\b\c b\c\d wright answer is a b c b c d Andrey Popyk. > this test you're wrong ( I think so ! ) > 3 > a\b > a\b\c > b\c\d > > My answer is : > a > b > c > d > your answer differs from me . > > | | Please, help me!!! I get WA in simple problem 1020. I tried to submit this solve many times. But I always get WA! | [SPbSU ITMO] Yuri Bedny | | 25 Jun 2002 23:30 | 3 | #include <iostream.h> #include <math.h> struct tPt{double x,y;}p1,p2,fs; int n; double dx,dy,r,l; const double PI=3.141592; int main() { cin>>n>>r>>p1.x>>p1.y; fs=p1; l=2*PI*r; for (int i=1;i<n;i++) { cin>>p2.x>>p2.y; dx=p2.x-p1.x;dy=p2.y-p1.y; l+=sqrt(dx*dx+dy*dy); p1=p2; } if (n>1) { dx=p1.x-fs.x;dy=p1.y-fs.y; l+=sqrt(dx*dx+dy*dy); } cout.precision(2); cout<<l; return 0; } try this: l=3.00000 cout.precision(2); cout<<l; the result is 3 (not 3.00) that after using cout, use printf for output float and double with precision.
| | To administration of acm.timus.ru!!! | [SPbSU ITMO] Yuri Bedny | | 24 Jun 2002 21:57 | 1 | First of all I am sorry for my bad English. Please, answer what are the compilers you are use to compile our source? I don't understand why my solve's on C++ and Pascal very often get CE, but in my home computer it's succesfull work. I use Visual C++ 6.0 and Borland Delphi 6.0. I can't imagine any reason why you don't use last version's of this compilers. And at last: is it very difficult to publish information about compilers in FAQ? I think that it is very necessary!!! | | can you help me? | Cross | 1179. Numbers in Text | 24 Jun 2002 19:46 | 1 | how to do this ? i can't get answer it in time the text for 1MB is too big | | Why WA | Alabaster | 1094. E-screen | 24 Jun 2002 15:50 | 1 | Why WA Alabaster 24 Jun 2002 15:50 // E-screen #include <iostream.h> char screen[80]; int cur=0; void emulate() { char c; while (cin.get(c)) { if (c=='<' && cur>0) cur--; else if (c=='>') { if (cur<79) cur++; else cur=0; } else if (c!='\n' && c!='>' && c!='<') { screen[cur]=c; if (cur<79) cur++; else cur=0; } } for (cur=0; cur<80; cur++) if (screen[cur]!=NULL) cout << screen[cur]; cout << '\n'; } int main() { emulate(); return 0; } | | Why I can't submit my solution using e-mail ? | Orlov Dmitry | | 23 Jun 2002 21:21 | 1 | I submit my program to judge@acm.timus.ru, but it returns with "Unable to relay for judge@acm.timus.ru..." It seems like there are no adress judge@acm.timus.ru, isn't it ? | | CRASH !!! Please give me some test . I got a headache about it . My source along | Nguyen Viet Bang | 1037. Memory Management | 22 Jun 2002 15:58 | 1 | { memory management _ heap technique } CONST INP = '1037.in1'; OUT = '1037.out'; chk = '1037.ou2'; maxn = 30000 ; TYPE inttype = word ; ar1 = array[1..maxn] of inttype ; VAR posbheap,ctime,bheap,fheap : ^ar1 ; s : string ; pfheap,pbheap,btime,idblock : inttype ; PROCEDURE InputRead ; begin { assign (input,inp); reset(input); assign (output,out) ; rewrite (output) ;} end; PROCEDURE newVari ; begin new ( posbheap ) ; new (ctime ) ; new (bheap ) ; new (fheap ) ; end ; PROCEDURE d_Analyse ; var i : inttype ; b_code : inttype ; s1 : string ; begin i:=pos('+',s) ; if i <> 0 then begin while not (s[length(s)] in ['0'..'9'] ) do delete(s,length (s),1) ; val ( s , btime,b_code) ; idblock:=0 ; end else begin i:=pos ('.',s) ; s1:=copy ( s , 1,i-1) ; while not (s1[length(s1)] in ['0'..'9']) do delete ( s1,length (s1),1) ; val (s1 , btime,b_code) ; delete(s,1,i) ; while not (s[length(s)] in ['0'..'9'] ) do delete(s,length (s),1) ; while not (s[1] in ['0'..'9'] ) do delete(s,1,1) ; val (s,idblock , b_code ) ; end ; end ; PROCEDURE d_swap ( var a,b : inttype ) ; var tam : inttype ; begin tam:=a ; a:=b ; b:=tam ; end ; PROCEDURE fsiftup ( i : inttype ) ; var j : inttype ; begin while i*2 <= pfheap do begin if (i*2+1 <= pfheap) and (fheap^[i*2+1] < fheap^[i*2]) then j:=i*2+1 else j:=i*2 ; if fheap^[i] < fheap^[j] then exit else begin d_swap ( fheap^[i] , fheap^[j] ) ; i:=j ; end ; end ; end ; PROCEDURE bsiftup ( i : inttype ) ; var j : inttype ; begin while i*2 <= pbheap do begin if (i*2+1 <= pbheap) and (ctime^[bheap^[i*2+1]] < ctime^[ bheap^[i*2] ]) then j:=i*2+1 else j:=i*2 ; if ctime^[ bheap^[i] ] < ctime^ [ bheap^[j] ] then exit else begin d_swap ( bheap^[i] , bheap^[j] ) ; d_swap ( posbheap^ [ bheap^[i] ] , posbheap^[ bheap^ [j] ] ) ; i:=j ; end ; end ; end ; PROCEDURE fsiftdown ( i : inttype ) ; begin while i div 2 > 0 do begin if fheap^[i] < fheap^[i div 2] then begin d_swap (fheap^[i] , fheap^[i div 2]) ; i:=i div 2 ; end else exit ; end ; end ; PROCEDURE bsiftdown ( i : inttype ) ; begin while i div 2 > 0 do begin if ctime^[ bheap^[i] ] < ctime^ [ bheap^[i div 2] ] then begin d_swap (bheap^[i] , bheap^[i div 2]) ; d_swap (posbheap^ [ bheap^[i] ] , posbheap^ [ bheap^[i div 2] ]) ; i:=i div 2 ; end else exit ; end ; end ; PROCEDURE insertfheap ( d : inttype ) ; begin inc ( pfheap ) ; fheap^[pfheap ] := d; fsiftdown ( pfheap ) ; end ; PROCEDURE insertbheap ( d : inttype ) ; begin inc ( pbheap ) ; bheap^[pbheap ] := d; posbheap^[d]:=pbheap; bsiftdown ( pbheap ) ; end ; PROCEDURE deletefheap ( d : inttype ) ; var bufid : inttype ; begin bufid:=fheap^[d] ; d_swap ( fheap^[pfheap],fheap^[d] ) ; dec (pfhea | | Why does my program get WA? (code attached) | Alex[LSD] | 1019. Line Painting | 22 Jun 2002 12:12 | 1 | {A - is the array that stores white lines, visible at the moment} Program acm_1019; {the Line Painting} Type Lin = Record L,R: longint; End; Const MaxN=6000; Var A :array [1..maxN] of Lin; i,j,k,N :longint; c1,c :char; Cross :array [1..MaxN] of boolean; Function Cr(n1,n2:integer):boolean; Begin cr:=(((A[n1].L>=A[n2].L)and(A[n1].L<=A[n2].R))or ((A[n1].R>=A[n2].L)and(A[n1].R<=A[n2].R)) )or (((A[n2].L>=A[n1].L)and(A[n2].L<=A[n1].R))or ((A[n2].R>=A[n1].L)and(A[n2].R<=A[n1].R))); End; Procedure NewLine(L,R:longint; C:char); Var i,j,k,min,max :longint; Begin If c='b' then Begin For i:=1 to maxN do If (L>A[i].L)and(R<A[i].R) Then Begin k:=1; While A[k].L>=0 do Inc(k); A[k].R:=A[i].R; A[k].L:=R; A[i].R:=L; End Else Begin If (L<=A[i].L)and(R>=A[i].R) then Begin A[i].L:=-1; A[i].R:=-1; End; If (L>A[i].L)and(L<=A[i].R) Then A[i].R:=L; If (R>=A[i].L)and(R<A[i].R) Then A[i].L:=R; End End Else Begin k:=1; While A[k].L>=0 do Inc(k); A[k].L:=L; A[k].R:=R; Fillchar(Cross,sizeOf(Cross),0); For i:=1 to maxN do If cr(i,k) then Begin Cross[i]:=true; End; min:=1000000001; max:=0; For i:=1 to maxN do Begin If (cross[i])and(A[i].R>max) then Max:=A[i].R; If (cross[i])and(A[i].L<min) then Min:=A[i].L; End; A[k].L:=min; A[k].R:=max; Cross[k]:=false; For i:=1 to maxN do If cross[i] then A[i].L:=-1; End; End; Begin For i:=1 to 6000 do Begin A[i].L:=-1; A[i].R:=-1; End; A[1].L:=0; A[1].R:=1000000000; ReadLn(N); For i:=1 to N do Begin Read(j,k,c1,c); {c:=' '; While (c<>'b')or(c<>'w') do Read(c);} If j<k then NewLine(j,k,c); End; k:=0; j:=1; For i:=1 to maxN do If A[i].R-A[i].L+1>A[j].R-A[j].L+1 then j:=i; Writeln(A[j].L,' ',A[j].R); End. | | How to | Alabaster | 1194. Handshakes | 21 Jun 2002 23:38 | 1 | How to Alabaster 21 Jun 2002 23:38 You can solve this problem using simple expression of n and k. Other numbers are useless. | | To Rybak Michael: About Problem (+) | Miguel Angel | | 21 Jun 2002 07:58 | 5 | given a set of points (xi,yi) find a circle with less possible area covering each of these points I saw time ago that problem, i thought of the next algorithm: 1. Find the convex hull 2. Get the gravity's center of that convex hull, that will be the center of the minimal circle 3. from the center to all the points which make the convex hull, find the largest distance and that will be the radius. I think that center only will be x = avg(xi), y = avg(yi) since it's convex polygon. It's not so hard i think :). I only have doubts about the gravity's center, but is easy to prove that the problem above is equivalent to: Given a convex polygon, find the circle with minimal area which contains it. Since that convex polygon contains all the points of the set given, that circle contains all the points. Problem of finding circle with minimal radius, that contains set of points, can be solved in O(N) Emo Welzl randomized algorithm, and need not to build convex hull. Andrey Popyk. > Problem of finding circle with minimal radius, that contains set of > points, can be solved in O(N) Emo Welzl randomized algorithm, and > need not to build convex hull. > > Andrey Popyk. > And as I think, centroid doesn't work. Suppose we have 3 points with coordinates 0 0 0 10 10 0 Real center of our circle is (5.000 ; 5.000) Center of gravity of Convex Hull this set of points is (3.536 ; 3.536) Center of gravity of Convex Polygon contains this points is (3.333 ; 3.333) Center of gravity of this points is (3.333 ; 3.333) Which center of gravity we must to find if we want to solve mincircle problem? Andrey Popyk. popyk@ief.tup.km.ua > And as I think, centroid doesn't work. > > Suppose we have 3 points with coordinates > 0 0 > 0 10 > 10 0 > > Real center of our circle is (5.000 ; 5.000) > Center of gravity of Convex Hull this set of points is (3.536 ; 3.536) > Center of gravity of Convex Polygon contains this points is (3.333 ; > 3.333) > Center of gravity of this points is (3.333 ; 3.333) > > Which center of gravity we must to find if we want to solve mincircle > problem? > > Andrey Popyk. > popyk@ief.tup.km.ua > | | What is wrong in my program, I got WA. Please give me some test | hidden_u | 1099. Work Scheduling | 20 Jun 2002 12:48 | 2 | [deleted by moderator] Edited by moderator 11.04.2004 01:52 This is general graph matching, and you cannot find augmenting path in such way, that you use in bipartite graph matching. | | Give me some test, please!I got WA! | hidden_u | 1019. Line Painting | 19 Jun 2002 17:40 | 5 | const MAXN = 5005; type pointtype = record x:longint; y:integer; { b:byte;} end; var a:array[0..MAXN*2]of pointtype; b:array[1..MAXN]of byte; ccc:array[1..MAXN]of byte; s:array[1..MAXN]of integer; r:array[1..MAXN]of integer; N,i,h:integer;ch:char; col:byte; max,c,ai,bi,x,l:longint; procedure sort(l,r: integer); var i,j: integer;y:pointtype;x:longint; begin i:=l; j:=r; x:=a[(l+r) DIV 2].x; repeat while a[i].x<x do i:=i+1; while x<a[j].x do j:=j-1; if i<=j then begin y:=a[i]; a[i]:=a[j]; a[j]:=y; i:=i+1; j:=j-1; end; until i>j; if l<j then sort(l,j); if i<r then sort(i,r); end; procedure uph(k:integer); var v:integer; begin if 2*k+1<=h then begin if s[2*k+1]>s[2*k] then v:=2*k+1 else v:=2*k; if s[v]>s[k] then begin c:=s[v];s[v]:=s[k];s[k]:=c; r[s[v]]:=v;r[s[k]]:=k; if k div 2 <>0 then uph(k div 2); end; end else if 2*k<=h then begin v:=2*k; if s[v]>s[k] then begin c:=s[v];s[v]:=s[k];s[k]:=c; r[s[v]]:=v;r[s[k]]:=k; if k div 2 <>0 then uph(k div 2); end; end; end; procedure downh(k:integer); var v:integer; begin if 2*k+1<=h then begin if s[2*k+1]>s[2*k] then v:=2*k+1 else v:=2*k; if s[v]>s[k] then begin c:=s[v];s[v]:=s[k];s[k]:=c; r[s[v]]:=v;r[s[k]]:=k; downh(v); end; end else if 2*k<=h then begin v:=2*k; if s[v]>s[k] then begin c:=s[v];s[v]:=s[k];s[k]:=c; r[s[v]]:=v;r[s[k]]:=k; downh(v); end; end; end; begin { assign(input,'1019.dat');reset(input);} readln(N); for i:=1 to N do begin read(ai,bi);read(ch);read(ch);readln; a[2*i].x:=ai; a[2*i-1].x:=bi; a[2*i].y:=i; a[2*i-1].y:=i; if ch = 'b' then begin ccc[i]:=1; end else begin ccc[i]:=0; end; end; { inc(N); a[2*N].a:=0;a[2*N-1].a:=1000000000; a[2*N].b:=N;a[2*N-1].b:=N; a[2*N].c:=0;a[2*N-1].c:=0;} sort(1,2*N); x:=a[1].x;col:=0; max:=x; l:=0; for i:=1 to 2*N do begin if b[a[i].y]=0 then begin inc(h); r[a[i].y]:=h; s[h]:=a[i].y; if h div 2<>0 then uph(h div 2); b[a[i].y]:=1; end else begin s[r[a[i].y]]:=s[h];dec(h); downh(r[a[i].y]); r[a[i].y]:=0; end; if ccc[s[1]] = col then begin x:=x+a[i+1].x-a[i].x; if (col = 0)and(x>max) then begin max:=x; l:=a[i+1].x-x; end; end else begin if a[i+1].x-a[i].x<>0 then begin x:=a[i+1].x-a[i].x; col:=ccc[s[1]]; if (col = 0)and(x>max) then begin max:=x; l:=a[i+1].x-x; end; end; end; end; if 1000000000-a[2*n].x>max then begin max:=1000000000-a[2*n].x; l:=a[2*n].x; end; writeln(l,' ',l+max); end. look at this test 2 33 99 w 21 91 b your program prints 99 1000000000 but the answer obviously is 91 1000000000 good luck. const MAXN = 5005; type pointtype = record x:longint; y:integer; { b:byte;} end; var a:array[0..MAXN*2]of pointtype; b:array[1..MAXN]of integer; ccc:array[1..MAXN]of integer; s:array[1..MAXN]of integer; r:array[1..MAXN]of integer; N,i,h:integer;ch:char; col:integer; max,c,ai,bi,x,l:longint; procedure sort(l,r: integer); var i,j: integer;y:pointtype;x:longint; begin i:=l; j:=r; x:=a[(l+r) DIV 2].x; repeat while a[i].x<x do i:=i+1; while x<a[j].x do j:=j-1; if i<=j then begin y:=a[i]; a[i]:=a[j]; a[j]:=y; i:=i+1; j:=j-1; end; until i>j; if l<j then sort(l,j); if i<r then sort(i,r); end; procedure uph(k:integer); var v:integer; begin if 2*k+1<=h then begin if s[2*k+1]>s[2*k] then v:=2*k+1 else v:=2*k; if s[v]>s[k] then begin c:=s[v];s[v]:=s[k];s[k]:=c; r[s[v]]:=v;r[s[k]]:=k; if k div 2 <>0 then uph(k div 2); end; end else if 2*k<=h then begin v:=2*k; if s[v]>s[k] then begin c:=s[v];s[v]:=s[k];s[k]:=c; r[s[v]]:=v;r[s[k]]:=k; if k div 2 <>0 then uph(k div 2); end; end; end; procedure downh(k:integer); var v:integer; begin if 2*k+1<=h then begin if s[2*k+1]>s[2*k] then v:=2*k+1 else v:=2*k; if s[v]>s[k] then begin c:=s[v];s[v]:=s[k];s[k]:=c; r[s[v]]:=v;r[s[k]]:=k; downh(v); end; end else if 2*k<=h then begin v:=2*k; if s[v]>s[k] then begin c:=s[v];s[v]:=s[k];s[k]:=c; r[s[v]]:=v;r[s[k]]:=k; downh(v); end; end; end; begin readln(N); for i:=1 to N do begin read(ai,bi);read(ch);read(ch);readln; a[2*i].x:=ai; a[2*i-1].x:=bi; a[2*i].y:=i; a[2*i-1].y:=i; if ch = 'b' then begin ccc[i]:=1; end else begin ccc[i]:=0; end; end; { inc(N); a[2*N].a:=0;a[2*N-1].a:=1000000000; a[2*N].b:=N;a[2*N-1].b:=N; a[2*N].c:=0;a[2*N-1].c:=0;} sort(1,2*N); x:=a[1].x;col:=0; max:=x; l:=0; for i:=1 to 2*N-1 do begin if b[a[i].y]=0 then begin inc(h); r[a[i].y]:=h; s[h]:=a[i].y; if h div 2<>0 then uph(h div 2); b[a[i].y]:=1; end else begin s[r[a[i].y]]:=s[h];dec(h); downh(r[a[i].y]); r[a[i].y]:=0; end; if ccc[s[1]] = col then begin x:=x+a[i+1].x-a[i].x; if (col = 0)and(x>max) then begin max:=x; l:=a[i+1].x-x; end; end else begin if a[i+1].x-a[i].x<>0 then begin x:=a[i+1].x-a[i].x; col:=ccc[s[1]]; if (col = 0)and(x>max) then begin max:=x; l:=a[i+1].x-x; end; end; end; end; if 1000000000-a[2*n].x>max then begin max:=1000000000-a[2*n].x; l:=a[2*n].x; end; if col = 0 then begin x:=x+1000000000-a[2*n].x; if x>max then begin max:=x; l:=1000000000-x; end; end; writeln(l,' ',l+max); end. look at this test 10 1 999999999 b 234 543 w 26 345 w 522 5453 w 64 345 b 384 400 b 774 1000 w 888 999 b 777 888 b 1 10 b you print 999 1000000000 but the answer is 999 5453 good luck. | | What type in C++ like longint in Pascal? | [SPbSU ITMO] Yuri Bedny | | 19 Jun 2002 16:26 | 4 | Sorry, I mean in "like longint in Delphi",or like comp in Pascal. Comp EQU long double (maybe :-) > Sorry, I mean in "like longint in Delphi",or like comp in Pascal. > | | How to assign cin, cout to files in C++?? | [SPbSU ITMO] Yuri Bedny | | 19 Jun 2002 11:52 | 2 | #include <fstream.h> int main() { ifstream in("1.dat"); cin=in; ofstream out=("1.sol"); cout=out; .... return 0; } P.S. But in online judge fstream.h maybe not present. | | Another prayer for help | Toshke | 1036. Lucky Tickets | 19 Jun 2002 02:27 | 1 | Reason is of course WA Here 's my code. My solution differs much from the other solutions because I count the matrix kolko with DFS. Thus it is obvius that it's faster but the memory is going over the limit so I had to use one byte for two digits. Then I copy the result into the variable result which has 100 bytes and square it. I would be very grateful if someone could see the error. Thanks, Toshke type vbroj = array [0..30] of byte; vbroj1 = array [0..100] of byte; var n, s, i, j: longint; kolko: array [0..50,0..450] of vbroj; mark: array [0..50, 0..450] of boolean; result: vbroj1; function max(a, b: longint): longint; begin if a > b then max := a else max := b; end; procedure saberi(var a, b: vbroj); var pamti: longint; begin b[0] := max(a[0], b[0])+1; pamti := 0; for i := 1 to b[0] do begin b[i] := a[i] + b[i] + pamti; pamti := b[i] div 100; b[i] := b[i] mod 100; end; if b[b[0]] = 0 then dec(b[0]); end; procedure pomnozi(var a, b: vbroj1); var c: vbroj1; i, j, k: longint; begin if a[0] = 0 then a[0] := 1; if b[0] = 0 then b[0] := 1; fillchar(c, sizeof(c), 0); for i := 1 to a[0] do for j := 1 to b[0] do begin k := a[i]*b[j]; c[i+j-1] := c[i+j-1] + k mod 100; c[i+j] := c[i+j] + k div 100; end; c[0] := a[0] + b[0]; for i := 1 to c[0]+1 do begin c[i+1] := c[i+1] + (c[i] div 100); c[i] := c[i] mod 100; end; while (c[c[0]] = 0) and (c[0] > 1) do dec(c[0]); b := c; end; procedure izracunaj(brc, suma: longint); var s1, i: longint; begin if not mark[brc,suma] then begin for i := 0 to 9 do begin s1 := suma - i; if s1 >= 0 then begin izracunaj(brc-1,s1); saberi(kolko[brc-1,s1], kolko[brc,suma]); end; end; end; mark[brc,suma] := true; end; procedure ispisi(x: vbroj1); var i: longint; begin if x[0] = 0 then x[0] := 1; for i := x[0] downto 1 do begin if (x[i] < 10) and (x[0] <> i) then write('0'); write(x[i]); end; writeln; end; begin read(n, s); fillchar(kolko, sizeof(kolko), 0); fillchar(mark, sizeof(mark), false); kolko[0,0][0] := 1; kolko[0,0][1] := 1; for i := 0 to 450 do mark[0,i] := true; if s mod 2 = 0 then izracunaj(n ,s div 2); for i := 0 to 30 do result[i] := kolko[n,s div 2][i]; pomnozi(result, result); ispisi(result); end. | | I've got WA on 1003. Somebody give me some good test... | earthman | 1003. Parity | 18 Jun 2002 17:23 | 4 | MY CODE: #include <iostream.h> #define maxN 5005 int i,Len,N; int mn[maxN]; int L[maxN]; int R[maxN]; int pL[maxN]; int pR[maxN]; void search(int l,int r,int &il,int &ir,int &pl,int &pr){ int j; il = ir = -1; for(j = 0;j < i;j++){ if(r + 1 == L[j]){ ir = j; pr = pL[j]; break; } } for(j = 0;j < i;j++){ if(l == R[j] + 1){ il = j; pl = pR[j]; break; } } for(j = 0;j < i;j++){ if(r == R[j]){ ir = j; pr = pR[j]; break; } } for(j = 0;j < i;j++){ if(l == L[j]){ il = j; pl = pL[j]; break; } } } int findroot(int k){ if(mn[k] == -1)return -1; if(mn[k] == k)return k; int l = findroot(mn[k]); mn[k] = l; return l; } int add(int a,int b,int c){ int pl,pr,il,ir; L[i] = a; R[i] = b; search(a,b,il,ir,pl,pr); if(il == -1 && ir == -1){ pL[i] = 0; pR[i] = c; mn[i] = i; } if(il != -1 && ir == -1){ int rl = findroot(il); mn[i] = rl; pL[i] = pl; pR[i] = (pL[i] + c) % 2; } if(il == -1 && ir != -1){ int rr = findroot(ir); mn[i] = rr; pR[i] = pr; pL[i] = (pR[i] - c + 2) % 2; } if(il != -1 && ir != -1){ int rl = findroot(il); int rr = findroot(ir); mn[i] = rl; if(rl == rr){ if(((pl + c) % 2) != (pr % 2)){ return 0; } }else{ pL[i] = pl; pR[i] = (pL[i] + c) % 2; if(pr != pR[i]) for(int k = 0;k < i;k++) if(findroot(k) == rr)pR[k] = (pR[k] + 1) % 2,pL[k] = (pL[k] + 1) % 2; int o = findroot(ir); mn[o] = i; } } return 1; } void main(void){ for(;;){ cin >> Len; if(Len == -1)break; cin >> N; int bad = 0; for(i = 0;i < N;i++){ mn[i] = -1; int a,b;char k[10]; cin >> a >> b >> k; // FOR debug reasons only... // if(a == -1){cout << "Wrong input";return;} // if(b == -1){cout << "Wrong input";return;} if(!add(a,b,(k[0] == 'e') ? 0 : 1)){ cout << i << "\n"; bad = 1; for(i++;i < N;i++) cin >> a >> b >> k; break; } } if(!bad)cout << N << "\n"; } } i know that this task from CEOI 99 but i don't want to see sol. and theier test, because in that case it is a cheat :-) But you can find your mistake! And if I send you this test, is it cheat? :-) > i know that this task from CEOI 99 but i don't want to see sol. and > theier test, because in that case it is a cheat :-) | | Someone could help me :| with this problem...(+) | Miguel Angel | 1144. The Emperor's Riddle | 18 Jun 2002 08:00 | 1 | Email: miguelangelhdz@hotmail.com thanks :) | | Why WA?Help me,please!Give me some tests! | Aleksandr Panteleimonov | 1011. Conductors | 17 Jun 2002 17:50 | 2 | var p,q:real; j:longint; i:longint; begin readln(p,q); if (p>50)and(q>50) then begin q:=100-p; p:=100-q; end; for j:=1 to 20000 do begin i:=round(j/q*100); if (i*p/100<j)and(i*q/100>j) then begin writeln(i); halt; end; end end. |
|
|