Общий форумMany times my code was reviewed and rewatched, but still WA7. Could anybody help? What wrong with code? May be this algorithm gives not the optimal path? int main() { double r, a; std::cin >> r >> a; // first, walk to the edge of the island double s = r; // total angle of undiscovered edge const double a_left = 360.0 - 2.0*a; // hops count on 2*a "arc" line const int full_hops = (int)(a_left / (2.0*a)); s += range(r, to_rad(2.0*a)) * full_hops; // remaining angle to hop double a_rem = a_left - full_hops * (2.0 * a); s += range(r, to_rad(a_rem)); std::cout << std::fixed << std::setprecision(12) << s << std::endl; } Your algorithm allows me to AC. Maybe problem in calculations, in "to_rad" or "range"... I wrote to_rad and range to compile your code, and compared my code with yours: all output is identical. So, maybe you've mistook in one of these functions. Edited by author 18.10.2009 00:00 Thank you a lot for a great advice! Problem was eliminated after rewriting range() function: Old: used cosinus theorem New: using sinus to radius multiplication AC! Dmitriy S. Hodyrev! You solved 1726. If you read this, help me, please. My e-mail in my profile. Moders, sorry for the message concerning not this problem. But did you think about a functionality of allowing users to send private messages to the other users' e-mails through a web-form? I had the same problem: Since the cosine can be quite close to zero its square root is not calculated properly. So I also didn't use cosine theorem but calculated the length of the chords with simpler geometry: long double x = radius * cos(angle); long double y = radius * sin(angle); long double ans = sqrt((x - radius) * (x - radius) + y * y); Here the square root is done over the distance, not over the cosine, which, as it seems, solved the problem. Use the law of sines instead of cosines. я решаю через количество пересечений графиком синуса ось ох, вроде алгоритм правильный а преодолеть третий тест не могу. помогите пожалуйста!!! 1) если число k простое, то результат: k/2 2 пример: >31 15 2 2)если число k является степенью двойки, то результат: k 1 пример: >1024 1024 1 3)остальные числа перебором(перебирать а1-первый элемент арифметичиской прогрессии) и через квадратное уравнение находить p. P.S. AC 0.031 137 КБ Thank уравнение кому нужно (по крайней мере такое у меня) 0.5p^2+(a1-0.5)*p-n=0 если перебирать не a1, а p, то можно сэкономить время =) P.S. AC 0.015 118kb #include <iostream.h> long int fac(long int k) { int i,total=1; if(k==0) { return 1; } for(i=1;i<=k;i++) { total*=i; } return total; } int main() { long int n,total=0,i; cin>>n; { if(n<14) { for(i=2;i<=n;i++) { total+=fac(n)/fac(n-i); } cout<<total<<endl; } } if(n>14&&n<17) { for(i=2;i<=n;i++) { total+=fac(n)/fac(n-i); } cout<<total<<endl; } if(n==14) { cout<<"87178291200"<<endl; } if(n==17) { cout<<"355687428096000"<<endl; } if(n==18) { cout<<"6402373705728000"<<endl; } if(n==19) { cout<<"121645100408832000"<<endl; } if(n==20) { cout<<"2432902008176640000"<<endl; } if(n==21) { cout<<"51090942171709440000"<<endl; } return 0; } for example for 21 answer is 138879579704209680000 WHY?????????? If you have WA6 try this test: 40 5 12368145698754*11111*21*111*000010000000 ans = 34 This test helped me to pass Test 6, but then I got WA 10. Special thanks to <A HREF=" http://acm.timus.ru/author.aspx?id=69418">Bunyodbek Bobodjanov (TATU UF)</A>. This test was suggested by him but it was contained some mistake. Edited by author 08.01.2010 17:58Is it really appropriate to translate 'целые числа' as 'whole numbers'? short, int, long etc... ;) #include <cstdlib> #include <iostream> //----------Funkcje---------------------------- long long nwd(long long a, long long b) { if (b>=1) nwd(b, a%b); if (b=0) return a; } using namespace std; //---------------Program------------------------------------ int main(int argc, char *argv[]) { int n; long long tab[1002]={0}; //printf("Dla ilu liczb chcesz policzyc NWD?: \n"); scanf("%d", &n); //printf("Podaj liczby: \n"); for (int i=0;i<n;i++) scanf("%I64d", &tab[i]); long long wynik=tab[0]; for (int i=0;i<n-1;i++) { wynik=nwd(tab[i],tab[i+1]); tab[i+1]=wynik; }
//printf("NWD wynosi %I64d \n", wynik); printf("%I64d", wynik);
system("PAUSE"); return EXIT_SUCCESS; } use __int64 instead long long I insert to my array only the final verdict of author, then start to counting; if WA,ML,TL 7 min++,max++ if AC,WA,ML,TL 6 max++ print min,max Why WA13 Edited by author 19.10.2009 22:28 send your code to me ,I will look! Edited by author 19.10.2009 01:49 Edited by author 19.10.2009 19:52 Edited by author 19.10.2009 20:26 5 [SPbSU_ITMO]_WiNGeR TL 6 Milanin_(TNU) WA 6 Vladimir_Yakovlev_(USU) AC Sandro_(USU) ML 7 Sandro_(USU) WA 4 Think about it! I think the answer is 0 3 is it right? No,why do you think so? Edited by author 19.10.2009 23:50 i can't understand :( why the answer isn't '0 3'? My answer for this test is "1 4"...is it correct? I am also getting wrong answer on test 13. Thanks I got it eventually...I was just making a small mistake...saving those tests in my hashmap which was less than 6...hope that helps if (pts[m].y == (int)(Math.Round(k * (double)pts[m].x + b))) this i changed on if (Math.Abs(pts[m].y - (k * (double)pts[m].x + b))<0.000000001) and now I have AC Edited by author 08.01.2010 03:08 Please, gimme some tests equal test8 Edited by author 08.01.2010 02:59 #include <cstdlib> #include <iostream> //----------Funkcje---------------------------- long long nwd(long long a, long long b) { if (b>=1) nwd(b, a%b); if (b=0) return a; } using namespace std; //---------------Program------------------------------------ int main(int argc, char *argv[]) { int n; long long tab[1002]={0}; //printf("Dla ilu liczb chcesz policzyc NWD?: \n"); scanf("%d", &n); //printf("Podaj liczby: \n"); for (int i=0;i<n;i++) scanf("%I64d", &tab[i]); long long wynik=tab[0]; for (int i=0;i<n-1;i++) { wynik=nwd(tab[i],tab[i+1]); tab[i+1]=wynik; }
//printf("NWD wynosi %I64d \n", wynik); printf("%I64d", wynik);
system("PAUSE"); return EXIT_SUCCESS; } Give me some tests or write if there are some sly tests. I solve this problem by 2^K*N*N. I have the same problem. Where is bag? Edited by author 09.07.2008 23:49 Also WA8. Give some tests WA8. Small Code, but can not find any bug/ [code cut] Edited by moderator 18.04.2013 21:14 My solution is O(2^k). I think, that main problem's are - how reduce amount of DFS (check the route existence's with current set of licenses) and reduce brute-force to find all possible combinations of licenses. Binary search for number of licenses helped me to avoid TLE. Edited by author 08.01.2010 01:39 type sl=array[1..150] of longint; var i,j,k,l,n,m,s:longint; f:array[0..50,-10..1000] of sl; u:sl; function gjc(a:sl):sl; var i,t:longint; tmp:sl; begin for i:=120 downto 1 do if a[i]<>0 then break; t:=i; fillchar(tmp,sizeof(tmp),0); for i:=1 to t do for j:=1 to t do inc(tmp[i+j-1],a[i]*a[j]); for i:=1 downto 120 do begin tmp[i+1]:=tmp[i+1]+tmp[i] div 10000; tmp[i]:=tmp[i] mod 10000; end; exit(tmp); end; procedure gjj(b:sl;var a:sl); var i,j,k,l:longint; begin for i:=1 to 120 do a[i]:=a[i]+b[i]; for j:=1 to 120 do begin inc(a[j+1],a[j] div 10000); a[j]:=a[j] mod 10000; end; end; procedure printgj(a:sl); var i,j,k,l,len:longint; st:string; begin i:=120; while (i>0)and(a[i]=0) do dec(i); if i=0 then BEGIN writeln(0);exit;end; len:=i-1; write(a[len+1]); for i:=len-1 downto 1 do begin str(a[i],st); while length(st)<4 do insert('0',st,1); write(st); end; end; begin readln(n,s); if (n=1)and(s<=9) then begin writeln(1);halt; end; if s mod 2=1 then begin writeln(0);halt; end; f[0,0][1]:=1; for i:=1 to n do for j:=0 to s shr 1 do for k:=0 to 9 do begin gjj(f[i-1,j-k],f[i,j]); end; l:=s shr 1; u:=(gjc(f[n,l])); printgj(u); end. Edited by author 07.01.2010 10:17 test: 4 0000 011 1011 11011 answ: 0000 0111 1010 1101 is it correct or not? lol, i calculated sum of ALL positions What does mean WA3 Crash (access violation)? I compiled my program many times in dev-C++ and VC++. Then I try to write #pragma comment(linker, "/STACK:16777216") but it doesn't work. I use dynamic array and sheker sort. program stone; const nmax=20; var i,k,n:byte; x:longint; a:array[1..nmax] of longint; begin read(n); For i:=1 to n do read(a[i]); For i:=2 to n do For k:=n downto i do If a[k-1]>a[k] then begin x:=a[k]; a[k]:=a[k-1]; a[k-1]:=x; end; while n>1 do begin a[n-1]:=a[n]-a[n-1]; dec(n); For i:=2 to n do For k:=n downto i do If a[k-1]>a[k] then begin x:=a[k]; a[k]:=a[k-1]; a[k-1]:=x; end; end; write(a[1]); read; end. May be I am too self-confident, but I am sure my program must work. But the fifth test refutes my confidence. If you are able to help, please,try to find mistake and write where it is=) Your algo is incorrect. Test: 5 3 3 3 4 5 Answer: 0 Thank you, I understood, I will at a new algo. I used getc and the idea of finite automaton to solve this problem and my program is working fine on the sample test case as well as all test cases given in thread. Still I am getting WA#1. I know it is not same as sample case. Please give me some good test from case 1. Thanks. I have used getc(stdin), but if I give input from file by <<, I have to put an extra getc(stdin), whereas if I write it on command prompt, that is not required. Why is this so? Why input from file has an extra character at end of line? I thought that in the end of n-th line it is EOF. But this line finishes by '\n' similarly as another lines. That's why I got WA#1. Why this #include <math.h> #include <iostream> #include <iomanip> #include <vector> using namespace std; int main() { vector<double> numbers; double number = 0; while(cin >> number){ numbers.push_back(number); }
for(int i = numbers.size() - 1; i >= 0 ; i--){ cout<<setprecision(5)<<sqrt(numbers[i])<<'\n'; }
return 0; } is wrong and this //... printf("%.4lf\n", sqrt(numbers[i])); //... is write? I don't understand. Both ways are correct... I don't know C++ a lot, but I think setprecision(5) means at most 5 digits. So use this instead and be happy: cout<<setprecision(5)<<setiosflags(ios::fixed)<<sqrt(numbers[i])<<'\n'; in which setiosflags(ios::fixed) means there must be 5 digits, filling with zero, which will satisfy the judge. Edited by author 04.01.2010 18:41 Edited by author 04.01.2010 18:42 #include<stdio.h> #include<iostream> using namespace std; char str[300],text[3000005],c,ch; int n=-1,i=0,cnt=-1; int main() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif while(scanf("%c",&c)!=EOF) { n++; text[n] = c;
} while(i<n) { memset(str,'\0',sizeof(str)); cnt= -1; while(1) { if((text[i]>='a'&&text[i]<='z')||(text[i]>='A'&&text[i]<='Z')) { cnt++; str[cnt] = text[i]; i++; } else { ch = text[i]; i++; break; } } for(int j=cnt;j>=0;j--) { printf("%c",str[j]); } printf("%c",ch); } return 0; } i WA#2,too. what's the test? Edited by author 04.01.2010 10:42 forzm why [2] 6 дек 2009 14:24 fail SuperLight Re: why 2 янв 2010 13:54 |
|