Common Board| Show all threads Hide all threads Show all messages Hide all messages | | About condition... | bsu.mmf.team | 1814. Continued Fraction | 11 Feb 2011 16:15 | 1 | The statement of the problem says: "Output the value of the convergent continued fraction of order k of the square root of x as an IRREDUCIBLE fraction." But it is well-known, that every such convergent fraction is irreducible. However after taking modulo it may become reducible. So I thought I should reduce the answer in this case. But it is not true! You don't have to do it. Otherwise you'll get WA#8. May admins clarify this misunderstanding somehow, please? | | Why? | muhammad | 1358. Cables | 11 Feb 2011 16:13 | 1 | Why? muhammad 11 Feb 2011 16:13 I do not know why I got AC !!! why log doesn't work and exp works? | | Hint | ASK | 1111. Squares | 11 Feb 2011 15:29 | 2 | Hint ASK 24 Mar 2010 18:15 To calculate the distance, rotate the square and the point so that the diagonal (if it is not a zero vector) becomes parallel to (1,1). In this case sides of the square are parallel to axes and the distance is trivial to calculate. The problem can be solved without floating point operations: the square of the distance is a rational number. But note that to compare (an/ad < bn/bd) you cannot use (an*bd < bn*ad) since the products can overflow 64-bit integers. Instead first compare the integer parts, and in case they are equal to the same number, subtract this number from both parts and compare the results using multiplication (denominators are 32-bit integers). Re: Hint Phan Hoài Nam (Harvey Nash) 11 Feb 2011 15:29 Nice solution ! Edited by author 11.02.2011 15:53 | | Other ways of solution | Dima&Dima | 1542. Autocompletion | 11 Feb 2011 08:29 | 10 | Hallo all! I think here is only one solution for this problem. First of all sort incoming data in alphabetical order. Then choose words in second array. sort it by frequenscy. Take first 10 words and print them. And do not forget to sort word's with same frequency alphabeticaly. That's All. But when I implement whis algoritm it slove my test, slove test coming with problem, nevertheles it cannot pass first test at server. Can U advise me some other ways how to slow this problem. lbvf(dog)mail(point)ru All the Best to U... My algorithms is the same, but TLE on test 12 Maybe a main problem in sorting? I had WA 12 Hash codes of strings and qsort can help to increase speed of sorting, I think. I got TLE12, and don`t have a time during contest to rewrite my program. Maybe later I`ll try to solve it again. What kind of Hash codes did U use? I think your output file has one more empty line, when I had such code I had WA1, now I'm one of the many TL12- ers :( I built characters tree for request and almost beaten the top with it )) Hash codes of strings and qsort can help to increase speed of sorting Really good hint! Thanks! Also this problem can be solved with segment tree and some preprocessing: 1) create array of pairs <string word,int frequency> and sort this array 2) build segment tree on maximum on frequences of sorted array 3) answering the query: find all words which matches the pattern - these words will be in one sequental interval because array sorted lexocographically,here example of finding this interval: L = lower_bound(array,array+n,make_pair(pattern,-INF))-array; //substraction pointers R = upper_bound(*,*,make_pair(pattern+"zzzzz_fill_until_max_len",+INF))-array; now we found all relevant words, let's choose 10 most frequent: 1 most frequent word - find_max_with_segment_tree(L,R) - also should return index of maximal element Now you should change maximal element to -INF in order to provide that second most frequent word will be founded by segment tree; change second to -INF and so on; after answering 10 questions just undo changes: you know old values and indices of altered elements, use this this information and restore segment tree. Edited by author 11.02.2011 08:31 I was using qsort. And testing how it sorts simple incoming data by the debuger, it was testing normaly. It's looks pretty mistical... I can belive in TLE, but WA in first test looks very strange. To find a problem at my code I want to create testing porgram that counts words in big Engish book. And then test A program on created test data. | | Problem 1542 Autocompletion. Time limit was changed | Vladimir Yakovlev (USU) | 1542. Autocompletion | 11 Feb 2011 01:13 | 1 | Time limit was reduced from 3 sec to 2 sec. Submissions were rejudged. 15 authors lost AC. Edited by author 11.02.2011 01:13 | | how you compare doubles? | Baurzhan | 1503. Polynomial | 10 Feb 2011 20:20 | 5 | Persons, who got AC without long arithmetics,tell me how did you comapre doubles? I used construction: fabs(r-l)>eps,where eps=1e-15, and i'm getting wa5 every time. Please,somebody, help me to find the bug, I need it in my work to solve polinomial of 5-th degree.My code available for looking - my judge id - 77493FG, password - shared, last submissions - 1503 problem. If somebody will find bug in my code,please write it on this thread. Edited by author 01.02.2011 09:52 I dont use binary-search with double all in my life but i think you can use long long instead of double, and for every expresion you devide the parameter by 10^7. like this: double a= 1.1234567; cout << a * 1e-1 << endl; ---> 0.11234567 you can use: long long a= 11234567; cout << ((long double)a * 1e-7) * 1e-1 ---> 0.11234567 I hope can help you Edited by author 10.02.2011 17:59 thanks for advice, but it seems impossible for me to use long long because my aim is not submit 1503 problem, but care about cases when coefficients of polinomial is large enough - 10^20,10^30 - i need it in my work.Long long doesn't allow to store such large numbers as I need. Also, I red in the forum that somobody accepted this problem with algorithm similar to mine, so my approach is correct but has some troubles with precision. Anyway, a lot of thanks for advice! | | how to calcute C(n,k) ??? | hoan | | 10 Feb 2011 17:35 | 8 | Hi How to calcute c(n,r) modula p when p is prime. 1<= n,r<= 10^5. please give me a algo with inverse number! (thanx a lot) sorry for my poor english. thanks for your answer, but how to use this for calcute C(n,k) ? please answer to me. thanks!!! Let's make some denotations before starting. Let n! be up and k!*(n-k)! be down and c(n,k) be bc - short form of binomial coef, so we have up/down = bc. First af all, find the prime's degree both in up and down using Legendre's formula: degree_of_prime_in_x! = x/prime +x/prime^2+ x/prime^3 and so on, while x>=next_deg_of_ prime. You see, it works very fast, in log(factorial_value) by prime base. After that, we have two possible cases: 1) Degree of prime in up>the same thing in down; It means that after reduction up and down on p^degree_of_down_part we have up = p^delta_degree*some_int1/some_int2 = bc, where both some_int1 and some_int2 DON'T divide p but fraction some_int1/some_int2 is an integer. Obviously, bc%p=0 in this case because bc%p = (int_result_of_fraction*p^some_degree)%p = some_remainder*0 = 0; 2) degree in up = degree in down. So, up/down = (p^x*some_int1) / (p^x*some_int2) = bc; After reduction on p^x we have some_int1 = some_int2*bc, where both of some_ints don't divide p or, in other words, gcd(p,some_int1) = gcd(p,some_int2)=1; some_int_1 and some_int2 denoted as si1 and si2 in the rest part of text because i'm too lazy=) Let's take both part by modulo p: si1%p = (si2%p)*(bc%p) <=> si1%p = si2*answer_you_need, so, answer_you_need = si1%p*(1/si2%p) or answer_you_need=si1%p*(inverse_elem_to_si2_by_modulo_p); Now we are ready to use Fermat's little theorem: si2^p==si2(mod p), but we can use more stronger equation because gcd(si2,p)=1,as I mentioned 5 lines before. Stronger eq:si2^(p-1)==1(mod p); Please, note that stronger version is allowed only when gcd(si2,p)=1 thats why we started from boring reduction of prime component! we can divide both parts of comparison/equation/equivalence_relation on si2 and write something like that: si2^(p-2)==1/si2(mod p); you can ask, why division is allowed here but just believe me, it's just rule which yo can find and read in internet. so 1/si2(mod p) is inverse_element, so answer_you_need = si1%p*(inverse_elem) = si1%p*si2^(p-2); If p is large you can use fast_exp; si1%p ans si2%p calculated in ~linear time via stupid for loop: si1=1; for(int i=2;i<=n;i++){ tmp=i; if(i%p==0){ while(tmp%p==0) tmp/=p; // here tmp%p!=0 because while loop excluded p. } si1*=tmp; si1%=p; } P.S This loop was written considered deg_in_up=deg_in_down because when d_in_up>in_down you may return zero, I explained why. The same loop for si2 but you nedd 2 loops: i<n-r and i<r; P.P.S Please, answer to my question here http://acm.timus.ru/forum/thread.aspx?id=25978&upd=634327602601135000 or just advise me how avoid problems with precision in double_variables binary_search Edited by author 09.02.2011 23:55Something like this: int fact(int x, int mod) { if (x == 0) return 1; return (x * fact(x-1, mod)) % mod; } int pow(int x, int n, int mod) { if (n == 0) return 1; if (n % 2 == 0) { int tmp = pow(x, n/2, mod); return (tmp * tmp) % mod; } return (x * pow(x, n-1, mod)) % mod; } int c(int n, int k, int mod) { int up = fact(n, mod); int down = (fact(k, mod) * fact(n-k, mod)) % mod; int downInv = pow(down, mod-2, mod); return (up * downInv) % mod; } Wait... You have solved 290 problems, and you don't know how to calculate C(n,k)? in my solved problem there is no need to calcute c(n,k) for n bigger than 50, and for this question i use dynamic programming. thanks in advance and i dont forgot your help in my life ;D | | Keep WA #2...Help.. | caoyuan9642 | 1815. Farm in San Andreas | 10 Feb 2011 10:05 | 1 | What's wrong with #2? I've got 10+ WAs and found no real mistake yet.. | | WA#4, help!!!!!!!!!! here is my code | Bobur | 1604. Country of Fools | 10 Feb 2011 00:03 | 10 | var a, b, c : array [1..10000] of integer; k, n, s, i, j : integer; toq : boolean; procedure quicksort; procedure sort(l, r : integer); var i1, j1, x, w : integer; begin i1 := l; j1 := r; x := a[(l+r) div 2]; repeat while a[i1]<x do inc(i1); while x<a[j1] do dec(j1); if i1 <= j1 then begin w := a[i1]; a[i1] := a[j1]; a[j1] := w; w := b[i1]; b[i1] := b[j1]; b[j1] := w; inc(i1); dec(j1); end; until i1 > j1; if l < j1 then sort(l, j1); if i1 < r then sort(i1, r); end; begin sort(1, n); end;{quicksort} begin read(n); for k := 1 to n do begin read(a[k]); b[k] := k; end; s := 0; for k := 1 to n do s := s + a[k]; quicksort; toq := true; for k := 1 to n do begin if toq then begin j := 1; i := 1; while (i <= s) and (j <= a[k]) do begin c[i] := b[k]; inc(i, 2); inc(j); end; if i > s then toq := false; end; if toq = false then begin j := 1; i := 2; while (i <= s) and (j <= a[k]) do begin c[i] := b[k]; inc(i, 2); inc(j); end; end; end; for i := 1 to s do write(c[i], ' '); end. or smth wrong with my idea!!! check this test 3 5 8 10 correct answer 1 3 2 3 1 3 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 2 3 Edited by author 02.03.2008 21:38 And this: 3 1 2 5 Answer: 3 1 3 2 3 2 3 3 thx Bobur 19 Mar 2008 18:26 test : 3 5 8 10 answer: will be this answer correct too? 1 2 3 2 1 2 3 2 1 2 3 2 1 2 3 2 1 2 3 2 1 2 3 Edited by author 30.10.2008 11:39 and this? 3 5 8 10 answer: 3 2 3 2 3 2 3 1 3 2 3 1 2 3 1 2 3 1 2 3 1 2 3 //// SuperLight 8 Sep 2009 14:36 Test #4 is something like this: 2 5 1 answer: 1 2 1 1 1 1 Ans Test #6: 2 2 6 answer: 2 2 2 1 2 1 2 2 Edited by author 28.04.2010 14:40 Test 4 is something like this: (I fixed this when had WA4 and got WA26) 3 1 1 3 ------- 3 1 3 2 3 Edited by author 09.02.2011 23:51 AC now :) Edited by author 28.05.2011 17:05 | | Some hints for you ! | Phan Hoài Nam (Harvey Nash) | 1140. Swamp Incident | 9 Feb 2011 09:39 | 1 | - Calculate the x y coordinates of the student - Find the X, Y or Z axis nearest to the student (the axis that the student can go on it with least step). - Calculate the number of steps to nearest axis + the number of steps from new place in nearest axis to central cell. Note: On X axis : x = 0 On Y axis : x = y On Z axis : x = -y Least steps to X: x + step * xDir = 0 => step = ? Least steps to Y: x + step * xDir = y + step * yDir => step = ? Least steps to Z: x + step * xDir = - (y + step * yDir) => step = ? Of which: X axis : (xDir, yDir) = (0,2) Y axis : (xDir, yDir) = (1,1) Z axis : (xDir, yDir) = (1,-1) Chúc các bạn may mắn :) Edited by author 09.02.2011 09:40 Edited by author 09.02.2011 09:41 | | WA 23 | rohit | 1635. Mnemonics and Palindromes | 9 Feb 2011 00:56 | 1 | WA 23 rohit 9 Feb 2011 00:56 Can someone please tell me what the test 23 is ? My program passes all the tests given in forum. | | Thanks for rejudge | muhammad | 1684. Jack's Last Word | 8 Feb 2011 20:50 | 1 | my even very stupid silly mistake got ac previously. Case: abcd bcd or simply a b :ans must be yes! | | Can't pass test number 1 | Maximus | 1092. Transversal | 8 Feb 2011 19:43 | 1 | Edited by author 08.02.2011 19:51 | | WA30 | Borozdin Kirill | 1643. Attack of the Dark Fortress | 8 Feb 2011 16:20 | 1 | WA30 Borozdin Kirill 8 Feb 2011 16:20 | | Strange thing... | Alexander Samal | 1191. Catch the thief! | 8 Feb 2011 16:17 | 2 | If L == K, policeman doesn't catch the theif. I got AC when supposed so. Text from statement: "For instance, if L < K1, then it may happen that the policeman reaches the first stop when the robber is still waiting for a tram there." It means that you are right. | | Data is too weak!! | CodeChomper | 1005. Stone Pile | 8 Feb 2011 07:07 | 2 | Hello, administrator, I find this problem's data is too weak.Sometime before, I submitted my code to this problem, and got AC.Today, I sudden to realize my mistake, and I back to check my answer.Oh, my god, I had so stupid mistake.To my suprise, I had AC.So I think the problem's data is too weak.Please generate more strong input.. Hi! There seem to be many *accepted* solutions here that do not really try all possible combinations. These do *NOT* solve this problem, as some have pointed out correctly, this is a knapsack type of problem and unless going through all 2^n combinations of n numbers, you cannot find the optimal answer. It is clear, that the test data are too weak indeed!!! | | 1001 Crash HELP | Visual_Studio2010 | 1001. Reverse Root | 8 Feb 2011 01:55 | 2 | I used the vector to solve this problem, but the system told me "Crash". I want to know why, so sent help to you, thank you. Below is my solution: #include <iostream> #include <vector> #include <math.h> using namespace std; int main() { vector<double> doubleVector; int i = 0; double cinVector = 0; // Read in numbers while (cin >> cinVector) { doubleVector.push_back(cinVector); i++; } // Display the results while (i > 0) { cout << sqrt(doubleVector.at(i)) << endl; i--; } return 0; } In addition, what will cause the "Crash"? Edited by author 07.02.2011 23:58 Input: n numbers After 1st while cycle: i = n doubleVector.at(i) - crash because size = n and only doubleVector[n-1] exists. And you should print numbers with 4 digits after the decimal point. | | Explain tests plz. | Oleg Strekalovsky [Vologda SPU] | 1804. The Machinegunners in a Playoff | 7 Feb 2011 23:31 | 1 | DELETED Edited by author 07.02.2011 23:41 | | WA 5 | Muravjev Slava [Samara SAU] | 1067. Disk Tree | 7 Feb 2011 22:46 | 1 | WA 5 Muravjev Slava [Samara SAU] 7 Feb 2011 22:46 What is main mistake of programs, which has WA 5? If you can, write here the hardest or questionable tests, please. Edited by author 07.02.2011 22:48 | | it seems that the solution needs high precision operation? | fjxmyzwd | 1818. Fair Fishermen | 7 Feb 2011 20:24 | 1 | try it out: N=1000 999 "0"and a single "1" |
|
|