Common BoardGimme some tests, please :) All tests that I found my program passed right, I can't understand my mistake. Now I have WA4 :) Edited by author 08.07.2012 10:07 can anybody explain me an idea of N^2? I think there is no O(N^2) solution, but who knows? Maybe, I'm not right. Now my AC solution is nearly O(N^3) (something like N^3-N^4 operation) - it's enough. When the number of compartments is 0 you should output 0 (not -1),maybe you guessed why i said "not -1",because when you output (Number_of_Compartments-1) the answer will be -1 because Number_of_Compartments=0 ,maybe it will help you. Good Luck! #include <iostream> #include <stdio.h> #include <vector> #include <cctype> #include <stdlib.h> #include <numeric> #include <string.h> #include <algorithm> #include <cmath> #include <queue> #include <stack> #include <iterator> #include <set> using namespace std; #define FOR(i, a, b) for (int i = (a) ; i < (b); i++) #define sz size() #define pb push_back #define clean(t) memset ((t) , -1, sizeof(t)) #define VI vector <int> #define VS vector <string> #define cinput(n) scanf("%d", &n) int main() { int n; double a; VI ans; while(cin >> n) { if (n == 1) {ans.pb(1); continue; } if (n == 0) goto end; a = log(n)/log(2); if ( a == (int ) a) ans.pb(a); else ans.pb((int) a+1); } end:; int q; FOR(q, 0, ans.sz) { cout << ans[q] << endl; } return 0; } What's Wrong?? Plz some1 tell me.. I am able to find the minimum cost but not being able to print the room numbers. Please, check this test(or checker) - my program passes all tests correctly(all 365 tests for non-leaps years and 366 for leap years), but WA 10, or say, if my solution gives a wrong answer at all :) Got AC after I did 4 spaces between 1-digit numbers and 3 spaces between day-name and first column... It's not very obvious, I think... What's the numeber means after the wrong answer. Is the correct number or wrong? It's number of test, which you program failed. what is test 8. i get wrong answew :( :( Edited by author 10.11.2012 16:31 Try something like: 5 5 4 3 2 1 The answer should be anything except 1 or 5. The first pirate is compared and switched straight away. This is also the first comparison for the 2nd pirate, which is compared with 3rd before before swapping. I use bit operations for this problem =) and simple DP =) It has AC with ~4Mb memory and ~0.7 sec time... I got AC using 2 arrays of size 10^7 without bit compression. Strange... Could anyone give me some test cases? Thanks. Edited by author 07.03.2013 11:16 Edited by author 07.03.2013 11:16 Edited by author 07.03.2013 11:17 Edited by author 07.03.2013 11:17 I'm only start to learn Haskell. I'm confused with std function and IO. My solution (does not work): main = do a <- getLine let b = sum map read words a // <- I try to use this functions putStrLn (show b) let b = words a // work, but let b = sum map (read::Int) words a //does not work Where I wrong? #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; } In JAVA version of the tests, in test 3, N<3, be careful when declaring array sizes. In C# version of the tests there is no such test. This code results in a runtime error at test #26: from sys import stdout d = int(float(raw_input().strip())) n = [1,5,10,20,50,100,250,500,1000,2000] l = ['few','few','several','pack','lots','horde','throng','swarm','zounds','legion','legion'] a = min(map(lambda x: x+d,filter(lambda x: x > 0, map(lambda x:x - d,n)))) stdout.write(l[n.index(a)]) This code was accepted without error: from sys import stdout d = int(raw_input()) if d > 0 and d < 5: stdout.write('few') elif d < 10: stdout.write('several') elif d < 20: stdout.write('pack') elif d < 50: stdout.write('lots') elif d < 100: stdout.write('horde') elif d < 250: stdout.write('throng') elif d < 500: stdout.write('swarm') elif d < 1000: stdout.write('zounds') else: stdout.write('legion') Can anyone explain why the first code fails but the second doesn't? Initially, in one trie node i stored: Node child, sibling, sufLink; byte parSymb; short lEnd; This is 4 * 3 + 1 + 2 = 15 bytes per node, ML 28. Then I used static array of nodes(maximum number of nodes is 99991), memory consumption per node is the same(instead of Node reference we store int), ML 28. At the end, I stored child, sibling, sufLink and parSymb(we need 17 bits for each memory pointer and 8 bits for parent symbol, 17 * 3 + 8 = 59 bits in total) in one long, and lEnd in short, only 10 bytes per node, and got AC! #include<stdio.h> int main() { long long i,n; while(scanf("%lld",&n)==1) { long long s=0; if(n==1) printf("%lld",n); if(n>1&&n<=10000) { for(i=1;i<=n;i++) { s=s+i; } } if(n<1&&n>=-10000) { for(i=1;i>=n;i--) { s=s+i; } } printf("%lld\n",s); } return 0; } Help me!!!I got WA#2 Please give me some tests... I use merge sort. Здравствуйте, прошу прощения за русский язык (проблемы с английским)... Число 1 не строго больше одного, а значит, ошибка в условии задачи, т.к. при Вашем условии при вводе 4 1 6 на принтер выведется 2 2 1 1 и вывод программы будет 2... Исправьте, пожалуйста, условие для того чтобы не возникали недоразумения. СПАСИБО! "Функция организует следующую процедуру: на принтер выводит количество чисел в массиве, далее количество чисел, строго больших одного, ..." Именно это я и имел в виду! "далее количество чисел, строго больших одного..." А у в примере единица также учитывается... Первое число - количество ВСЕХ чисел в массиве! Hi! Please help russian shoolboy Where the error is? I realized that '1'-s are in the field of the sequence. 1 2 4 7 11 16 int main() { long a,j,i,n; cin>>n; for(int x=0; x<n; x++) { cin>>a; i=1; j=1; while (a>i) { i=i+j; j++; } if (a==i) cout<<1; else cout<<0; } return 0; } while (a>i) { i=i+j; j++; } Sorry, I have it, I just forgive write it at the sample for you. Program code has generate 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 isn't right? Xax! Sorry again. I have Acc, I just was to add "space" between numbers :) Hi! Sorry, how i can have WA 1# if my program generate 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 at first test? Do you have 16 in the end of the list? Look at the sample output - it is there Sorry, I have it, I just forgive write it at the sample for you. Program code has generate 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 isn't right? |
|