Common Board| Show all threads Hide all threads Show all messages Hide all messages | | Re: It's not a NP problem, my algorithm is O(n) - I have answers to all your questions :) 26 Dec 2001 08:04 | Zhou Yuan | 1171. Lost in Space | 7 Aug 2002 15:38 | 1 | Could you tell me the algorithm? my email is : smzyjsj1@mail.wh.ah163.net | | IMPORTANT FOR ALL SOLVERS OF THE PROBLEM | Victor Costan | 1093. Darts | 7 Aug 2002 13:35 | 1 | A person knowing elementary physics may think that, if the dart touches the board, it gets stuck in it. Well, the one that wrote this problem failed to consider this: you'll usually get an equation depeding of t^2. If it has two positive solutions, you must report "HIT", if for any of them the dart is inside the board. I got stuck with this for 3 days - if I had two positive solutions, I only checked for the smaller one, and considered the dart stays there (reality check!!)... well, looks like the dart can very well get through the board, and then get back in it. | | I got WA !!! Look trought my code and tell me what's wrong in it !!! PLEASE!!! (PROBLEM 1018) | Romanchik Vitaly | | 6 Aug 2002 02:39 | 1 | var a:array[1..100,1..100]of longint; n,q:longint; b:array[1..10000]of longint; c:array[1..10000]of longint; noch,koch,i,ch1,ch2,s:longint; d:array[1..10000]of longint; function find:longint; var i:longint; max:longint; begin max:=0; while noch<=koch do begin for i:=1 to n do if a[b[noch],i]<>0 then begin inc(koch); b[koch]:=i; c[koch]:=c[noch]+a[b[noch],i]; d[koch]:=d[noch]+1; a[b[noch],i]:=0; a[i,b[noch]]:=0; if (d[koch]=q)and(c[koch]>max)then max:=c[koch]; if d[koch]>q then break; end; inc(noch); end; find:=max; end; begin readln(n,q); for i:=1 to n-1 do begin readln(ch1,ch2,s); a[ch1,ch2]:=s; a[ch2,ch1]:=s; end; noch:=1;koch:=1; b[koch]:=1; writeln(find); end. | | help!help!help! problem#1021 | Alexey | | 5 Aug 2002 17:11 | 1 | Compilation Error PROBLEM3 1021 program ViniT; var a,b:array[1..10000]of integer; u,i,j,n,k:integer; o:boolean; procedure swap(var a,b:integer); var t:integer; begin t:=a; a:=b; b:=t; end; procedure qsort(m,l:integer); var i,j,k:integer; begin k:=a[(m+l)div 2]; i:=m;j:=l; repeat while a[i]<k do inc(i); while a[j]>k do dec(j); if i<=j then begin swap(a[i],a[j]);dec(j);inc(i);end; until i>j; if m<j then qsort(m,j); if l>i then qsort(i,l); end; procedure init; begin read(n); for i:=1 to n do read(a[i]); read(k); for i:=1 to k do read(b[i]); qsort(1,n); end; function find(m,l:integer):boolean; var k:integer; begin if m=l then find:=u+a[m]=10000 else begin k:=(m+l)div 2; if u+a[k]<10000 then find:=find(k+1,l) else if u+a[k]>10000 then find:=find(m,k-1) else find:=true; end; end; procedure solve; begin o:=false; for i:=1 to k do begin u:=b[i]; o:=find(1,n); if o then i:=k; end; end; procedure print; begin if o then write('YES')else write('NO'); end; begin init; solve; print; end. | | Who can help me with my codes? | Dick162 | 1106. Two Teams | 4 Aug 2002 12:39 | 1 | program ex; const max=100; var j,st,z,ch,n,i:integer; gh:array[1..max,1..max]of boolean; flag:boolean; ans:array[1..max]of integer; begin z:=1; fillchar(gh,sizeof(gh),false); { assign(input,'d:\input.txt'); reset(input);} readln(n); for i:=1 to n do begin read(ch); if ch=0 then begin writeln(0); halt; end; while ch<>0 do begin gh[i,ch]:=true; gh[ch,i]:=true; read(ch); end; readln; end; { close(input);} st:=1; ans[z]:=st; flag:=true; while st<n do begin j:=st+1; while gh[st,j]=true do j:=j+1; if j>n then break; z:=z+1; ans[z]:=j; st:=j; end; writeln(z); for i:=1 to z do write(ans[i],' '); writeln; end. | | Who used this ID? | earthworm | | 3 Aug 2002 07:50 | 4 | What happened with this ID's submissions and the problem 1188 :-/
> What happened with this ID's submissions and the problem 1188 :-/ > > But why only this ID ?? There must be at least one more >:) > > What happened with this ID's submissions and the problem 1188 :- / > > > > > But why only this ID ?? There must be at least one more >:) > > > What happened with this ID's submissions and the problem 1188 :- > / > > > > > > | | what is wrong ? | evil | 1023. Buttons | 3 Aug 2002 03:18 | 3 | #include <iostream.h> #include <math.h> void main() { float k; long i,l; cin>>k; {l=int(k)-1; for(i=2;i<=sqrt(k)+4;i++) if ((k/i==int(k/i))&& (i>=3) ){l=i- 1;break;}; cout<<l;}; } always get wrong answer > #include <iostream.h> > #include <math.h> > void main() > { float k; > long i,l; > cin>>k; > {l=int(k)-1; > for(i=2;i<=sqrt(k)+4;i++) if ((k/i==int(k/i))&& (i>=3) ){l=i- > 1;break;}; > cout<<l;}; > } Though I don't know what wrong about sqrt(k)+4 but I use k/2 instead of sqrt(k) and Get a AC try it please . I haven't learn C++ but I learned C and Pascal Why don't you use % in you program? If there is no % in C++ you can try this (k/i-int(k/i)<1e-15) and i think you'll get AC then. At last I give you a AC C program; #include<math.h> void main() { long n; long i; scanf("%ld",&n); for (i=3;i<=n/2;i++) if (!(n%i)) {printf("%ld\n",i-1);exit();} printf("%ld\n",n-1); } Good luck next time.:-) > > #include <iostream.h> > > #include <math.h> > > void main() > > { float k; > > long i,l; > > cin>>k; > > {l=int(k)-1; > > for(i=2;i<=sqrt(k)+4;i++) if ((k/i==int(k/i))&& (i>=3) ){l=i- > > 1;break;}; #include<iostream.h> #include<math.h> int k,l; void main() { cin>>k; long temp=(long)floor(sqrt(k))+2;//be care about k=4 for(long i=3;i<=temp;i++) if(k%i==0){ cout<<i-1; return; } if(k%2==0)k/=2; cout<<k-1; } > > cout<<l;}; > > } > Though I don't know what wrong about > sqrt(k)+4 but > I use k/2 instead of sqrt(k) and Get a AC > try it please . > I haven't learn C++ but I learned C and Pascal > Why don't you use % in you program? > If there is no % in C++ you can try this > (k/i-int(k/i)<1e-15) > and i think you'll get AC then. > At last I give you a AC C program; > #include<math.h> > void main() > { > long n; > long i; > scanf("%ld",&n); > for (i=3;i<=n/2;i++) > if (!(n%i)) > {printf("%ld\n",i-1);exit();} > printf("%ld\n",n-1); > } > Good luck next time.:-) > | | why I got WA? 3q | noname | 1032. Find a Multiple | 2 Aug 2002 22:24 | 1 | program find_a_multiple; const maxn=1000; var n:integer; a:array[1..maxn] of integer; s:array[0..maxn] of integer; c:array[1..maxn,0..2] of integer; procedure init; var i:integer; begin readln(n); for i:=1 to n do readln(a[i]); end; procedure out(i,j:integer); var k:integer; begin for k:=i to j do write(a[k],' '); writeln; halt; end; procedure work; var i:integer; begin fillchar(s,sizeof(s),0); for i:=1 to n do s[i]:=(s[i-1]+a[i]) mod n ; fillchar(c,sizeof(c),0); for i:=1 to n do if s[i]=0 then out(1,i) else begin inc(c[s[i],0]); c[s[i], c[s[i],0]]:=i; if c[s[i],0]=2 then out(c[s[i],1]+1, c[s [i],2]); end; end; begin init; work; end. | | help!!Why I got WA? | qwt | 1022. Genealogical Tree | 2 Aug 2002 21:18 | 3 | var a:array[1..100,0..100] of 0..1; b:array[1..100] of integer; n,i,j,k:integer; begin readln(n); for i:=1 to n do begin read(j); while j<>0 do begin a[i,j]:=1; read(j); end; readln; b[i]:=i; end; for i:=1 to n do for j:=1 to n do for k:=1 to n do if (a[i,j]=1)and(a[j,k]=1) then a[i,k]:=1; for i:=1 to n do for j:=1 to n do inc(a[i,0],a[i,j]); for i:=1 to n-1 do for j:=i+1 to n do if a[b[i],0]<a[b[j],0] then begin k:=b[i]; b[i]:=b[j]; b[j]:=k; end; for i:=1 to n do write(b[i],' '); writeln; end. Try this: delete the writeln; at the last line > Try this: delete the writeln; at the last line Thanks a lot!!!! | | My code gets WA, any help appreciated | Daniel | 1020. Rope | 2 Aug 2002 21:07 | 1 | #include <stdio.h> #include <math.h> int main() { float ans,r,x[100], y[100]; int n,i; scanf("%d %f", &n, &r); for (i = 0; i < n; i++) scanf("%f %f", &x[i], &y [i]); ans = 2*r*3.14159; if (n > 1) { for (i = 0; i < n-1; i++) ans += sqrt( (x[i]-x[i+1])*(x[i]-x[i+1]) + (y[i]-y[i+1]) * (y [i]-y[i+1])); ans += sqrt( (x[n]-x[1])*(x[n]-x[1]) + (y[n]-y[1]) * (y[n]-y [1])); } printf("%.2f\n", ans); return 0; } | | I got AC but if u know algorithm O(n) please send it to me(e-mail inside message) | King Without Kingdom | 1098. Questions | 2 Aug 2002 16:11 | 2 | vladimir_mnog@mail.ru tnxx VAR N,M:longint; FUNCTION Josefus(N,M:longint):longint; var L,c:longint; begin L:=0; for c:=1 to N do L:=(L+M-1) mod c + 1; Josefus:=L; end; BEGIN readln(N,M); writeln(Josefus(N,M)); END. | | Why am I getting a wrong answer... here's my source | Costel::icerapper@k.ro | 1028. Stars | 2 Aug 2002 12:47 | 2 | program timus_1028; const maxn=15000; type tcoord=record x,y:integer end; function Greater(c1,c2:tcoord):boolean; begin Greater:=(c1.x+c1.y)>(c2.x+c2.y); end; type ta=array[1..maxn]of tcoord; tv=array[0..maxn]of word; var n:integer; a:ta; v:tv; procedure read_data; var i:integer; begin readln(n); for i:=1 to n do readln(a[i].x,a[i].y); end; procedure Switch(var a,b:tcoord); var c:tcoord; begin c:=a; a:=b; b:=c; end; procedure quicky(start,stop:integer); var ini,fin:integer; step:integer; begin if start>=stop then exit; ini:=start; fin:=stop; step:=1; while ini<fin do begin if Greater(a[ini],a[fin]) then begin Switch(a[ini],a[fin]); step:=1-step; end; inc(ini,step); dec(fin,1-step); end; quicky(start,ini-1); quicky(fin+1,stop); end; procedure sort_data; begin quicky(1,n); end; procedure init_data; begin fillchar(v,sizeof(v),0); end; procedure make_data; var i:integer; k:integer; begin v[0]:=1;k:=0; for i:=2 to n do begin if Greater(a[i],a[i-1]) then inc(k); inc(v[k]); end; end; procedure writ_data; var i:integer; begin for i:=0 to n-1 do writeln(v[i]); end; begin read_data; sort_data; init_data; make_data; writ_data; end. 3 1 1 4 1 3 10 The Correct answer is : 1 2 0 | | Who can paste an AC program to all us ? | lyj_george | 1201. Which Day Is It? | 1 Aug 2002 20:25 | 2 | We can know all where we made mistakes. #include <iostream> using namespace std; inline bool is_leap_year(int y) { return y%4==0&&(y%100!=0||y%400==0); } inline int days_per_year(int y) { if(is_leap_year(y)) return 366; else return 365; } inline int days_per_month(int m,int y) { const int days[12]={31,28,31,30,31,30,31,31,30,31,30,31}; if(m!=2) return days[m-1]; else if(is_leap_year(y)) return 29; else return 28; } int get_day_of_week(int m,int d,int y) { int day=4; int i; for(i=1600;i<y;i++) day+=days_per_year(i); for(i=1;i<m;i++) day+=days_per_month(i,y); day+=d; return day%7; } void print_calendar(int m,int d,int y) { const char* day_name[7]= {"mon","tue","wed","thu","fri","sat","sun"}; int days=days_per_month(m,y); int day_begin=1-get_day_of_week(m,1,y); for(int i=0;i<7;i++) { cout<<day_name[i]; for(int j=day_begin+i;j<=days;j+=7) if(j<1||j>days) cout<<" "; else if(j==d) { if(j<10) cout<<" [ "<<j<<"]"; else cout<<" ["<<j<<"]"; } else { if(j<10) cout<<" "<<j<<" "; else cout<<" "<<j<<" "; } cout<<endl; } } int main() { int d,m,y; cin>>d>>m>>y; print_calendar(m,d,y); return 0; } | | Give me some good test, please! I gov WA! | hidden_u | 1087. The Time to Take Stones | 1 Aug 2002 12:36 | 4 | const MAXN = 10000; var N,M,i,j,min:integer; K:array[1..100]of integer; a:array[1..MAXN]of byte; begin readln(N,M); for i:=1 to M do begin read(K[i]); end; for i:=1 to N do a[i]:=2; min:=MaxInt; for i:=1 to M do if min > k[i] then min:=k[i]; a[min]:=0; for i:=min+1 to N do begin for j:=1 to M do if (i-K[j]>0)and(a[i-K[j]]<>2) then begin if a[i-K[j]] = 0 then begin a[i]:=1; break; end else a[i]:=0; end; end; if a[N] = 0 then writeln(2) else writeln(1); end. Try this test: 117 2 15 17 Correct answer is 1 > Try this test: > 117 2 > 15 17 > Correct answer is 1 But, 117 = 15*1+17*6; so the first person will take four times and the second one three times. This implies that the first one must be taking the last stone. | | Pls tell me why WA!?!?problem : 1185. | Rostislav | | 1 Aug 2002 07:47 | 1 | #include <fstream.h> #include <math.h> #include <stdio.h> struct point { double x,y; }; point a[1024],convex[1024],pom; double det (double x1,double y1,double x2,double y2,double x3,double y3) { return x1*(y2-y3)-y1*(x2-x3)+x2*y3-y2*x3; } void qsort (long l,long r) { point z; long i,j; i=l; j=r; z=a[(i+j)/2]; do { while (det(a[1].x,a[1].y,a[i].x,a[i].y,z.x,z.y)>0.0) i++; while (det(a[1].x,a[1].y,a[j].x,a[j].y,z.x,z.y)<0.0) j--; if (i<=j) { pom=a[i]; a[i]=a[j]; a[j]=pom; i++; j--; } } while (i<=j); if (l<j) qsort(l,j); if (i<r) qsort(i,r); } void main () { long n,i,p,k; double d,l; cin >> n >> l; for (i=1;i<=n;i++) cin >> a[i].x >> a[i].y; //------------------ p=1; for (i=2;i<=n;i++) if (a[p].y>a[i].y || (a[p].y==a[i].y && a[p].x>a[i].x)) p=i; pom=a[p]; a[p]=a[1]; a[1]=pom; qsort(2,n); a[n+1]=a[1]; p=1; for (i=2;i<=n;i++) if (a[i].y==a[1].y && a[i].x>a[p].x) p=i; if (p==1) p=2; convex[1]=a[1]; convex[2]=a[p]; k=2; for (i=p+1;i<=n+1;i++) if (a[i].y>a[1].y || i==n+1) { convex[++k]=a[i]; while (det(convex[k-2].x,convex[k-2].y,convex[k-1].x,convex[k- 1].y,convex[k].x,convex[k].y)<=0 && k>2) convex[--k]=convex[k+1]; } //------------------ double pi; pi=3.14159265358979; d=0; for (i=1;i<k;i++) d+=sqrt((convex[i].x-convex[i+1].x)*(convex[i].x-convex[i+1].x)+ (convex[i].y-convex[i+1].y)*(convex[i].y-convex[i+1].y)); d+=2*pi*l; //------------------ printf("%.0f \n",d); } | | Why My Program Get Crash(ACCESS_VIOLATION) ? Help !!! | XueMao | 1036. Lucky Tickets | 31 Jul 2002 17:40 | 1 | {$N+,s-} Program Lucky_ticket; Type xm=array[-50..200] of integer; Lion=array[0..1,-50..1000] of ^xm; Var k,i,j,m,n,u,v,t,t1:Longint; q:double; a:Lion; LL:array[0..1,-100..1000] of integer; c:array[-100..1000] of longint; Procedure Go(x,y:longint); var i,j,k,L:longint; begin if LL[t,x]>LL[t1,y] then L:=LL[t,x] else L:=LL[t1,y]; for i:=1 to L do begin inc(a[t,x]^[i],a[t1,y]^[i]); if a[t,x]^[i]>9 then begin dec(a[t,x]^[i],10); inc(a[t,x]^[i+1]); end; end; if a[t,x]^[L+1]<>0 then LL[t,x]:=L+1 else LL[t,x]:=L; end; Procedure Cheng(x:integer); var i,L:longint; begin fillchar(c,sizeof(c),0); for i:=1 to LL[t,x] do for j:=1 to LL[t,x] do inc(c[i+j-1],a[t,x]^[i]*a[t,x]^[j]); for i:=1 to LL[t,x]+LL[t,x] do begin inc(c[i+1],c[i] div 10); c[i]:=c[i] mod 10; end; if c[LL[t,x]+LL[t,x]]<>0 then L:=LL[t,x]+LL[t,x] else L:=LL[t,x]+LL[t,x]-1; for i:=L downto 1 do write(c[i]); writeln; end; Begin read(n); read(m); if (m>2*n*9)or(odd(m)) then begin writeln(0); exit; end; m:=m shr 1; for j:=0 to 1 do for i:=0 to m+1 do begin new(a[j,i]); fillchar(a[j,i]^,sizeof(a[j,i]^),0); end; for i:=0 to 9 do begin a[1,i]^[1]:=1; LL[1,i]:=1; end; t:=1; t1:=0; for i:=2 to n do begin t1:=t; t:=1-t; for j:=0 to m+1 do fillchar(a[t,j]^,sizeof(a[t,j]^),0); fillchar(LL[t],sizeof(LL[t]),0); u:=i*9; if m<u then u:=m; for j:=0 to u do begin v:=j-9; if v<0 then v:=0; for k:=v to j do go(j,k); end; LL[t1]:=LL[t]; end; cheng(m); End. | | HELP ME,PLS...1102 | Vladimir Milenov Vasilev | | 31 Jul 2002 14:56 | 4 | Hi! When reading string from the standart input character by character, how can I stop reading it and go to the next line of the input.. I mean, when I understand the answer is "NO", I don't need to read the whole string, as the answer will be the same, I just want to go to the next line and proceed with the next string. How to do This? Thanks in advice :) while not eoln(INPUT) do begin ... ... if NO then break; ... end; if not eoln(INPUT) then readln; Thank you verry much, but I am using C++... Do you know how it will be there? | | How to slove this problem ? could anyone help me ? | XueMao | 1028. Stars | 30 Jul 2002 18:17 | 1 | I am so stupid . I can't find the way of doing this problem in O(n*Log(n)) , Can anyone tell me the method ? Thanks a lot ! | | Problem: Some board aren't working (1205 for example) | Petko Minkov | | 30 Jul 2002 16:35 | 2 | Do you have the same problem ??? | | About problem 1004 - wrong test data!!! | Vladimir Milenov Vasilev | 1004. Sightseeing Trip | 29 Jul 2002 22:24 | 1 | This porblem has not correct test's again.For example, if always output something like printf("700000\n"); you'll get accepted. |
|
|