|
|
Общий форумSome testcases contain empty strings, which is very nasty, and they should be read in combination with scanf and gets. I had scanf("%d\n", &N) initially, which skipped the empty lines afterwards, so my gets() calls where kind of useless. Secondly, here are some testcases: 2 bc abcd 1 abcx Should return 1 2 2 bc abcd 1 abcd Should return 1 1 int main(){ long long a; double b=0; int count=0; double *array = (double *)malloc(sizeof(double)); while(scanf("%lld",&a)){ b = sqrt(a); array[count]=b; count++; } for(int i = count-1; i >= 0; i--){ printf("%f\n",array[i]); }
return 0; } my code is showing above, but each time it returns the runtime error. i run it on my PC but everything is fine. is there any runtime error here? thanks! There is access violation Your array is only ONE element in size It works on your PC because your runtime environment does not checks whether you are violating borders of memory Memory allocation is just a promise to use allocated memory But in C++, there are no checks by default So it is programmer's task to ensure there is no BUFFER OVERRUN. So malloc(sizeof(double) *N) returns memory for N doubles In your case N is just one When you allocate memory System is not permitted to use that memory for it's operations Because if it uses You may change system parameters and break down the system Problem solved Edited by author 13.09.2017 11:45 New tests have been added to the problem. 82 authors have lost AC. My ac program gives wrong answer on this test: Input 1 101234 Output: 14231 Edited by author 31.08.2017 22:02 Edited by author 31.08.2017 22:02 Your test is added. Thank you! Edited by author 11.09.2017 21:42 What is the meaning of this problem ? Edited by author 11.09.2017 19:22 Edited by author 11.09.2017 19:22 Considered several ways Decided binary search is the best Pls halp... var i, n: integer; id:array of longint; ball: array of integer; procedure qSort(var ar: array of integer; ra:array of longint); procedure sort(var ar: array of integer; low, high: integer; ra:array of longint); var i, j: integer; m, wsp: integer; b: longint; begin i := low; j := high; m := ar[(i + j) div 2]; repeat while ar[i] < m do Inc(i); while ar[j] > m do Dec(j); if i <= j then begin wsp := ar[i]; ar[i] := ar[j]; ar[j] := wsp; b := ra[i]; ra[i] := ra[j]; ra[j] := b; Inc(i); Dec(j); end; until i > j; if low < j then sort(ar, low, j, ra); if i < high then sort(ar, i, high, ra); end; begin sort(ar, 0, High(ar), ra); end; begin read(n); setlength(id,n); setlength(ball,n); for i := 0 to n-1 do read(id[i], ball[i]); qSort(ball, id); for i := n-1 downto 0 do writeln(id[i], ' ', ball[i]); end. What's wron? Halp pleese! don't use that language Because that language hasn't got sort functons? Strange advice to the beginner N=int(input()) s=0 for i in range(N): x,y=map(int,input().split()) s*=10 s+=(x+y) print(s) s is one digit by definition But if a+b>=10 s can be expressed only using two digits Ohh, wait... Try print(int(s)) I suppose you print in scientific notation when s is huge URAAA! Hmm... :) I wanna see the code I managed to get 0.001s on 500 kB :D Send at night. Code is here: * deleted * Edited by moderator 23.07.2022 20:34 yordam kerak aka deleted Edited by author 08.09.2017 13:54 5 0 0 2 2 3 1 4 0 6 2 Answer: 5 Russian: Далее следуют M строк по 2 целых числа в каждой — координаты тараканов в настоящий момент. M + 2 строка содержит число ??? N (0 ≤ N ≤ 10000) ??? . Далее N строк — координаты кусочков сладости. Все координаты — действительные числа. English: M lines follow, containing 2 numbers each — these are coordinates of the cockroaches at the present moment. (M + 2)nd line of the input stream contains the number ??? N (0 ≤ N ≤ 10000) ??? . N following lines contain coordinates of sweet pieces. Can be the number of sweet pieces equal 0 ? So what will be the answer in this case ? Answer can be empty ? Edited by author 07.09.2017 17:23 Edited by author 07.09.2017 17:23 Задача - бомба! Подсказка - производная... Edited by author 07.09.2017 16:41 Edited by author 07.09.2017 16:41 I used greedy search on sorted edges in increasing order of sum of degrees of vertices (of edge). Should I refine my compare function? Other hints? I use dp,but W4.Who can give me some hints or tests. Thanks a lot. Though I don't know why I wa4 that time , I AC now without any change... may be it's time's power... Try 1 10 a1aaaa1aaaa1 Try 1 2 [space] [space] = " " My code in python 3.6: def is_palindrom(x): if x==x[::-1]: return True return False s=input() s=s[::-1] n=len(s) a=[] for x in range(2,n+1): for i in range(0,n-x+1): if is_palindrom(s[i:i+x]): a.append(s[i:i+x]) if len(a)==0: b=s[-1] else: b=a[-1] print(b) Memory is 70160 Kb, where so much it? Please, help, I would be grateful! I see you AC now What was the issue? Oh, sorry, it is other task Can somebody tell me why i get memory limit exceeded in test case #9... ???? i make an k-d tree and use nearest neighbor search in my solution and still have memory limit Edited by author 03.05.2013 07:52 Have you done it? i have memory limit in test 10 too (c++) Have you done it? i have memory limit in test 9 too (c++) Edited by author 05.09.2017 19:58 Edited by author 05.09.2017 19:58 |
|
|