Show all threads Hide all threads Show all messages Hide all messages | Help me please !!! | Simeon Kostenski | 1053. Pinocchio | 19 Oct 2004 14:52 | 5 | I just can't understand which blanks we actually choose at step 3. What does "minimal numbers" mean. It's just very bad English that has been used. I've submitted this problem lots of times, but I just can't grasp the situation. If possible, please help me. The percentage is extremely low, but please explain it to me :(((( > I just can't understand which blanks we actually choose at > step 3. What does "minimal numbers" mean. It's just very > bad English that has been used. I've submitted this problem > lots of times, but I just can't grasp the situation. If > possible, please help me. The percentage is extremely low, > but please explain it to me :(((( "minimal numbers" - meen that one of them shoud be minimal number in the set of numbers "blank with minimal number" is equal to "blank with minimal length" Edited by author 19.10.2004 14:53 | It's very simple problem, but you don't need to sort the elements :-) | Veselin Kolev | 1053. Pinocchio | 22 Sep 2004 18:01 | 2 | #include <iostream> using namespace std; short n; unsigned long a[1000]; void Input() {cin>>n; for (short i=0; i<n; i++) cin>>a[i]; } unsigned long gcd(unsigned long a, unsigned long b) {unsigned long x; while (b>0) {x=b; b=a%b; a=x; } return a; }
void Solve() {for (short i=1; i<n; i++) a[i]=gcd(a[i-1],a[i]); } void Output() {cout<<a[n-1]<<"\n"; } int main() {Input(); Solve(); Output(); return 0; } Edited by author 11.09.2004 21:52 You even may keep in memory only two elements. | Though the problem seems difficult, it is really very simple! | Nijino Saki | 1053. Pinocchio | 11 Jun 2004 08:04 | 3 | See my accepted program: Program P1053; Const Max=1000; Type TList=Array[1..Max] of Longint; Var A:TList; n,s,i:Integer; r1,r2:longint; Procedure Sort(l,r:Integer); Var x,t:Longint; i,j:Integer; Begin i:=l; j:=r; x:=A[(i+j) div 2]; repeat while A[i]>x do inc(i); while A[j]<x do dec(j); if i<=j then begin if i<>j then begin t:=A[i]; A[i]:=A[j]; A [j]:=t end; inc(i); dec(j) end until i>j; if i<r then Sort(i,r); if l<j then Sort(l,j) End; Function Gcd(A,B:Longint):Longint; Var C:Longint; Begin while B<>0 do begin C:=A; A:=B; B:=C mod B end; Gcd:=A End; Begin readln(n); for i:=1 to n do read(A[i]); Sort(1,n); for i:=n-1 downto 1 do A[i]:=Gcd(A[i+1],A[i]); writeln(A[1]) End. Yes, that's really nice. And think about a programming language that supports sorting like C, C++, Java, Perl, ... The code would be even smaller. But if you think a bit further, sorting isn't necessary at all. That makes the following program getting accepted, too. Normally I would never ever post a ready-to-submit program, but since you already did this I think I can't make things worse... (I admit that I didn't solve the problem myself; I read yours in order to understand the problem and unfortunately the whole solution was clear at first sight :-( #include <iostream.h> int gcd( int a, int b ){ return b ? gcd( b, a%b ) : a; } int main () { int n, L, g=0; cin >> n; while( cin >> L ) g=gcd( L, g ); cout << g << endl; } Just calculate the GCD of the given numbers! | SOS! | Amy | 1053. Pinocchio | 18 Jul 2003 15:24 | 1 | SOS! Amy 18 Jul 2003 15:24 This is my programme,please tell me why I got WA.Thank you! var n,m,m0,ys:longint; procedure pd(a,b:longint); var t:longint; begin if a<b then begin t:=b; b:=a; a:=t; end; while a mod b<>0 do begin a:=a mod b; t:=a;a:=b;b:=t; end; ys:=b; end; procedure run; var i:integer; begin for i:=1 to n-1 do begin read(m); pd(m0,m); m0:=ys; end; writeln(ys); end; begin readln(n); read(m0); run; end. | why did I have CE??! | Bushtruk Vyacheslav | 1053. Pinocchio | 14 Feb 2003 16:26 | 1 | On my computer program works correclty, but I had three CE to #1053 problem.Quastion is a word - "why":-(( ? I supposed problem in <math.h> or <stdlib.h> file. Program COD:: #include <stdio.h> #include <math.h> #include <stdlib.h> int NOD(int i1,int i2){ if(i1==i2)return i1; int del=1,c1,c2; while(1){ c1=i1; c2=i2; if(fmod(c1,del)!=0)break; if(fmod(c2,del)!=0)break; del++; }; del--; return del; }; void main(){ int mas[999]; int q1; scanf("%i",&q1); for(int i=0;i<q1;i++){ scanf("%i",&mas[i]); if(mas[i]==1){ printf("%i",1); exit(1); } } q1=1; while(mas[q1]!=0){ mas[0]=NOD(mas[0],mas[q1]); q1++; if(mas[0]==1){ printf("%i",1); exit(1); } } printf("%i",mas[0]); }; | Help me,please!What does the mistake called "Crash (ACCESS_VIOLATION)"??? | Lin Bo | 1053. Pinocchio | 5 Dec 2001 20:54 | 2 | What does the mistake called "Crash (ACCESS_VIOLATION)"??? > What does the mistake called "Crash (ACCESS_VIOLATION)"??? > |
|
|