Общий форумI got WA 1. I think this problem is, easy but WA 1!!! I was also getting WA on test case 1.The correct pattern for 7 is- 7 1 1 1 0 1 1 1 1 1 0 0 0 1 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1 1 1 0 0 0 1 1 1 1 1 0 1 1 1 at first it seems - 7 1 1 1 0 1 1 1 1 0 0 0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 1 1 1 1 0 1 1 1 Edited by author 09.06.2005 16:00 I had this stupid WA I printed "No solution7" I didn't really got it. Can anyone explain it more? You can simply consider strings that consist of 0 and 1s. It won't make any change to the problem. import string def excute(): line = raw_input(); my_array = line.split(); result = 2; for element in my_array: # print element; result = result*string.atoi(element); print result; return 0; if __name__ == '__main__': excute(); Edited by author 03.04.2016 11:22 Edited by author 03.04.2016 11:23 caused by printed new line i solved this by using Optimized backtracking and i don't understand why it needs DP? I've done with DP in 0.001 sec It's very difficult to explain how you can get this formula. Maybe you'll understand : Just it necessary to know how many new numbers you can get with knowing that numbers having 0 in the end give less than numbers having any another digit in the end. Sorry if I have some mistakes in it. I have solved it both ways with DP and BackTracking, my question is aren't limits to easy to pass? I know that my algorithm exactly correct but only mathematically but not in program var n1:longword; function max(n:longword):word; begin max:=max+(n mod 2); if (n<>1) then if n mod 2=0 then max(n div 2) else begin max(n div 2); max((n div 2)+1); end; end; begin readln(n1); writeln(max(n1)); readln; end. Maybe I do not fully understand how do recursive functions operate. Edited by author 02.04.2016 15:07 If you change word to longint, it returns even more~ Even if you leave just function max(n:longword):word; begin max:=max+(n mod 2); end; , it will return an enormous number. Because, you see, in this very first row, you try to assign the function its own value (plus something). But it might be initialized in its own mysterious ways. So it's not how you do it. So uh... i solved this one long ago without any recursion, and i'm not quite sure what you're trying to do, but i modified it a bit, so at least it's trying to make some sense (even though it returns the wrong result still; but it's not that bad anymore, and maybe you'll be able to fix it into a proper version). So there you go. function max(n:longint):longint; var funcRes: longint; begin funcRes:=(n mod 2); if (n <> 1) then if n mod 2 = 0 then inc(funcRes, max(n div 2)) else begin inc(funcRes, max(n div 2)); inc(funcRes, max((n div 2)+1)); end; max:=funcRes; end; Thank you very much. I understood No problem. If you want to use recursion for calculations, maybe i'd suggest something like this: var i, n1, r1, maximum: longint; function x(p: longint): longint; begin if p <= 1 then x:=p else if p mod 2 = 0 then x:=x(p div 2) else x:=x(p div 2) + x(p div 2 + 1); end; begin readln(n1); maximum:=0; for i:=0 to n1 do begin r1:=x(i); if maximum < r1 then maximum:=r1; end; writeln(maximum); readln; end. But i think it's kinda slower than if you'd just precalculated the array, and then precalculated another array for maximums. It was quite likely harder back in the days, with 64kb turbo pascal limitations and all, so maybe you'd have to use smarter ways, rather than those blunt ones nowadays~ I meant I understood that I've used wrong way to get maximum. By the way I accidentally started to write a program that prints out the number from this sequence. And namely this way I think would be good to solve it. I was interested to write such a program and that's what I got: var n:longword; r:word; procedure max(n1,n2:word; var res:word); begin if n1 and (n1-1)=0 then inc(res) else if n1=3 then inc(res,2) else if n1 mod 2=0 then max(n1 div 2,0,res) else max(n1 div 2, (n1 div 2)+1,res); if n2<>0 then if n2 and (n2-1)=0 then inc(res) else if n2=3 then inc(res,2) else if n2 mod 2=0 then max(n2 div 2,0,res) else max(n2 div 2, (n2 div 2)+1,res); end; begin readln(n); if n=1 then writeln(1) else if n and (n-1)=0 then writeln(1) else if n mod 2=0 then begin max(n div 2,0,r); writeln(r); end else begin max(n div 2, (n div 2)+1,r); writeln(r); end; readln; end. Also div 2 can be shl 1 Edited by author 02.04.2016 20:42 Edited by author 02.04.2016 20:44 Write numbers from 1 to n, that's enough! You should be accepted. > Write numbers from 1 to n, that's enough! You should be > accepted. Write numbers from 1 to n, that's enough! You should MUST be accepted. THANK YOU VERY MUCH! > Write numbers from 1 to n, that's enough! You should be > accepted. Right. But plainly saying that it works (and it does) spoils the fun. And fun is to figure out WHY it works. I think we can't know why this work. We must check this solution on all tests [1, 1 2, 1 2 3, ..., 1 2 ... 1000]. If solution works on all tests it means that solution is right. you say write num from 1 to n, but the example.... it's very simple, I think Quick_sort procedure and it are very much the same, Yeah , better to guess yourself what is variable c. Please don't put in forum your very simple solving ? Just send one more time) (If your time 0.015) По условию ki<=100 => можно поддерживать степень каждого простого числа; при включении или отключении опции мы уменьшаем степень или увеличиваем на соотв. число. В чём обман не знаю. Хотелось бы получить тесты,т.к. на мою фантазию прога работает. const NMAX=105000; MMAX=100; LMAX=10; var a,ki:array[1..NMAX] of int64; step:array[1..MMAX] of int64; step26:array[0..LMAX] of int64; p:array[1..MMAX] of longint; N,i,j,r,m,t:longint; W,H,p0,key,k,res:int64; f:boolean; s,s1:string; procedure QSort(L,R:longint); var i,j:longint; X,Y:int64; begin X:=A[random(r+1-l)+l]; i:=L; j:=R; while i<=j do begin while A[i]<X do i:=i+1; while A[j]>X do j:=j-1; if i<=j then begin y:=A[i]; A[i]:=A[j]; A[j]:=y; y:=ki[i]; ki[i]:=ki[j]; ki[j]:=y; i:=i+1; j:=j-1; end; end; if L<j then QSort(L,j); if i<R then QSort(i,R); end; function Hash(s:string):int64; var i,len:longint; z:int64; begin z:=0; len:=length(s); for i:=0 to len-1 do inc(z,(ord(s[len-i])-ord('a'))*step26[i]); Hash:=z; end;
function Search(L,R:longint;key:int64):int64; var m:longint; begin while(R-L>1) do begin m:=(L+R) div 2; if(a[m]<=key) then L:=m else R:=m; end;
if(a[L]=key) then Search:=ki[L] else Search:=ki[R]; end;
procedure Update(x:int64;sgn:longint); var i:longint; begin i:=1; while(i<=r) do begin while(x mod p[i]=0) do begin x:=x div p[i]; inc(step[i],sgn); end; inc(i); end; end;
BEGIN randomize; r:=1; p[r]:=2; for i:=3 to MMAX do begin f:=true; for j:=2 to i-1 do if(i mod j=0) then f:=false; if(f) then begin inc(r); p[r]:=i; end; end;
for i:=1 to r do step[i]:=0;
step26[0]:=1; for i:=1 to LMAX do step26[i]:=step26[i-1]*26;
readln(N); for i:=1 to N do begin readln(s); t:=pos(' ',s); s1:=copy(s,1,t-1); delete(s,1,t); val(s,ki[i],t); a[i]:=Hash(s1); Update(ki[i],1); end;
Qsort(1,N);
readln(W,H,p0); readln(m);
res:=W*H; i:=1; while(res<=p0)and(i<=r) do begin j:=step[i]; while(j>0)and(res<=p0) do begin res:=res*p[i];dec(j);end; inc(i); end;
if(p0<10*res) then writeln('Slideshow'); if(p0>=10*res)and(p0<60*res) then writeln('So-so'); if(p0>60*res) then writeln('Perfect');
for i:=1 to m do begin readln(s); if(s[2]='n') then begin t:=pos(' ',s); delete(s,1,t); key:=Hash(s); k:=Search(1,N,key); Update(k,1); end; if(s[2]='f') then begin t:=pos(' ',s); delete(s,1,t); key:=Hash(s); k:=Search(1,N,key); Update(k,-1); end; if(s[1]='R') then begin t:=pos(' ',s); delete(s,1,t); t:=pos(' ',s); s1:=copy(s,1,t-1); delete(s,1,t); val(s1,w,t); val(s,h,t); end;
res:=W*H; t:=1; while(res<=p0)and(t<=r) do begin j:=step[t]; while(j>0)and(res<=p0) do begin res:=res*p[t];dec(j);end; inc(t); end;
if(p0<10*res) then writeln('Slideshow'); if(p0>=10*res)and(p0<60*res) then writeln('So-so'); if(p0>60*res) then writeln('Perfect'); end; END. Банальное (p0>60*res) -> (p0>=60*res) в двух местах. Если будет время, напиши мне пожалуйста? Что именно написать : как я решать пытаюсь, вердикты на попытки или что-то ещё? На емайл, т. к. есть вопрос по другой задаче. Сам отвечу себе))) Ошибка находилась в строках if(s[2]='f') then begin ... и if(s[1]='R') then begin ..., т.к. в первом условии s менялось и могло попасть во второе или третье; P.S. задачу сдал без хэшей: можно просто отсортировать строки. Возможно, участникам проекта будет интересен сайт одного из бывших олимпиадников. На сайте http://zealcomputing.ru/ обсуждаются различиные вопросы, связанные с программированием алгоритмов. Постепенно появляется новый материал, в том числе интересный будущим профессиональным программистам. Please, help me understand, how turn on printf and scanf in my program. If I write : int Solution (int n, int a, int b) { return (2*n*a*b); } int main() { int n,a,b; scanf ("%d %d %d", &n, &a, &b); printf ("%d", Solution (n,a,b)); return 0; } system will throw "Compilation error" with vtje2d-4h6iqg.cpp(9) : error C3861: 'scanf': identifier not found vtje2d-4h6iqg.cpp(10) : error C3861: 'printf': identifier not found. If i write the same, with #include "stdafx.h" on the top, system will throw "Compilation error" with rvkkio-7db2pu.cpp(4) : fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory #include <cstdio> Edited by author 30.03.2016 12:44 var n: integer; begin readln(n); if (n>=1) and (n<=4) then writeln('few'); if (n>=5) and (n<=9) then writeln('several'); if (n>=10) and (n<=19) then writeln('pack'); if (n>=20) and (n<=49) then writeln('lots'); if (n>=50) and (n<=99) then writeln('horde'); if (n>=100) and (n<=249) then writeln('throng'); if (n>=250) and (n<=499) then writeln('swarm'); if (n>=500) and (n<=999) then writeln('zounds'); if n>=1000 then writeln('legion'); end. will be better with CASE OF IMHO, using CASE OF operator, You'll get more esthetic look, no more. And insignificant advantage in performance. IlushaMax, could you check message year and don't answer if message is 2 (or more) years old? Thanks in advance. My program works fine in console, but for some reason I get wrong answer on test 9. Could someone point out where is the problem in my code? #include <iostream> #include <vector> #include <math.h> #include <iomanip> using namespace std; int main() { double num; vector<long long> input; int limit = 256 * 1024 / sizeof(long long); for (int k = 0; (cin >> num) && k <= limit; k++) { if (num != (long long)num || num < 0 || num > pow(10.0, 18)) return 0; input.push_back((long long)num); } for (int i = input.size() - 1; i >= 0; i--) cout << fixed << setprecision(4) << sqrt(input[i]) << endl; return 0; } Edited by author 28.03.2016 23:17 Edited by author 28.03.2016 23:18 Edited by author 28.03.2016 23:18 Limit is wrong. Min number size is 2 bytes - "1 ". In common, you shouldn't check if input is correct. It's supposed to be always correct. Reading like: while (cin >> number) { input.push_back(number); } should be enough. If you want to check input (for lulz?) you should fail your program in more visible way - via return not 0, throw something etc. Judge system will return another error, not WA. Edited by author 28.03.2016 23:43 Another note. You read number into double, convert it into long long, convert it back to double and finally call sqrt. Why do you need 2 conversions in the middle? Shouldn't you better use vector<double> input? Sorry for stupid question: what is WA? Никак не пойму,что обозначает "Во всех тестах, кроме первого, расстановки зашифрованы. Вы не должны пытаться расшифровывать эти данные (и не обязаны их считывать), однако наличие во вводе этой информации позволяет нам гарантировать, что в этой задаче заранее определённые тесты, которые не подстраиваются под вашу стратегию." Как выглядят эти данные и влияют ли они на решение? И вопрос тем,кто решил-всегда ли мы можем "угадать в среднем",что у нас в очередной игре ровно один 0(или 1)? P.S. Пока дошёл только до 70 теста P.S. Уже решил.Не заметил одну особенность. Edited by author 25.10.2015 00:00 The solution is independent to this data. It's hard to provide test data to checker programm and not to provide it to participant. Can you tell what feature you found? I still have WA 70 too and need any idea to improve my program. I have one question. If there are three balls: 1st - black, 2nd - white and 3rd - unknown color, is it possible to find numbers of 2 balls of the same color or no? Obviously it's not possible if you talk of a 100% chance. Then how can we guess it with 80% chance? I thought that we always can determine these positions with 100%. Correct me if I am wrong. «I thought that we always can determine these positions with 100%. Correct me if I am wrong.» Yes, you are wrong. Hint: try to think of a certain specific test that will aim to fail your algo. More particularly, even your test above will do — black, white, unknown. We have options of <1 2> (obviously wrong), <1 3> (wrong if 3 is white) and <2 3> (wrong if 3 is black). So we can't guess with a 100% chance. Anyways, here's that very minor hint i can give: use random(). Edited by author 28.03.2016 17:12 Thanks, I just wanted to know in what direction to think further... Edited by author 28.03.2016 17:44 Edited by author 28.03.2016 17:44 Lost ac. WA 17 Looks like it isn't "n<=0", it isn't about integer overflow during even-length sequence overflow calculation. Edit: oh alright, congratulations. Edited by author 28.03.2016 16:15 Thanks, finally got AC. Was childish error in checking if N is odd or even. Hi , What IDE or Editor or Online Interpreter do you guys use for Python? Please help! Thanks in advance Why constraints are so small? My algo is O(max(a,b,c)). I always WA#2 Edited by author 27.02.2016 15:28 Edited by author 27.02.2016 15:30 Yes you can, in practice it will be max value of type used for storing straw height. Do strings consist of only lower-case letters of latin alphabet ? |
|