Common Board| Show all threads Hide all threads Show all messages Hide all messages | | 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! | | E belea... | Daniel Pasaila | 1018. Binary Apple Tree | 11 Jun 2004 05:23 | 3 | In Eng, plz! Maigo Akisame (maigoakisame@yahoo.com.cn) 11 Jun 2004 05:23 | | You are talking about ignoring 0-apple branches and decreasing q by the number of them. But where does the problem talk about 0-apple branches? | Maigo Akisame (maigoakisame@yahoo.com.cn) | 1018. Binary Apple Tree | 11 Jun 2004 05:22 | 1 | | | I used DP and got AC.I just want to know is there any ways to solve this problem by maths? | Yuanming YU, Frank | 1223. Chernobyl’ Eagle on a Roof | 10 Jun 2004 21:27 | 1 | If so, could you write it down or post it to me? Thanks! My E-mail: yuyuanming163@163.com | | WA on test #1! I used the O(n) algo. Anything strange? | Maigo Akisame (maigoakisame@yahoo.com.cn) | 1032. Find a Multiple | 10 Jun 2004 17:28 | 1 | | | Problem??? | sokol | 1296. Hyperjump | 10 Jun 2004 12:14 | 3 | For example: If N=3 and p1=3; p2=-3; p3=10; What i and j = ? How can you calculate i and j? | | Why do I get CRASH(ACCESS_VIOLATION)? I don't understand! | Maigo Akisame (maigoakisame@yahoo.com.cn) | 1016. Cube on the Walk | 10 Jun 2004 09:24 | 1 | program ural1016; const top:array[1..6{front},1..6{left}]of byte= ((0,4,2,5,3,0),(3,0,6,1,0,4),(5,1,0,0,6,2), (2,6,0,0,1,5),(4,0,1,6,0,3),(0,3,5,2,4,0)); var side:array[1..6]of integer;{top,front,right,bottom,back,left} dist:array['a'..'h',1..8,1..6{front},1..6{left}]of longint; q:array[1..10000]of record x:char; y,f,l:byte; pre:integer; end; sx,tx,x:char; sy,ty,y,f,l:byte; front,rear,p:integer; min:longint; route:string; procedure add(x1:char;y1,f1,l1,cost:byte); begin if dist[x,y,f,l]+side[cost]>=dist[x1,y1,f1,l1] then exit; dist[x1,y1,f1,l1]:=dist[x,y,f,l]+side[cost]; inc(rear); with q[rear] do begin x:=x1;y:=y1;f:=f1;l:=l1;pre:=front; end; if (x1=tx) and (y1=ty) then if dist[x1,y1,f1,l1]<min then begin min:=dist[x1,y1,f1,l1]; p:=rear; end; end; begin for x:='a' to 'h' do for y:=1 to 8 do for f:=1 to 6 do for l:=1 to 6 do dist[x,y,f,l]:=maxlongint; min:=maxlongint; read(sx);read(x);sy:=ord(x)-48;read(x); read(tx);read(x);ty:=ord(x)-48; readln(side[2],side[5],side[1],side[3],side[6],side[4]); dist[sx,sy,2,4]:=side[6]; front:=0;rear:=1; q[1].x:=sx;q[1].y:=sy;q[1].f:=2;q[1].l:=4; repeat inc(front); x:=q[front].x;y:=q[front].y;f:=q[front].f;l:=q[front].l; if y<8 then add(x,succ(y),7-top[f,l],l,7-f);{Go up} if y>1 then add(x,pred(y),top[f,l],l,f);{Go down} if x>'a' then add(pred(x),y,f,top[f,l],l);{Go left} if x<'h' then add(succ(x),y,f,7-top[f,l],7-l);{Go right} until front=rear; write(min); route:=' '+q[p].x+chr(48+q[p].y); while p>1 do begin p:=q[p].pre; route:=' '+q[p].x+chr(48+q[p].y)+route; end; writeln(route); end. | | Anyone can give any hint to save the Memory? | liuchang | 1220. Stacks | 10 Jun 2004 07:09 | 1 | I'm locked at the problem some long.Could anyone make me know how to save the memory? | | Please give me some test | 法克 | 1039. Anniversary Party | 10 Jun 2004 04:06 | 4 | {my wrong code} const maxn=600; type link=^re; re=record num:integer; q:link; end; var p:link; n:longint; va:array[1..maxn]of byte; g:array[1..maxn]of link; max:array[1..maxn,0..1]of longint; r:array[1..maxn]of boolean; procedure init; var x,y,i:longint; begin assign(input,'1039.in'); reset(Input); fillchar(r,sizeof(r),false); readln(n); for i:=1 to n do readln(va[i]); readln(y,x); while (x<>0) or (y<>0) do begin r[y]:=true; new(p); p^.num:=y; p^.q:=g[x]; g[x]:=p; readln(y,x); end; end; procedure solve(root:longint); var p:link; x,big:longint; begin new(p); p:=g[root]; while p<>nil do begin x:=p^.num; solve(x); inc(max[root,1],max[x,0]); if max[x,0]>max[x,1] then big:=max[x,0] else big:=max[x,1]; inc(max[root,0],big); p:=p^.q; end; inc(max[root,1],va[root]); end; procedure main; var i:longint; begin for i:=1 to n do if not(r[i]) then begin solve(i); if max[i,1]>max[i,0] then writeln(max[i,1]) else writeln(max[i,0]); exit; end; end; begin init; main; end. The code is wrong at the fourth test.I am pluzzled. Please give me some tests. Sorry for my fool. Two bugs A new start... 25 May 2004 15:25 1). maxn must be 6000 2). va must be array of LongInt Thank you very much! I fix my code following your advice and AC now. I am so careless that I feel very ashamed.You are an alive Lei Feng(a great person).And I would like to make friends with you. Re: Two bugs Maigo Akisame (maigoakisame@yahoo.com.cn) 10 Jun 2004 04:06 'An alive Lei Feng' is wrong, it must be 'a living Lei Feng'. | | I've got the problem with compilation... | Alfard | | 9 Jun 2004 21:43 | 1 | Language Pascal In puzzle 1221 system said me : "Compilation error"... On my PC program is work. Which kind of Pascal compilator using for test programs? Where I could take tests for programs, if it's possible? | | Why this code got CE? I can compile it by GCC. | Savior | | 8 Jun 2004 14:49 | 2 | #include <cstdio> #include <cstring> #include <cmath> #include <vector> #include <algorithm> using namespace std; const double EPS=1e-8; const int MAXN=100; const int MAXM=100; struct Tnode { int x,y; double r,c; }; int n,m; int s; double v; vector<Tnode> c; double a[MAXN]; int ind[MAXN][2]; inline bool cmp(Tnode p1,Tnode p2) { return(p1.x==p2.x)?(p1.y<p2.y):(p1.x<p2.x); } void read() { int i,x,y; Tnode tmp; scanf("%d%d%d%lf",&n,&m,&s,&v); s--; c.clear(); for(i=0;i<m;i++) { scanf("%d%d",&x,&y); x--,y--; tmp.x=x,tmp.y=y; scanf("%lf%lf",&tmp.r,&tmp.c); c.push_back(tmp); tmp.x=y,tmp.y=x; scanf("%lf%lf",&tmp.r,&tmp.c); c.push_back(tmp); } sort(c.begin(),c.end(),cmp); memset(ind,255,sizeof(ind)); ind[c[0].x][0]=0; for(i=1;i<c.size();i++) { if(c[i].x!=c[i-1].x) { ind[c[i-1].x][1]=i-1; ind[c[i].x][0]=i; } } i=c.size()-1; ind[c[i].x][1]=i; } bool solve() { int i,j; bool done; double u; for(i=0;i<n;i++) a[i]=-1.; a[s]=v; do { done=1; for(i=0;i<n;i++) if(a[i]>EPS) { if(ind[i][0]<0) continue; for(j=ind[i][0];j<=ind[i][1];j++) if(a[i]>c[j].c+EPS) { u=(a[i]-c[j].c)*c[j].r; if(a[c[j].y]<-EPS) { a[c[j].y]=u; done=0; } else { if(u>a[c[j].y]+EPS) return 1; } } } } while(!done); return 0; } int main() { read(); if(solve()) printf("YES\n"); else printf("NO\n"); return 0; } | | what is the answer for ... (very important test) | lomark | 1200. Horns and Hoofs | 7 Jun 2004 15:14 | 2 | 8475.009765625 3721.89990234375 3455 my answer is : 17925655.52 2916 539 for 8475.00 3721.89 3455 i have the answer 17925621.65 2916 539 First answer is correct (I mean, my program that is AC, gives the same result :)) Answer for 2nd test should look like this: 17925621.71 2916 539 Probably you have some rounding problems (in your answer two digits after decimal point are incorrect). | | Help! Why my program got WA at test4??? I didn't know! | Tang RZ | 1094. E-screen | 7 Jun 2004 11:46 | 1 | This is my program: var a:array [1..80] of char; hand:integer; procedure work(ch:char); begin if ch='>' then begin inc(hand); if hand>=80 then hand:=1; end else if ch='<' then begin dec(hand); if hand<=1 then hand:=1; end else if (ch>='a')and(ch<='z')or(ch>='A')and(ch<='Z') then begin a[hand]:=ch; inc(hand); if hand>=80 then hand:=1; end else begin a[hand]:=ch; inc(hand); if hand<1 then hand:=1; end; end; procedure init; var ch:char; begin hand:=1; fillchar(a,sizeof(a),' '); repeat read(ch); work(ch); until eof; end; procedure print; var i:integer; begin for i:=1 to 80 do write(a[i]); writeln; end; begin init; print; end. | | Help! Why my program got WA at test4??? I didn't know! | Tang RZ | 1094. E-screen | 7 Jun 2004 11:46 | 1 | This is my program: var a:array [1..80] of char; hand:integer; procedure work(ch:char); begin if ch='>' then begin inc(hand); if hand>=80 then hand:=1; end else if ch='<' then begin dec(hand); if hand<=1 then hand:=1; end else if (ch>='a')and(ch<='z')or(ch>='A')and(ch<='Z') then begin a[hand]:=ch; inc(hand); if hand>=80 then hand:=1; end else begin a[hand]:=ch; inc(hand); if hand<1 then hand:=1; end; end; procedure init; var ch:char; begin hand:=1; fillchar(a,sizeof(a),' '); repeat read(ch); work(ch); until eof; end; procedure print; var i:integer; begin for i:=1 to 80 do write(a[i]); writeln; end; begin init; print; end. | | what is the answer for ... | lomark | 1200. Horns and Hoofs | 7 Jun 2004 02:16 | 1 | | | why WA !! i use GCD only plzzzzz help me! | Pradeep Muthukrishnan | 1024. Permutations | 6 Jun 2004 19:09 | 2 | [code deleted] Edited by moderator 04.12.2019 21:09 #include<iostream> #define MAX 1001 // see here [code deleted] long long int ord[MAX],arr[MAX]; // see here [code deleted] Edited by moderator 04.12.2019 21:10 | | Why do we use calculation lcm? | LittleTiger | 1024. Permutations | 6 Jun 2004 16:45 | 1 | | | HINT if u use gcd in calculation of lcm | xdex | 1024. Permutations | 6 Jun 2004 13:36 | 6 | in pascal i used lcm := a*b div gcd(a,b); i got WA i changed line to lcm := trunc(1.0*a*b / gcd(a,b)); and got AC i think i had arithmetic overflow Post your code please .... I dont understand well in pascal but i want to know your algorithms ... Using my code , i got Time Out .... below is my code : #include<stdio.h> int p[1000],tmp[1000]; int n; int go(int t,int i){ int j,v;
v=p[i]; for(j=1;j<t;j++) v=p[v-1]; return v; } int checkout(int t){ int i;
for(i=0;i<n;i++){ tmp[i]=go(t,i); if(tmp[i] != i+1) return checkout(t+1); } return t; } int main(){ int i; scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&p[i]); printf("%d\n",checkout(1)); return 0; } let consider following : (a**b means a*a*a*...*a (b times)) p ** k1(1) = 1 p ** k2(2) = 2 ... p ** kN(n) = n i.e. order of #i is ki. the order of entire permutation is a number that is devided by k1, k2, .., kN. The lowest such number is lcm(k1, k2, ... , kN); but lcm(a, b) * gcd(a, b) = a * b; that is lcm(a, b) = a * b / gcd(a, b); Yep , That is realy a GOOD Yep , that is a good idea ... | | I want to know if there are here cool programists which can help me? | Vasily Slesarev | | 5 Jun 2004 18:51 | 2 | problem 1286 I am sure that my program is right, but I get WA on test 16 Help(Do somebody know something interesting?) I want to know anything too.. | | How write answer fast? | Marina Mukhacheva | 1069. Prufer Code | 5 Jun 2004 14:40 | 3 | How write answer fast? In my program i get array[1..2, 1..n] - array of rid in graph. And write answer in O(3*N^2) - that very big. My program: var a,b : array [1..7501] of word; p : array [1..2, 1..7501] of word; ans : array [1..7501] of boolean; i,j,k,n,x : longint; BEGIN n := 0; while not eof do begin read(x); inc(n); a[n] := x; inc(b[x]); end; for i := 1 to n do begin j := 1; while (b[j] <> 0) do inc(j); dec(b[a[i]]); b[j] := 65535; p[1, i] := a[i]; p[2, i] := j; end; for i := 1 to n+1 do begin fillchar(ans, sizeof(ans), 0); for k := 1 to n do for j := 1 to 2 do if p[j, k] = i then ans[p[3-j, k]] := true; write(i,':'); for j := 1 to n+1 do if ans[j] then write(' ',j); writeln; end; END. Edited by author 05.06.2004 09:37 How??? Marina Mukhacheva 5 Jun 2004 14:40 |
|
|