Общий форум| Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения | | How to avoid TLE? | Vedernikoff Sergey | 1464. Освещение | 17 авг 2012 15:15 | 7 | Some people claimed, that this problem can be solved in O(NlogN). How? My solution O(N^2) gets TLE #39... Thanks in advance! Sort all starts/ends by angle. Then track closest inner wall within every angular segment, use heap for that. Comparing segments in a heap can be done by comparing distance to ray intersection. Though rays will be different during segment's lifetime, relative order of segments along the ray will not change because segments do not intersect. I've implemented this approach, but I have WA#33. I make exact calcucations except finding the square of triangle in the angular segment. Can somebody help me to overcome the problems with precision? Or maybe there's some bug in my program... Edited by author 09.08.2009 21:21 Of course 2 segments compared once will never swap order; but suppose, there is an active segment in the heap whose end is not reached yet. However, another segment's start has come before in angle-wise sorted order. Now, when we enter that segment in the heap according to distance along current ray we have trouble; since, the previously mentioned segment's distance was calculated along old ray. Now, it may occur so that, the newly entered segment comes before along current ray, but previous segment might be popped before cause, its distance is less in heap - since, this is distance along old ray. And, there may be many such previous segments in the heap. I think, this gives same scenario as would be in case of intersection; and this is precisely what giving me WA 33. If, I update all existent segments in the heap by distance along current ray this gives the same effect as sorting edges each time and of course, gives me TLE 37 or 39. This is creeping me out. Sure, I am missing some trivial logic :( Please, help me out. Thanks in advance. This is part of the code I am trying on now: for(i=0;i<n;++i){ if(mark[arr[i].e1]) out(arr[i].e1); else in(arr[i].e1,(arr[i].ang+arr[i+1].ang)/2.0); if(mark[arr[i].e2]) out(arr[i].e2); else in(arr[i].e2,(arr[i].ang+arr[i+1].ang)/2.0); seg ret=heap_extract_max(); area+=triangle(make_pair(0.0,0.0),calc(ret.e,arr[i].ang),calc(ret.e,arr[i+1].ang)); in(ret.e,(arr[i+1].ang+arr[i+2].ang)/2.0); } Sorry, I did stupid mistake. I made distance of a segment along some ray an attribute of the segment structure which is inserted on heap and in operator<() I compared that attribute. That's obviously wrong; since, newly inserted segment has distance calculated along different ray and can't be compared with others that way. But, look, 'the ORDER of the all previously entered segments' is correct. So, all i have to do is, rather than making distance an attribute, compute it along current ray/angle each time operator<() is called. I think, that will fix WA 33 of anyone getting it :) | | Celebrating for my 100AC | OwenOu | 1297. Палиндромы | 17 авг 2012 14:37 | 2 | | | WA 5 | rakeshvarna | 1118. Нетривиальные числа | 17 авг 2012 14:07 | 2 | WA 5 rakeshvarna 27 дек 2010 21:40 HI I seem to be getting WA 5 everytime. Any ideas or hints on the test? Here is what i do: if start is 1 cout 1 for i=stop to start and for odd numbers for j= 2 to floor(sqrt(i)) add the divisors if it is a primeNumber cout<<i cout the number with least triviality. Re: WA 5 Vladimir Plyashkun [CSU] 17 авг 2012 14:07 in test5 I = J. Try this 2 2 aswear 2. Edited by author 17.08.2012 14:07 | | I solve using only integer arithmetics!!! | xurshid_n | 1637. Игра в треугольник 2 | 17 авг 2012 12:57 | 1 | | | Wrong answer. Why? | Alexandr | 1079. Максимум | 17 авг 2012 11:32 | 1 | #include <stdio.h> unsigned long get_an(unsigned long n); int main(){ unsigned long n[10],i; for(i=0; ; ++i){ scanf("%ld", &n[i]); if(!n[i]) break; n[i]=get_an(n[i]+n[i]%2-1); } for(i=0; n[i]; ++i) printf("%ld\n", n[i]); return 0; } unsigned long get_an(unsigned long n){ if(n==1) return 1; if(n%2) return ( get_an((n-1)/2)+get_an((n-1)/2+1) ); else return get_an(n/2); } | | WA #30 | Rouk | 1274. Fractional Arithmetic | 17 авг 2012 02:13 | 1 | I have WA #30, but on all tests and on same tests my solution give right answers. Can be there others tricks? | | speeding up the s0lut1on | Mr Chi | 1002. Телефонные номера | 17 авг 2012 01:55 | 2 | wondering, how can executing time = 0.001 sec be gained? or at least 0.015? Which struct dictionary should have? As for me, I used lower_bound to find out needed word in dictionary (::vector) in my solution and got 0.041 sec time (memory usage is not so interesting) 0.001 sec is impossible now. | | WA #1 Please help! | Rouk | 1274. Fractional Arithmetic | 16 авг 2012 15:05 | 1 | Hello! The code works correctly. Checked on many examples. Most likely something with input-output. Prompt, where it is wrong and how it is better to make fraction input? Code C++ Sorry for Russian comments //структура дроби struct Fractional { //объявление целой части, числителя и знаменателя long long intPart, numerator, denomerator; } _oneFract, _twoFract, _result; //функция считывания дроби Fractional ReadFractional() { Fractional _fract; //переменная _razdel определяет, что ввели: только целую часть, только дробную часть или целую и дробную часть char _razdel; //считываем первое число scanf("%lld%c",&_fract.intPart, &_razdel); //считываем разделитель после первой цифры: если нажат Enter, то число без дробной части, //если слеш, то только дробная часть, если пробел то и целая и дробная части присутствуют if (_razdel == '\n') { _fract.numerator = 0; _fract.denomerator = 1; } else if (_razdel == ' ') { //Считываем дробную часть scanf("%lld/%lld%*c", &_fract.numerator, &_fract.denomerator); if (_fract.denomerator == 0) _fract.denomerator = 1; } else if (_razdel == '/') { //Считываем знаменатель scanf("%lld%*c", &_fract.denomerator); if (_fract.denomerator == 0) _fract.denomerator = 1; _fract.numerator = _fract.intPart; _fract.intPart = 0; } //Сбрасываем входной поток fflush(stdin); return _fract; } | | WA 5 | minda ro bednieri iyo | 1752. Дерево 2 | 16 авг 2012 14:37 | 1 | WA 5 minda ro bednieri iyo 16 авг 2012 14:37 | | 2ADMINS: condition ambiguities | melkiy | 1039. Юбилейная вечеринка | 16 авг 2012 13:40 | 2 | It is not clear at least 2 points: 1) "The output should contain the maximal total rating of the guests." President is the host, not a guest, so his rating is excluded. (?) 2) As the party is the president's anniversary he cannot absent. (?) Am i right? If not, correct the condition please. Answers to questions 1) President's rating should be included if he goes 2) President may not be at a party 3) Noone may go to the party P.S. I'm not an admin :) | | Urra | xurshid_n | 1596. Кошмарный конь | 16 авг 2012 12:40 | 4 | Urra xurshid_n 24 июл 2012 17:38 How to solve it? What idea? my be need to delete this link :)) | | Помогите! В чем проблема? | yura | 1068. Сумма | 16 авг 2012 09:34 | 2 | import java.util.Scanner; public class my9 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("Введите n"); int n=sc.nextInt(); int s=0; if ((n>0) & (Math.abs(n)<=10000)) { for (int i=1;i<=n;i++) s=s+i; } else if ((n<=0) & (Math.abs(n)<=10000)) { for (int i=n;i<=1;i++) s=s+i; } System.out.println(s); } } Убери строку : System.out.println("Введите n"); Можно вывести только ответ. | | JAVA - What's wrong with my solution (Crashed) | JOLO_ | 1023. Пуговицы | 16 авг 2012 02:27 | 2 | public class Buttons { public static void main(String[] args) { //convert parameter into int int N = 0; try { N = Integer.parseInt(args[0]); } catch(NumberFormatException ignore) {} //find L for(int i = 3; i < Math.sqrt(N); i++) { if(N%i == 0) { System.out.println(i-1); System.exit(1); } } System.out.println(N-1); } } P.S. On my computer it works perfectly Numbers are read from stdin | | WA on test #1 | Rouk | 1274. Fractional Arithmetic | 15 авг 2012 17:19 | 1 | Please help me! I think the problem with the input / output. post the code sorry for the Russian comments. INPUT //структура дроби struct Fractional { //объявление целой части, числителя и знаменателя long long intPart, numerator, denomerator; } _oneFract, _twoFract, _result; //функция считывания дроби Fractional ReadFractional() { Fractional _fract; //переменная _razdel определяет, что ввели: только целую часть, только дробную часть или целую и дробную часть char _razdel; //считываем первое число scanf("%lld",&_fract.intPart); //считываем разделитель после первой цифры: если нажат Enter, то число без дробной части, //если слеш, то только дробная часть, если пробел то и целая и дробная части присутствуют scanf("%c", &_razdel); if (_razdel == '\n') { _fract.numerator = 0; _fract.denomerator = 1; } else if (_razdel == ' ') { //Считываем дробную часть scanf("%lld/%lld", &_fract.numerator, &_fract.denomerator); if (_fract.denomerator == 0) _fract.denomerator = 1; } else if (_razdel == '/') { //Считываем знаменатель scanf("%lld", &_fract.denomerator); if (_fract.denomerator == 0) _fract.denomerator = 1; _fract.numerator = _fract.intPart; _fract.intPart = 0; } //Сбрасываем входной поток fflush(stdin); return _fract; } OUTPUT if (_result.intPart == 0) { if (_result.numerator == 0) { printf("0"); } else { printf("%lld/%lld", _result.numerator, _result.denomerator); } } else if (_result.numerator == 0) { printf("%lld",_result.intPart); } else { printf("%lld %lld/%lld",_result.intPart, _result.numerator, _result.denomerator); } The answers are checked and correct Edited by author 15.08.2012 17:22 | | what is test 1????? | emkeb1371 | 1001. Обратный корень | 15 авг 2012 16:21 | 2 | | | Please help! Time limit exceeded! | Grigorenko Vlad | 1021. Таинство суммы | 15 авг 2012 15:35 | 7 | #include<stdio.h> int main(void){ long n,m,i,j; int flag; int A[50001],B[50001]; scanf("%ld",&n); for(i=1;i<=n;i++) scanf("%d",&A[i]); scanf("%ld",&m); for(j=1;j<=m;j++) scanf("%d",&B[j]); flag=0; for(i=1;i<=n;i++) for(j=1;j<=m;j++) if(A[i]+B[j]==10000) flag=1; if(flag) printf("YES"); else printf("NO"); return 0; } not an optimal algo... O(n^2), this problem can be solved with O(n+m) you should think a little more. If you need code, send an email on andrewshmig@gmail.com Edited by author 06.05.2012 00:27 or u can use BinarySearch to search second value. for example in the first test: 1) u take -175 value, 2) try to find 10175 in second list (using binary search) (because -175 + 10175 == 10000) ... good luck! Edited by author 08.05.2012 00:20 >not an optimal algo... O(n^2), this problem can be solved with O(n+m) This problem can be solved with O(n). ) Edited by author 02.06.2012 20:52 Use the associative containers you can use HashSet, it's faster use the two-pointers method or boolean set. It's enough fast for this problem. | | why WA on test14~Always>?<? | Heng | 1299. Псилонцы | 15 авг 2012 12:50 | 1 | | | I need help ! Prompt please! | Buer | 1810. Антиуравнения | 14 авг 2012 18:29 | 2 | if det(A) == 0 , what should I do ? If A - is not square matrix ( i.e. k != n ), how to calculate det(A) ? | | Any fast solutions? | YSYMYTH | 1144. The Emperor's Riddle | 14 авг 2012 15:40 | 1 | If so, please send one to ysymyth@gmail.com please! | | First test doesn't fit the statement limitations! (+) | Yermak | 1526. Martian Plates | 14 авг 2012 00:03 | 7 | #include <stdio.h> int p,t,n,m; int main() { scanf("%d%d%d%d",&p,&t,&n,&m); if (p<2 || p>10000 || t<2 || t>200 || (t&1) || n<1 || n>10 || m<1 || m>100) return 1/(p-p); return 0; } This program gets "Crash (integer division by zero)" at test #1. http://acm.timus.ru/status.aspx?space=1&num=1526You are right, m = 0 in the 1st test. This limitation in the problem statement is fixed now. But there is a division by zero in his code! Sandro, why did you delete my post? Because the solution of Yermak is a input validator. If the system verdict on some test is Crash (division by zero), then this test is incorrect. If the test is correct, system verdict should be Wrong Answer. Sandro, look at this line of his code! There is a division by zero if condition is true, because p-p = 0! if (p<2 || p>10000 || t<2 || t>200 || (t&1) || n<1 || n>10 || m<1 || m>100) return 1/(p-p); Edited by author 13.08.2012 11:55 Captain Obvious to the rescue! Noob, oh, i understand. Edited by author 14.08.2012 00:04 |
|
|