Common BoardCan I use C++ feature "overloading of operator new" to increase the speed of memory allocation? give me this test and it's result please. I am stupid :) now I have problems with WA#11 Edited by author 29.08.2007 23:09 12 ans:3052783504 16 ans:23194144960900 Thank!!! Edited by author 30.08.2007 04:32 What answer,when n=14.Thank! There is no need to use DP. Can your write proveness of Greedy for this problem? Dp as a rule absolute correct optimization method but greedy often well to next rejudgement. Yes!! AC Very hidden information needed: Dimploms of one type must be placed in one row. During a long time I thought that after changing conditions we can placed them in any different rows. Edited by author 24.01.2008 11:04 Let's try to proove it with one additional statement: "There is only one type of diploms with some size S". First we put all type of diploms in seperate lines. Now we must minimize the number of rows. By the problem description we have: We can merge two (x and y) rows into one if and only if equality is statisfied: |size(x)-size(y)| == 1 So, some diplom row x can be merged only with row y. Where: size(y) == size(x)+1 or size(y) == size(x)-1. If none of y diploms row exist, then row x can not be merged and it must stay. If only one dimplom row y exist, then we must do this megre not looking on y at all. Even if y has other possible merging global minimus isn't affected. If we can megre x and y or y and z, we can merge only one pair. The last type of merge left, then x can be merged from both sides. Here we cant choose the prefered merge so easily. So let's sort all rows and analise them in accessing order. Then this situation just can not happen, cause all size(y)-1 merging row will be merged before, then analysing Y row. Now lets apply this proof to out problem. We just have to divide all dimploms into sets. In set A goes all dimpols x with size(x) == A. So we must minimize the sum of all set's power by same apporach. Just want to concern who got WA in test 4. Coz, I waste my time for debuging it. Why don't someone add this imformation on the problem page. I wrote this program and think this is right. But I have WA#7. I tested my program by many my own test. And it gives correct answer in 100% cases. May be someone can give me a test. This is my prog: [Code deleted by author] Edited by author 28.08.2007 22:14 I'm still waiting for your help... My friend, you should be more attentive)) 200 * 200 is much more bigger then 5000)) And please delete your AC code)) Edited by author 28.08.2007 22:43 My program: Program t1130;{$N+} Const MaxN=10000; Var T :array[1..MaxN,1..3]of longint; N,i,j :longint; L :extended; Ci,Cj :extended; ex :boolean; begin FillChar(T,SizeOf(T),0); Ci:=0; Cj:=0; Read(N,L); for i:=1 to N do begin Read(T[i,1],T[i,2]); T[i,3]:=1; Ci:=Ci+T[i,1]; Cj:=Cj+T[i,2]; end; Repeat ex:=true; for i:=1 to N do if T[i,3]=1 then if Sqr(Ci-2*T[i,1])+Sqr(Cj-2*T[i,2])<Ci*Ci+Cj*Cj then begin T[i,3]:=-1; Ci:=Ci-2*T[i,1]; Cj:=Cj-2*T[i,2]; ex:=false; end else if Sqr(Ci+2*T[i,1])+Sqr(Cj+2*T[i,2])<Ci*Ci+Cj*Cj then begin T[i,3]:=1; Ci:=Ci+2*T[i,1]; Cj:=Cj+2*T[i,2]; ex:=false; end; if (ex)and(Ci*Ci+Cj*Cj>2*L*L) then begin T[N,3]:=-1*T[N,3]; Ci:=Ci+2*T[N,3]*T[N,1]; Cj:=Cj+2*T[N,3]*T[N,2]; ex:=false; end; Until ex; Writeln('YES'); for i:=1 to N do if T[i,3]=1 then Write('+') else Write('-'); Writeln; end. {$n+} Program Walk; Var i,j,k,m,n,bj:longint; x,y,z:double; a:array[1..10001,1..2] of integer; e:array[1..10001] of shortint; Begin fillchar(a,sizeof(a),0); fillchar(e,sizeof(e),0); read(n); read(z); x:=0; y:=0; for i:=1 to n do begin e[i]:=1; read(a[i,1],a[i,2]); x:=x+a[i,1]; y:=y+a[i,2]; end; while x*x+y*y-2*z*z>1e-14 do begin for i:=1 to n do if sqrt(x*x+y*y)-Sqrt(sqr(x-2*a[i,1]*e[i])+sqr(y-2*a[i,2]*e[i])) >1e-14 then begin x:=x-2*a[i,1]*e[i]; y:=y-2*a[i,2]*e[i]; e[i]:=-e[i]; if 2*z*z-x*x-y*y>1e-14 then break; end; end; writeln('YES'); for i:=1 to n do if e[i]=-1 then write('-') else write('+'); writeln; End. Dont believe this programm it gets TLE on test12 Who can give me that test? Thank you to the ones who provide some tests. wtf?? My equal solutions on Pascal and C++ has WA on tests 3 and 2. Why? I used some formulas - sqrt(2)/2, cos(pi/4), and others. May be, error in real types (I used some variants: Pascal - extended C++ - double, long double ) I read other topics about this problem, but I have not AC :) Thanks. I used: const double root = sqrt(2.0)/2.0; Ups.. double post.. Edited by author 28.08.2007 00:57 WA Test 9. Can anyone test my program? Anyone know what is the test #9? It runs well on MS Visual C# 2005, but here i get CE using System; using System.Text; class Program { static void Main() { ulong n = ulong.Parse(Console.ReadLine()); ulong sum = 1; ulong ans = 0; ulong a = 2, b = 3, c = 4; ulong a1 = 1, b1 = 1, c1 = 1; for (ulong i = 1; i <= n; ++i) { a1 *= a; a1 %= 1000; b1 *= b; b1 %= 1000; c1 *= c; c1 %= 1000; } sum += a1 + b1 + c1; while (true) { if ((sum % 10) == 0) { ans++; } else { Console.WriteLine(ans); break; } sum /= 10; } } } Edited by author 30.01.2007 15:26 Say you what you write on c# Edited by author 21.03.2007 14:23 Really compilation error? I sent your solution for problem 1000 and it was compiled (I got crash on 1 test). Be sure that you selected correct langyage during submitting Edited by author 21.03.2007 16:47 man put instead of true sum != 0 IS it possible such an input? OOO XX# X## I think no. It is finished . Here is my solution in C++ I delete my solution becouse I resive ansver . Edited by author 27.08.2007 14:22 Edited by author 27.08.2007 14:22 Look at attentively =) >> printf("%s\n", l[3][i]); printf("\n");s (symbol 's' in the end of string) I tried to receive accept using Java... Now I have only one trouble: "PrintStream System.out" saves all data which is outputted. So it uses unnecessary almost 1MB :( If somebody knows how to cope with it, please, tell me. I'm not sure, but mb calling "System.out.flush()" several times while outputing can help... Thank you :) I already tried... System.out is autoflushable so flush() doesn't change anything. Edited by author 26.08.2007 12:40 Hm... IMHO there is no place to store the previous output in java.lang.PrintStream. I think that plenty of temporary objects are creating in some operations (using Strings) in System.out.print(...). Of course they aren't deleting by the garbage collector during one-second thread lifetime. Try to use System.out.write(byte), it seems to be OK there. (So you have to implement some boring things...). I also had troubles with java.lang.String... Discovering O(n) performance of operator+ was at the wrong time :). Edited by author 27.08.2007 02:05 System.out=F; Of course, i used exactly F.write(int), it calls F.out.write(int) where F.out is OutputStream which F gets from its constructor. And how F.out is implemented, i don't know... And don't know where it can be read about :( Btw... I tried to use garbage collector with hands, it uses 1.5M itself :( >> I also had troubles with java.lang.String... Discovering O(n) performance of operator+ was at the wrong time :). Thank you for experience =) Edited by author 27.08.2007 13:05 Source code of all java libraries is fully avalible, there is the src.zip file in the root folder of JDK. That code isn't so complicated. In this problem... I've tried to submit code like this: public class A { public static void main(String[] args) { int[]a = new int[100000]; //to get ML, not OL, the size was different - I can't remember it for(int i = 0; i < 100000; ++i) { //also 100000 isn't true //System.out.print('1'); - case 1 //System.out.write((int)'1'); - case 2 } } } Case 1 got ML, but case 2 uses the same amount of memory like the code without any output.. Edited by author 27.08.2007 13:34 I had WA#12 when I've forgotten that the wights can be 0)) 850784 15:24:03 20 May 2005 Fu Dong 1115 Pascal Accepted 0.001 141 KB I think the most important thing to this problem is to sort ships' length. First I sorted them from short to long, but I got TLE on test #8, then I sorted from long to short, to my surprise, I got AC with 0.001s! My solution is not DFS ! I think it O(x*n*MaxL) with MaxL = Max( length row[i] , i=1..n ) . But I haven't define how much x does yet ! Maybe x <= 10 ! I don't think your program run faster than mine because the test are not so hard. To N.M.Hieu ( DHSP ): What's your way? Sorry , I'm mistaken . Mine is backtracking . At that time , I was too young , so ... I used DP to reduce the time of searching in bad result . It's hard to say clearly due to my bad english . If you want , leave me your email-address , I will mail you my solution , it's not good to pass the tests of problem 1394 ( Ship versions 2 ) but enough to pass those of this problem . // why wa, i was really confused #include <stdio.h> #define MAXN 1002 int perm[ MAXN ] ; void swap(long long* x,long long* y ) { long t = *x; *x = *y; *y = t; } long long gcd(long long m,long long n) { long r; if( m < n ) swap( &m,&n ); do{ r = m % n ; m = n; n = r; }while( r ); return m; } int main() { int size , i, mark, q[ MAXN ] ; long long t[ MAXN ] ; while( scanf("%d",&size ) != EOF ){ for( i = 1 ; i <= size; i++ ){ scanf("%d",&perm[ i ]); q[ i ] = perm[ i ] ; t[ i ] = 1; } for( i = 1; i <= size; i++ ) for( ; i != perm[ i ] ; t[ i ]++ ) perm[ i ] = q[ perm[ i ] ] ; for( i = 1; i <= size - 1; i++ ) t[ i ] = ( t[ i ] / gcd( t[ i ],t[ i + 1 ] ) ) * t[ i + 1 ] ; printf("%I64d\n",t[ i - 1 ] ); for( i = 1 ; i <= size; i++ ) t[ i ] = 1; } return 0; } Tests for your program: 1 1 5 2 1 4 5 3 Use for( i = 1; i <= size - 1; i++ ) t[ i + 1 ] = ( t[ i ] / gcd( t[ i ],t[ i + 1 ] ) ) * t[ i + 1 ] ; printf("%I64d\n",t[ i ] ); instead of for( i = 1; i <= size - 1; i++ ) t[ i ] = ( t[ i ] / gcd( t[ i ],t[ i + 1 ] ) ) * t[ i + 1 ] ; printf("%I64d\n",t[ i - 1 ] ); Edited by author 26.08.2007 14:50 I get CE in the next time. Judge said this: 03cfd131-5f0d-45f4-91b6-d6962d109aa7.obj : error LNK2019: unresolved external symbol _itoa referenced in function "void __cdecl init(void)" (?init@@YAXXZ) I already linked up <stdio.h> and <stdlib.h> but this didn't help. Please help me. i write program which have wa#1 "But it appeared that among those problems there were some, which have the analogous solutions." for me it's very difficult to understand such situation: solution of problem A is "analogous" to solution of problem B and solution of problem B is "analogous" to solution of problem C BUT solution of problem A is NOT "analogous" to solution of problem C in other words relation "analogous" is not transitive this fact must be clarified in the problem statement |
|