Common BoardFor God's sake, use ans/100 instead of ans*0.01f But i don't know why Maybe you forgot that the order of the numbers in the answer is important. you can implement your simple fraction class and use it instead of floating point numbers I don't know why, but in Python, code points of frame characters are: upper_left = 1066 upper_right = 1111 lower_left = 1040 lower_right = 1065 horizontal = 1044 vertical = 1110 That's really strange, because there are no common codecs encode those characters as such. Could Admin fix this or at lease give some explanations please? Also, don't put non-ascii characters in your source code, but use: c == chr(1066) or ord(c) == 1066 ord('┌') == 9484 list('┌'.encode('cp437')) == [218] list('┌'.encode('utf_16_le')) == [12, 37] # 12+37*256 == 9484 and Unicode code point is: U+250C == 9484 Any submission on Kotlin or Java return 'Restricted function' error. Even solutions that previously could pass at least some tests. Здравствуйте, решение из примеров для задачи "1000. A+B" object Main extends App { println(readLine().split(" ").map(_.toInt).sum) } выдает ошибку "Restricted function" Edited by author 23.06.2021 07:43 Edited by author 23.06.2021 07:43 Edited by author 23.06.2021 07:43 Remember: maximum accuracy can not be more than 10 in minus the secong degree. Запомните: максимальная точность числа не больше 10 в -2 степени. I have O(len(s) * k^2), and it is definitely too slow (TL#26). BTW, and here is some tests (don't want to create separate topic): 3 CC 00 1 01 ***** ans=-1 3 BAB 10 111 0 ***** ans=7 3 BA 00 01 1 ***** ans=3 3 CA 001 000 01 ***** ans=5 By applying suffix automaton, O(len(s) + k^2) complexity is received. Input: 3 '╣' like '[╣-I]' '╣' like '╣' '╣' like '_' Output: YES YES YES My AC solution gives NO to the first one; there should be no tests where the start character in a range is greater than the end character. 24 12 12 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Right Answer is 6 . - empty cage 1 - chess knight 2 - cells under attack 8 | . . . . . . . . 7 | . . . . . . . . 6 | . . 2 . 2 . . . 5 | . 2 . . . 2 . . 4 | . . . 1 . . . . 3 | . 2 . . . 2 . . 2 | . . 2 . 2 . . . 1 | . . . . . . . . ___________________ a b c d e f g h 1 2 3 4 5 6 7 8 is it possible to solve this problem with "smart" backtracking algo using a lot of restrictions ? As I know YES. But there easy and beautiful math solution. give me a hint how to solve it without using backtracking algorithm thank you ur e-mail ... Please send it to me too. eros_89@yandex.ru About math solution.. I am trying to it by the following way: Assume a connection between stops A and B. Then connection from B to A exists too. Then, to satisfy the problem's conditions, we have to introduce (2*n-1)*n connections (ordered in such a way that each tram route has 2*n-1 connections). All the connections are distinct. Next, each tram stop has exactly 2*n-1 connections to other distinct stops. It is always odd integer, so every tram stop must appear exactly once at the beginning of single route, and next time it must appear (2*n-2)/2=n-1 times in the middle of other routes. It is true for all the routes. So first we should build the following answer matrix if we consider n = 3: 1 x x x x 4 2 x x x x 5 3 x x x x 6 Then I am trying to place other elements to the matrix according to some placement rules from the thoughts above, but I am still unable to come up with a good solution. Could someone point out, am I going correct in my math thoughts or such approach leads to naive backtracking solution? Thanks! Sorry I was so verbose :D No more math is needed. Now you can use backtracking. I resisted the idea of writing a backtracking algo, but decided to implement it with rule of placing elements leftmost and outermost as you suggested and got AC :) Thank you. PS. I wonder if it is possible to write a backtracking solution without any initial placements or not. 2 Chmel_Tolstiy: Could you please give me small hint about a math solution? master.wsd064 (no spam) gmail.com Edited by author 03.04.2008 18:27 your Idea is a 2/3 of all way. just try to find a regularity between this paths. I think it's easy. naxart[at]yandex[dot]ru it's my email. I've found simple maths solution, here is my solution for n=3 1 2 3 4 5 6 2 4 6 1 3 5 3 6 2 5 1 4 Edited by author 02.06.2008 05:28 Edited by author 02.06.2008 05:28 There is no need for _smart_ backtracking. I placed 1..n on the left side and n..2n on the right side. Then I launched recursion over all cells row-by-row, column-by-column, taking every edge (i;j) exactly once, and it's AC in 0.078 sec. For n=100 there occurs only 562 returns. So, it's almost greedy algo. The only problem was expanding that recursion into a loop 'cuz I had stack overflow with 200x100 calls. Edited by author 25.07.2008 17:31 Continue filling the matrix from both left and right. Keep each pair of opposite columns contain every tram stops. I want to know too. pkkj@tom.com Thanks. Only math solution acceptable because this is structure design problem. I spent a lot of time but was unable to find it. Solution easy to find in internet with key words "decomposing complete graph in hamilton paths" Use diameters and walk left-rigth- down with respect to them. Edited by author 14.08.2009 11:02 no subject Edited by author 14.08.2009 11:03 Please I got Crash(Stack Overflow), I implemented my first heavy-light descomposition and tried this problem, but I got this. I got AC, I had to convert the DFS to BFS, to evade the StackOverflow. Edited by author 02.11.2011 04:45 Edited by author 02.11.2011 07:20 Edited by author 02.11.2011 08:20 {$m 100000000000000000000} You can use "G++ 9.2 x64" language to avoid it Sir Isaac Newton is important to this problem. In TWO different ways. Why WA 28?I don't understand. Here is my code: program gjkh; var a,b,ch,n,i,kol,sh,fir,sec,thi:longint; m:array[1..100001]of longint; flag:boolean; begin read(a);readln(b); n:=0; while not seekeof do begin read(ch); if (n=0)or(m[n]<>ch)then begin n:=n+1; m[n]:=ch; end; end; flag:=true; kol:=1; for i:=1 to n do begin if (i=1)then fir:=m[i] else begin if (flag=true)then begin sec:=m[i]; flag:=false; end else begin thi:=m[i]; if ((thi-sec)*(sec-fir)>0)then begin fir:=sec;sec:=thi; end else begin fir:=thi; kol:=kol+1; flag:=true; end; end; end; end; writeln(kol); end. 1 5 -100000 500000 -70000 800000 -80000 answ: 3 Edited by author 01.02.2010 18:44 Input numbers must not exceed 100000 by absolute value. why is 3, because there are 4 intervals? Edited by author 16.06.2021 15:21 Edited by author 16.06.2021 15:22 It means, each employee (except the director) has only one immediate superior. If employee A is superior to employee B, and employee C is superior to employee A, then C->A->B. Both C and A are superior to B, but only A is B's immediate superior. #include<algorithm> #include<cstdio> using namespace std; #define MAX_N 250000 int n, i, t1, t2; int *heap; int main(){ scanf("%d", &n); heap = new int[n/2+2]; for(i = 0; i < n/2+1; ++i){ scanf("%d", heap+i); push_heap(heap, heap+i+1); }
for(i = 0; i < n/2-(n+1)%2; ++i){ scanf("%d", heap+n/2+1); push_heap(heap, heap+n/2+2); pop_heap(heap, heap+n/2+2); } if(n%2){ printf("%d.0\n", heap[0]); }else{ t1 = heap[0]; pop_heap(heap, heap+n/2+1); t2 = heap[0]; if((t1+t2)%2){ printf("%d.5\n", t1/2+t2/2); }else{ printf("%d.0\n", t1/2+t2/2+t1%2); } } delete[] heap; return 0; } |
|