Общий форум| Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения | | Hint for DFS and Crash #3 !!!!! | tiancaihb | 1471. Расстояние в дереве | 16 янв 2010 12:50 | 3 | I used Tarjan Algo, based on DFS and union-find sets, but got Crash AV #3. I made a extreme data myself, like a chain from Node #0. And it really crashed with DEV-C++. I tried to enlarge the size of stack, but it seemed workless. After debugging for so long, I still can't explain why it got stuck at Node #49xxx (The program works on every "smaller data"). Do I have to make a "stack" myself? No, I came up with an idea--randomize. And with that I ACed with no difficulty. Here is the thing, maybe you picked Node #0 as the root of the tree, but why not change to a random one? I think data #3 is such a data that will make the first algo crash. Sorry for my poor English, btw. I had the same problems with this problem but increasing size of the stack helped me. Post here your e-mail and i'll send you my code. I think you understand my code because i made it the same way with you(dfs+disjoint set) tiancaihbATsinaDOTcom No, forget about it. I must have writen a wrong code The right one is #pragma comment(linker, "/STACK:16777216"). Well, that's embarrassing because you won't get CE even if it's wrong. I wrote before: #pragma comment(linker, "/STACK:64777216") Edited by author 16.01.2010 12:54 Edited by author 16.01.2010 12:55 | | WA#25: can you give me some tests? | fail | 1671. Паутина Ананси | 15 янв 2010 22:13 | 2 | I got AC when i handle multigraphs (multiple edges between pair of vertices are possible) Look my post (he located above your post in that node{ NOT MAIN NODE BUT NODE of the problem 1671}) there you can find test with multi-edges. Edited by author 15.01.2010 22:18 Edited by author 16.01.2010 13:03 | | Why WA#3. I don't know where my mistake. | Khramov Egor(9 class) | 1233. Amusing Numbers | 15 янв 2010 04:31 | 2 | Third test is the third test in the example. | | Crash on Test 1; c++; Падение на тесте 1. Что за тест? (РЕШЕНО! g++ vs. icl) | RR42 | 1001. Обратный корень | 15 янв 2010 01:57 | 2 | Странно, но со struct работает и у меня; но не на сервере. У меня libc6. #include <stdio.h> #include <math.h> struct Node // РЕШЕНИЕ: ЗДЕСЬ НУЖНО ПИСАТЬ class. Компилятор тимуса ругается почему-то. { public: Node* prev; double info; }; int main() { Node* p = NULL; Node* node; double d; while(scanf("%lf",&d)!=EOF) { node = new Node; node->info = sqrt(d); node->prev = p; p = node; } while (p != NULL) { printf("%.4lf\n", p->info); p = p->prev; } return 0; } Edited by author 31.12.2009 03:44 Выводить надо в обратном порядке | | To Admins | Prabhjot Singh | 1119. Метро | 15 янв 2010 01:13 | 1 | I have got AC for this problem but my solution is quite inefficient http://acm.timus.ru/status.aspx?space=1&num=1119&author=82952 It takes me 0.156 seconds to compute the answer, but there are many ppl who got solution in 0.015 secs.If possible please email me one of the efficient solution (C++ one).my email address is pjas002@aucklanduni.ac.nz Thanks | | test #12 | Zrutor | 1024. Перестановки | 14 янв 2010 20:10 | 1 | Would anyone happen to know what test #12 is, or otherwise suggest something similar? Because I keep getting Time limit exceeded on it. Thanks in advance. | | About timus Vkontakte.ru =) | Ras Misha [t4ce] | | 14 янв 2010 18:22 | 1 | | | Please Help me! I've got WA#4! | {AESC USU} Dembel | 1301. Кубик в лабиринте | 13 янв 2010 22:48 | 5 | Please give me some test or hint. Give me your mail, I'll try to help you) My mail: <deleted> Edited by author 29.11.2007 19:39 Mistake because of wrong processing obstacles | | Wrong answer why | zarrafa | 1020. Ниточка | 13 янв 2010 10:28 | 2 | #include <stdio.h> #include <math.h> int main(){ freopen("b.in","r",stdin); freopen("b.out","w",stdout); double x[102],y[102]; double d1,d2; int i,star=0,k,m,n,j; double s,r,pi=2*acos(0); scanf("%d",&k); for(m=0;m<k;m++){ s=0; scanf("%d %Lf",&n,&r); for(i=0;i<n;i++) scanf("%Lf %Lf \n",&x[i],&y[i]); for(j=0;j<n-1;j++){ d1=abs(x[j]-x[j+1]); d2=abs(y[j]-y[j+1]); s=s+sqrt(d1*d1 + d2*d2); } d1=abs(x[0]-x[n-1]); d2=abs(y[0]-y[n-1]); s=s+sqrt(d1*d1 + d2*d2); s=s+(n*pi*r)/2; if(star==0) star=1; else printf("\n"); printf("%.2Lf",s); } return 0; } #include <iostream> #include <cmath> using namespace std; int main(){ double PI=acos(-1.0); int N; double r(0), perimeter(0); cin>>N>>r; double *pointx, *pointy; pointx = new double[N+1]; pointy = new double[N+1]; for(int a=0; a<N; a++){ cin>>pointx[a]>>pointy[a]; } pointy[N]= pointx[0]; pointx[N] = pointy[0]; cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); if(N==1){ perimeter=2*PI*r; cout<<perimeter;
} else{ if(N==2){ perimeter=2*(pow((pow((pointx[0]-pointx[1]),2)+pow((pointy[0]-pointy[1]),2)),0.5)) + 2*PI*r; cout<<perimeter;
} else{ double angle(0); for(int a=0; a<N; a++){ perimeter += pow((pow((pointx[a]-pointx[a+1]),2)+pow((pointy[a]-pointy[a+1]),2)),0.5); }
double p1x, p2x, p3x, p1y, p2y, p3y, m1, m2;
p1x=pointx[N-1]; p2x=pointx[0]; p3x=pointx[1]; p1y=pointy[N-1]; p2y=pointy[0]; p3y=pointy[1]; if(p3x==p2x) m1=tan(PI/2.0); if(p2x==p1x) m2=tan(PI/2.0); if(p2x!=p3x) m1=(p3y-p2y)/(p3x-p2x); if(p2x!=p1x) m2=(p1y-p2y)/(p1x-p2x); angle = 2*PI - (PI + fabs(atan(m1)-atan(m2))); for(int a=1; a<N; a++){ p1x=pointx[a-1]; p2x=pointx[a]; p3x=pointx[a+1]; p1y=pointy[a-1]; p2y=pointy[a]; p3y=pointy[a+1]; if(p3x==p2x) m1=tan(PI/2.0); if(p2x==p1x) m2=tan(PI/2.0); if(p2x!=p3x) m1=(p3y-p2y)/(p3x-p2x); if(p2x!=p1x) m2=(p1y-p2y)/(p1x-p2x);
angle += ((2*PI) - (PI + fabs(atan(m1)-atan(m2)))); }
perimeter += r*angle; cout<<perimeter; }} delete pointx; delete pointy; return 0;}
// even me wrong answer Edited by author 13.01.2010 20:27 Edited by author 13.01.2010 20:27 | | why wa#10 (c#) | Ras Misha [t4ce] | 1038. Проверка орфографии | 12 янв 2010 15:50 | 2 | using System; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string razd=":;, -"; string kp=".!?"; string dig = "0123456789"; string[] input = Console.In.ReadLine().Split( new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); int cnt = 0; int ns = 0; int nb = 0; for (int i = 0; i < input.Length; i++) { string s = input[i]; for (int j = 0; j < s.Length; j++) { if ((s[j] >= 'A' && s[j] <= 'Z') || (s[j]>='a' && s[j]<='z') || dig.IndexOf(s[j])>=0) { nb++; if (ns == 0) ns++; if (nb == 1 && ns == 1 && (s[j] >= 'a' && s[j] <= 'z')) cnt++; if ((s[j] >= 'A' && s[j] <= 'Z') && nb > 1) cnt++; } if (razd.IndexOf(s[j]) >= 0) { nb=0; if (ns > 0) ns++; } if (kp.IndexOf(s[j])>=0) { ns = 0; nb = 0; } } nb = 0; } Console.WriteLine(cnt.ToString()); Console.ReadKey(); } } } i got wa in #10 too try this Asf,.,a the ans is 1 | | Test 12 | bsu.mmf.team | 1694. Слова-убийцы | 11 янв 2010 23:16 | 2 | Test 12 bsu.mmf.team 27 ноя 2009 06:18 What the answer to test: m k n 12 3 2 18 I got 53 and WA | | WA 4# Please help | Marck | 1095. Никифор 3 | 10 янв 2010 19:32 | 2 | I really don't like to do it, but i just can't find what is wrong in my code... In my pc it works pretty fine.. but, i got WA 4#... my bugged code: ========================================================== #include <iostream> using namespace std; void reordena(int *numeros[],int difzero,int num) { int rdn1,rdn2,aux; rdn1 = rand() % difzero; rdn2 = rand() % difzero; aux = numeros[num][rdn1]; numeros[num][rdn1] = numeros[num][rdn2]; numeros[num][rdn2] = aux; } void permuta(int *numeros[],int num,int tam) { int cont,cont2,aux,difzero=0,resp=0; int mult; long int contador=0; for(cont=0;cont<tam-1;cont++) { for(cont2=0;cont2<tam-1;cont2++) { if(numeros[num][cont2]==0) { aux = numeros[num][cont2]; numeros[num][cont2] = numeros[num][cont2+1]; numeros[num][cont2+1] = aux; } } } for(cont=0;cont<tam;cont++) { if(numeros[num][cont]!=0) difzero++; } mult=1; for(cont=difzero-1;cont>=0;cont--) { aux=(numeros[num][cont]*mult); resp+=aux; mult*=10; } while(resp%7!=0) { reordena(numeros,difzero,num); mult=1; resp=0; for(cont=difzero-1;cont>=0;cont--) { aux=(numeros[num][cont]*mult); resp+=aux; mult*=10; } contador++; if(contador>=1000000) { numeros[num][0]=0; resp=0; } } } int main() { int N,cont,**numeros,*tam; char aux[200]; cin >> N; if(N<0) exit(0); if(N>10000) exit(0); tam = new int[N]; numeros = new int*[N]; for(cont=0;cont<N;cont++) { numeros[cont] = new int[20]; } for(cont=0;cont<N;cont++) { cin >> aux; tam[cont] = strlen(aux); if(tam[cont]>20) { exit(0); } for(int cont2=0;cont2<tam[cont];cont2++) { numeros[cont][cont2]=aux[cont2]-'0'; } permuta(numeros,cont,tam[cont]); } system("cls"); for(cont=0;cont<N;cont++) { for(int cont2=0;cont2<tam[cont];cont2++) { if(numeros[cont][0]==0) { if(cont2==0) cout << "0"; } else if(numeros[cont][cont2]!=0) cout << numeros[cont][cont2]; } if(cont!=N-1) cout << endl; } delete [] numeros; delete [] tam; return 0; } ======================================================== please, help if you can =/ May be late=) but if input data contain 0 all zeroes must be output for example input: 1 12300134 example output: 13124300 | | what is the problem with the 2 test? | 2angels | 1041. Никифор | 10 янв 2010 13:50 | 1 | May be anybody knows, what is specific of the second test? All my examples work correctly, but the second test...... }:-/ | | WA7, what wrong? | Dmitriy S. Hodyrev | 1729. Сундук мертвеца | 10 янв 2010 10:10 | 8 | 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? Re: SuperLight 10 янв 2010 10:10 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. | | WA3 Please help!!! | SirJ [KhAI] Smusenok Sergey | 1704. Демодуляция | 9 янв 2010 00:28 | 1 | я решаю через количество пересечений графиком синуса ось ох, вроде алгоритм правильный а преодолеть третий тест не могу. помогите пожалуйста!!! | | HINT(+) (rus) | Smusenok Sergiy Andriyovich (KhAI) | 1120. Сумма последовательных чисел | 9 янв 2010 00:22 | 3 | HINT(+) (rus) Smusenok Sergiy Andriyovich (KhAI) 19 авг 2009 20:47 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 | | Please tell me what is wrong in my programm???????????!!!! | Atbasar(GBK) | 1402. Коктейли | 8 янв 2010 23:44 | 2 | #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 | | WA#6 | hanzhoufeng | 1061. Диспетчер буферов | 8 янв 2010 17:57 | 2 | WA#6 hanzhoufeng 21 ноя 2007 18:08 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:58 | | Whole numbers? | SkidanovAlex | 1115. Корабли | 8 янв 2010 16:27 | 3 | Is it really appropriate to translate 'целые числа' as 'whole numbers'? short, int, long etc... ;) | | what's wrong with that code :( | Bartosz | 1053. Пиноккио | 8 янв 2010 15:19 | 2 | #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 |
|
|