Страница 1 I didn't find a mistake in my program. And what is the test #19? I'am confused( 45 1 12 it was helped me. Good luck, bro! Try these tests on big input data: 1000000000000000000 999999999999999990 999999999999999999 3 1000000000000000000 10 500000000000000000 3 1000000000000000000 500000000000000000 250000000000000000 2 Tips: 1. Remember, that you should not only forget about using big types (for c++ it's long long int or __int64) but not forget to take big input data correctly. For example, if you will use scanf("%d", &i), it will not get correctly a big input digit. 2. If you use min function in you program to find the minimum of two digits, don't forget to initialize your min value variable with the maximum value your can input. For example, __int64 minInit = LLONG_MAX. If you have such problems, you will have incorrect answers on the second and third tests (you'll get 4 and 3 respectively) and you will have WA on the tests 17 (the first tip) and 18 (the second tip). Hi KOTnt, you helped a lot thank you ...!!! What is test 2? Try this 10 5 3 Answer: 4. My program is right for this test. What is in test 33 ? The same code with Scanner is accepted but with StreamTokenizer and BufferedReader is giving WA33. Very unexpected result!! O_O Edited by author 16.12.2012 10:56 I use unsigned long long and STL vector with very simple algorithm: store x1, x2, x3 in the vector, then find the minimal diffenrence and push it in the vector (repeat the process until minimal difference is 0). I got AC. I suppose that the tests are not strong enough. I wonder whether there is any test whose output is very large since I don's believe vector can store too many elements. P/S: I'm a beginner so I'm very glad to study from all of you :-)! The simulation works in O(logN), so your solution is correct Edited by author 21.10.2012 03:11 Edited by author 21.10.2012 03:11 I corrected my mistake!!! sorry for all ;) got AC! I had Crash 1!!! and solve in Java and found my mistake!!! #include <stdio.h> #include <stdlib.h> int cmp(const void *a, const void *b) { unsigned long long *pa = (unsigned long long *)a, *pb = (unsigned long long *)b; return *(unsigned long long *)pa - *(unsigned long long *)pb; } int main() { unsigned long long arr[15000], min=1000000000000000000; int N=3, count=0, i; for(i = 0; i<N; i++) scanf("%llu", &arr[i]); while(min) { qsort (arr, N, sizeof(unsigned long long), cmp); for (i = 0; i<N-1; i++) if(arr[i+1] - arr[i]<min) min=arr[i+1] - arr[i]; arr[N++] = min; count++; } printf("%d", count); return 0; } Can anybody help me? Use __int64 instead of unsigned long long I changed. But I stil have WA#17 and time limit exceed. #include <stdio.h> #include <stdlib.h> int cmp(const void *a, const void *b) { __int64 *pa = (__int64 *)a, *pb = (__int64 *)b; return *(__int64 *)pa - *(__int64 *)pb; } int main() { __int64 arr[100], min=1000000000000000000; int N=3, count=0, i; for(i = 0; i<N; i++) scanf("%I64d", &arr[i]); while(min) { qsort (arr, N, sizeof(__int64), cmp); for (i = 0; i<N-1; i++) if(arr[i+1] - arr[i]<min) min=arr[i+1] - arr[i]; arr[N++] = min; count++; } printf("%d", count); return 0; } Now I have WA#17 and crash(acces violation). Of course, you have crash :D Replace all number types to __int64, uncluding int. I changed: #include <stdio.h> #include <stdlib.h> int cmp(const void *a, const void *b) { __int64 *pa = (__int64 *)a, *pb = (__int64 *)b; return *(__int64 *)pa - *(__int64 *)pb; } int main() { __int64 arr[100], min=1000000000000000000, N=3, count=0, i; for(i = 0; i<N; i++) scanf("%I64d", &arr[i]); while(min) { qsort (arr, N, sizeof(__int64), cmp); for (i = 0; i<N-1; i++) if(arr[i+1] - arr[i]<min) min=arr[i+1] - arr[i]; arr[N++] = min; count++; } printf("%I64d", count); return 0; } But the same problem remain: WA#17 crasn(access violation) You didn't changed int cmp(const void *a, const void *b) { __int64 *pa = (__int64 *)a, *pb = (__int64 *)b; return *(__int64 *)pa - *(__int64 *)pb; } change to __int64 cmp(const void *a, const void *b) { __int64 *pa = (__int64 *)a, *pb = (__int64 *)b; return *(__int64 *)pa - *(__int64 *)pb; } #include <stdio.h> #include <stdlib.h> __int64 cmp(const void *a, const void *b) { __int64 *pa = (__int64 *)a, *pb = (__int64 *)b; return *(__int64 *)pa - *(__int64 *)pb; } int main() { __int64 arr[100], min=1000000000000000000, N=3, count=0, i; for(i = 0; i<N; i++) scanf("%I64d", &arr[i]); while(min) { qsort (arr, N, sizeof(__int64), cmp); for (i = 0; i<N-1; i++) if(arr[i+1] - arr[i]<min) min=arr[i+1] - arr[i]; arr[N++] = min; count++; } printf("%I64d", count); return 0; } No, it doesn't help. Oh,you have too small array size. Use STL vector do it greater. I don't know C++. I tried to change size of array, but I have time limit exceed. Edited by author 08.08.2012 18:32 # include <iostream> # include <vector> # include <algorithm> using namespace std; long long q; int main() { vector <long long> v(3),v1;
for(int i=0; i<3; i++) cin>>v[i];
while(1) { v1.clear();
q++;
for(int i=0; i<(int)v.size(); i++) { for(int h=0; h<(int)v.size(); h++) { if(i!=h) { int a=v[i]-v[h];
if(a>=0) v1.push_back(a); } } }
sort(v1.begin(),v1.end());
if(v1[0]==0) {break;}
v.push_back(v1[0]); } cout<<q; } For example, I got WA19 at first time. I changed real to extended and integer to longint and got AC. subj I didnt use ull & got AC. пробовал разные способы вычисления, упираюсь в 33 тест. Какие есть мысли? try more ways reading longs Here is my code: #include <iostream> using namespace std; int x[200]; int compare (const void *a, const void *b) { return (*(int*)a - *(int*)b); } int main() { int r[200], a = 3; long min; bool z = false; for (int i = 0; i<3; i++) cin>>x[i]; for ( ; ; ) { qsort (x, a, sizeof(int), compare); min = 1000000000; for (int i = 0; i<a-1; i++) { r[i] = abs(x[i] - x[i+1]); if (r[i]<min) min = r[i]; } x[a] = min; for (int j = 0; j<a; j++) { if (x[j] == min) { z = true; break; } } if (z == true) break; a++; } printf("%d", a - 1); return 0; } Where is my mistake? Use long long instead of int Edited by author 31.01.2012 15:35 Your must be min*10 + 9 Thanks! Sorry for my small intellegence)))) plese give me test 23 1 1 2 1 1 2 3 2 234 532 245 3 12345 87654 23456 4 1223456 8098887645 567321 4 12345 654345678 1234567890 5 plese give me test 23 Edited by author 29.10.2011 23:25 Can someone give me test #18??? Or give me some tests and answers??? For: 75000000000000000 50000000000000000 25000000000000000 answer is 2 (1 ≤ x1, x2, x3 ≤ 10^18) Try to use int64 Thanks, but i have already use int64/ but i dont know where's my error... :( I have submitted it more than one times with int64, but again and again I got WA on test19, however, same source code in Java using BigInteger was accepted at once. 45 1 12 You can have problems with sorting your array it was helped me. Good luck, bro! Edited by author 13.12.2018 21:43 Edited by author 13.12.2018 21:43 Can you give me some test? 1 1 2 1 1 2 3 2 234 532 245 3 12345 87654 23456 4 1223456 8098887645 567321 4 12345 654345678 1234567890 5 Edited by author 05.07.2011 20:09 Hey Maria, Problem states that the input, consists of 3 space-separated pairwise DISTINCT integers so your first example doesn't satisfy conditions and hence, is useless. Regards, Sepehr 99 8 1 3 thanks :) got AC after testing you input and fixing the program P.S. long in JAVA is enough!!!! Maria , for test number 4, I think the answer should be 3 : First aborigine brings a pile of 75309 ( 87654-12345 ) , the second aborigine also brings a pile of 75309 stones , because that's still the biggest difference , and the third points to the two equal piles. Correct me if I'm wrong! hopless dreamer, No, u r wrong. The FIRST aborigine will bring the pile of 64198 stones, becouse it's the LEAST. And the second aborigine will bring the pile of 64198 - 23456 = 40742 stones and so on. "Professor asked one of the aborigines to point at two piles with the MINIMAL difference of numbers of stones in them and tell what this difference is." Edited by author 06.07.2012 18:07 Edited by author 06.07.2012 18:07 Чё там в 21 тесте? Edited by author 14.08.2011 21:21 Чё там в 21 тесте? The theme is about test#9 |
|