Common BoardПочему моя программа выдаёт неправельный ответ на 6 вопрос? Looks like there is some bug in it =))) program p1; type tabel=array[-100..100] of byte; var r,eror,s,a,c,i,num,b:integer; n,pr:string; x:tabel; procedure insertare(var t:tabel; f:string; p:integer); var q,e,i:integer; begin for i:=1 to length(f) do begin s:=0; val(f[length(f)-i+1],q,e); if t[i+p-1]+q+s<=9 then begin t[i+p-1]:=t[-1+i+p]+q+s; s:=0; end else begin t[i+p-1]:=t[i+p-1]+q+s-10; s:=1; end; end; while s<>0 do begin inc(i); if t[i+p-1]+s<=9 then begin t[i+p-1]:=t[i+p-1]+s; s:=0; end else begin t[i+p-1]:=t[i+p-1]+s-10; s:=1; end; end; end; begin s:=0; for i:=-100 to 100 do x[i]:=0; readln(num); for i:=1 to num do begin readln(n); a:=pos('e',n); val(copy(n,pos('e',n)+1,length(n)),b,eror); if pos('.',n)<>0 then begin pr:=copy(n,1,pos('.',n)-1); insertare(x,pr,b); pr:=copy(n,pos('.',n)+1,a-pos('.',n)-1); insertare(x,pr,b-(a-pos('.',n)-1)); end else begin pr:=copy(n,1,pos('e',n)-1); insertare(x,pr,b); end; end; for i:=100 downto -100 do if x[i]<>0 then if x[i-20]>5 then insertare(x,'1',i-19); for i:=100 downto -100 do if x[i]<>0 then begin write(x[i],'.'); for c:=i-1 downto i-19 do write(x[c]); write('e'); if i<>0 then write(i); break; end; readln; end. Why, test please and tell me why it don't work Always WA at #18 I gave it everything I have. Resolve the formula group. Iterate to 1e-15. Still WA. Any hints? Thanks Edited by author 05.04.2013 23:37 Iterative schemes are unstable (small deviations from equilibrium in neighbor nodes lead to large error in final solution), so stupid iteration is hard to get AC here. Better reduce the problem to linear system and solve it honestly, or reduce it to matrix multiplications (even in this case you need some streetmagic to beat accuracy!) Thanks, Vedernikoff I resolved the linear formulations, but WA#18. Then I add some iterations afterward to 1e-14. Still failing. I'm now planning to pure iterations. The initial state doesn't matter, I think. So I'm gonna start from 1/64 in every cell. public class T_1219_Symbolic_Sequence { public static void main(String[] args) { PrintWriter pw= new PrintWriter(new OutputStreamWriter(System.out)); Random r= new Random(); char a[]=new char[30]; int k = 0 ; for (char j ='a'; j <='z'; j++) a[++k]=j; for (int i = 1; i <=1000000; i++) pw.print(a[r.nextInt(26)+1]); pw.close(); } } i used a df after i made an oriented graf(it's much easier to do than other solutions) if u did it better than O(N*N) please email me at dmarius1@yahoo.com Thanks Edited by author 15.04.2004 19:05 My decision not worse at all... At last! AC 0.001 and 394 KB I use dp O(n).ac in 0.0001s first,sort; second dp: answer=max{f(1)..f(n)}; f(i) means the best sum from the i one If you use sorting, it must be at least O(n*logn) I used sorting and then found the LIS in O(nlogn) time, 0.031 seconds We'd better dynamically allocate the array, which is too large. Edited by author 07.04.2013 13:13 GIVE ME SOME TESTS 41,40 100,40 40,100 60,60 73,68 Can anyone please give me a hint to solve this problem. Please dont give the recurrence. Thank you. Let project all segments to some line (x,y --> z=ax+by) and try all pairs of segments, which have an intersection of projections. To do it just sort events "open segment", "close segment" and brute force pairs. You will get TL. Yet. Now let try 4 lines: (a,b) = (1,0) (0,1) (1,1) (1,-1). At first, let estimate number of pairs to process for each line in O(nlogn) time. Now that we may choose line, which produces minimal mumber of pairs. AC in 0.937 seconds. id = 4870936. I am getting TLE on test 24. How will you choose from which town to start? Because of this I had to start from every town to find the answer. For each town it took me O(n),so for all the towns it becomes O(n^2), causing TLE. Actually that's the main issue for this problem. If you want a hint - that's it: try to develop some dynamic programming scheme for solution. Edited by author 05.04.2013 16:20 Edited by author 05.04.2013 16:20 Finally AC! Slight implementation change got me AC!. Edited by author 05.04.2013 16:19 Edited by author 05.04.2013 16:19 I don't understand what's the hint in this problem! I read it and I think this code must be enough to solve that problem in c#: using System; namespace ConsoleApplication1 { class Program1243 { static void Main() { ulong n = Convert.ToUInt64(Console.ReadLine()); Console.WriteLine(n%7);
} } } But I get WA#5. And I don't understand! Can someone help me? . . .
10^50 does not fit into UInt64. BigInteger integer does. However you could try to divide string by 7, or use some more sophiscated math (O(N), no divisions at all). OZone UTF-8 5 Apr 2013 02:54 Please add UTF-8 encoding HTTP tag to http://acm.timus.ru/getsubmit.aspx so we could see our comments written in native languages. At least for C#. Or just to files that were submitted with UTF-8 preamble. I'm using only notepad. 29 lines. Got AC after first sending. :-) This problem is so easy, so you should not think that all this is because you are a true-coder. we so proud of you. better tell what you did for solve that problem except just telling why you awesome, coz it does not make other people happy. WA#4 was because I didn't count last partially filled line. WA#10 was because I've got overflow in the following test: 1 3 4 a aaa aaa aaa Should be 4, but I had 2. [code deleted] Edited by moderator 01.12.2019 21:24 сделайте массив побольше) char s[101] Edited by author 04.06.2012 14:33 [code deleted] There is a error with c[100], but c[101] can work... I can't understand. Edited by moderator 01.12.2019 21:25 Additional 1 is for null-terminating character. My algo works with 255 Kb memory and 1ms. what can I improve in code to get ~120 KB, as in best results? [code deleted] Edited by moderator 04.12.2019 20:44 1) You don't need d. 2) If you'd like to improve speed even further, I suggest you to flag out elements in P that you have reached. In this case you'll get O(N) instead of O(N^2). What's the answer for this test? 3 1 1 1 25000000 10001 1 1 -90000 -999890001 I'm using BigInteger arithmethic and BinSearch, but still WA2... 1) D<0: answer 1 2) sum(0, k-1):f(x1+i) -> as result, we need to compare a^2*(2*k-1)^2 and 9*D what's wrong? Edited by author 03.04.2013 18:40 Output of my (AC) program: 1 2 190523 I used standard C++ double type to solve it - it seems there're no difficult tests that fail it (or such tests are just impossible) BTW, for the case (2) my solution considers two different cases I found bug in logic, but still... 1) D<0: 1 2) a) sum(0, k-1):f(x0+0.5+i) -> as result, we need to compare F(x0+0.5) and a*(k-1)/2.0 + a*(k-1)*(2*k-1)/6.0 -> then multiply by 2 b) sum(0, k-1):f(x0+i) -> as result, we need to compare F(x0)/2.0 and a*(k-1)*(2*k-1)/6.0 -> then multiply by 2 and substract 1 Some more tests: 7 1 1 0 1 6 -9 1 0 -1 1 1000000000 -1000000000 1000000000 -1000000000 -1000000000 1234 987654321 -987654321 100000000 987654321 -987654321 |
|