Common Boardtest 6 is something like this: 1 1 . answer: 1 1 1 I got TLE 15 times beacuse of this test! hi,friend how to get the damn test data i TLE on test 1 many time Thank you!! You've saved me. :) check your solution for this case: 0 0 1 0 0 1 1 1 answer is -1. How to optimize my code? I know there is a lot of convertions from one type to another. How to avoid it? Or problem of speed not in convertions? import sys, re, math str1 = str(sys.stdin.readlines()) Data = re.findall('\\b\\d+\\b', str1) for i in reversed (Data): print('%.4f' % math.sqrt(float(i))) Edited by author 19.02.2013 23:58 solution, which worktime is 1.85 import sys, re from math import sqrt as sq def find_numbers(f): for line in f: for word in line.split(): if word.isdigit(): yield float(word) lst = list(find_numbers(sys.stdin)) lst.reverse() for x in lst: print('%.4f' % sq(x)) I send my solution for problem 1837 in Java and got this. I used in my program Collections.sort, sun.misc.Queue, HashMap. Can anyone help me? From the sample test and the test on board (a = 10000 and b = 1), I have worked out the solution by guessing, and ACed online. For input a and b, the solution is: (a ^ 2 + b ^ 2) / 4 + Sqrt(2) * a * b / 2 However, I could not find the proof for this. Any help or suggestion for me? Write your e-mail. I will help you. S = F(alfa, betta), where alfa is angle of stick a, and betta is angle of stick b. It it requirement for extremum of such function that both partial derivatives (dS/dalfa and dS/dbetta) is zeros. From these two equations you could find that angle between a and b is constant, regardless of their lengthes. Using new formula and getting it's derivative, it's quite simple to show that length from zero point to touching point between stick and tree and length between zero point and touching point between 2nd stick and ground is equal. Also we know hypotenuse of this rectangular isosceles triangle because we know a, b and angle between. S = sum of S of two totaly determined triangles and it is exactly the formula you wrote. Edited by author 30.01.2012 14:21 Thanks so much, to both Neofit and Anatoly. I have followed the ideas of Anatoly, and finished the proof. This is really a good geometric problem! Anatoly, could you explain how sticks should been placed in task example? I even couldn't imagine how to place 2 sticks to get total square more than 4 (rectangle). // S(x, a, b) + x * x / 4 max. // sqrt((x + a + b) * (x + a - b) * (x + b - a) * (a + b - x)) + x * x // 2*x + 1/2 * (-2x * (x * x - (a-b) * (a-b)) + 2x * (-x * x + (a+b) * (a+b))) / sqrt(...) = 0 // 2*x + (-x * (x * x - (a-b) * (a-b)) + x * (-x * x + (a+b) * (a+b))) / sqrt(...) = 0 // delete x // 2 + (2*(a*a + b*b) - 2*x*x) / sqrt(...) = 0 // 1 + ((a*a + b*b) - x * x) / sqrt(...) = 0 // x^2 - (a^2 + b^2) = sqrt(...) // (x^2 - (a^2 + b^2)) ^ 2 = (x ^ 2 - (a - b) ^ 2) * ((a + b) ^ 2 - x ^ 2) // y = x^2 // (a*a + b*b))^2 - 2*(a*a + b*b) * y + y*y = -y*y + (2*(a*a + b*b)) * y - (a*a - b*b) ^ 2 // 2*y*y - 4*(a*a + b*b)*y + 2*(a^4 + b^4) = 0 // y^2 - 2(a^2 + b^2)y + (a^4 + b^4) = 0 // D/2 = 2(ab)^2 // y = (a^2+b^2 (+-) ab*sqrt(2)) // Smax = (2y - (a^2+b^2)) / 4 = (a^2+b^2)/4 + ab/sqrt(2) printf("%.18lf\n", (a * a + b * b) / 4 + (a * b) / sqrt(2.0));
it's the part of my solution and explanation of this formula. My solution and explanation gets about 5-7 lines of text :)It's so easy Can you post the mathematical explanation of your solution? It is very tempting to start solving using angles. But I would advice you to start with distances from the origin along x and y directions (say x and y). Following steps should easily guide you to the answer. 1) Area = 1/2*(xy+ ab Sin(ArcCos([a^2+b^2-x^2-y^2]/[2ab]))) 2) Using partial derivatives show x=y 3) substitute x=y in area and using first derivative of area show that x^2= [a^2+b^2+sqrt(2)ab]/2 4) Substituting y=x and the result from (3) Area =[a^2+b^2]/4 + ab/sqrt(2) Edited by author 08.02.2013 15:38 1)I can compute the partial derivative of the area function. How do you prove that x=y 2)I can compute the derivative of the area function with x=y but how do you prove that x^2= [a^2+b^2+sqrt(2)ab]/2 code1, code2 = [int(x) for x in input().split()] if not (int(code1) % 2) or (int(code2) % 2): print("yes") else: print("no") #What's wrong? in this task i should use: code1 = input() code2 = input() except of: code1, code2 = [int(x) for x in input().split()] assembler :))) Now it is impossible because of other compilator and type of compilation. This test helped me with WA#17: 5 5 1 right answer is 9 Some more tests, just in case 123 554 340 >10 123 554 300 >9 23 554 300 >8 1515 1414 3424 >10 9 9 100 >-1 19 9 100 >16 1 1 18 >16 What 's special in 18'th test? Hallo. I have already solved this problem, but I want try to do it on different languages. So I need help with VB.NET 2010. Explain me, please, how I should read the input data. Компилирую на компьютере, все нормально. Но на проверке ломается на первом же тесте. #include <stdio.h> #include <conio.h> main() { char A[999]; int i=0, s=0, n=0; for (i=0;i<=999;i++) { A[i]='\n'; } while (s!=1) { scanf("%c", &A[i]); if (A[i]=='\n') {s=1; n=i;} i++; } s=0; for (i=0;i<=n;i++) { switch (A[i]) { case 'c': case 'f': case 'i': case 'l': case 'o': case 'r': case 'u': case 'x': case '!': s=s+3; break; case 'b': case 'e': case 'h': case 'k': case 'n': case 'q': case 't': case 'w': case 'z': case ',': s=s+2 ; break; case 'a': case 'd': case 'g': case 'j': case 'm': case 'p': case 's': case 'v': case 'y': case '.': case ' ': s=s+1 ; break; } } printf ("%d", s); } I used Djkstra search. Why didn't this work? By the way, is 1<=K<=1000 or K may become zero or negative? What's wrong? Can anyone give me a test The k can't be negative, it means the number of the plat. Sample Input: Sample Output: 6 2 3 2 3 RT, 2 4 RT, 3 3 , 3 4 B, 4 2 , 4 3 . I just wonder why there is only one comma on the end. It seems that there should be two - first for squere "4 2" and second squere "3 4". So my question is what does this last comma referrs to ? And obvious - why the other comma isn't in the output ? Thank You. Mike Read correct the task !! There you can see that then last line contains '.' not ',' ! Point ends last line of input. Last line is NOT ONLY POINT! Last line may be the following: RT. POINT using at the last line instead of comma. well i think it must be '.' at last.. because if it can go on .. it will print R L T B .. when print '.' it means at this time it can't go ... Hey everyone, I'm very frustrated. I spent couple hours on this problem and couldn't get it in Java. it's always WA#2. Can anyone give me some test data? I know that input can be any of the two representations, and all test cases given in threads are passed. I have really no clue, what's going on. I also checked for line breaks in input and output files. nothing works Image in first format: 10 1 1 1 2 2 2 2 3 2 4 2 5 3 1 3 2 4 2 4 3 Image in second format: 1 1 T, R, RT, RB, T, T, , T, , . Sorry for late reply! Yes, that's exactly what I get. I don't think that the problem is within algo... I think there is some stupid mistake... something like extra line break or something else... =( The point is to read the statement thoroughly, more precise: Input One representation of the image will be given to your program in the input. Output Your program has to write other representation of the image to the output. I guess you can apply it yourself! I said that: "I know that input can be any of the two representations, and all test cases given in threads are passed." Read carefully before saying something... I'm really agree with you!!!And now I haven't fixed my WA2 yet!!!How can that be!!Could you give me some idea,ile?I have checked my code for a few days... Does the problem statement meant that each member should have all his friends in the other team OR each member should have at least 1 friend in the other team ? If the first statement is correct the sample output does not hold. Please clarify. Thanks in advance Edited by author 17.02.2013 01:32 > If the first statement is correct the sample output does not hold. Then how do you think which statement is correct? :) #include <iostream> #include <cmath> int i=0; using namespace std; void f(); int main() { cout.setf( ios::fixed ); cout.precision( 4 ); f(); return 0; } void f() { long int a; if (cin >> a) f(); if (i!=0) { cout << sqrt((double)a) << endl;} else i++; } use long long int instead of int , it may help.. Edited by author 20.08.2006 07:47 |
|