Общий форумhelo! this is just a suggestion, i believe there should be an option (if they wish) for authors to display their email address to be contacted ! as it will enable and allow for more communications between authors. my address is, baiguzair@gmail[dot]com Does nobody want to stay in touch!!?? Does nobody want to stay in touch!!?? I think they may also set up a mail function inside timus... But if you want to show your email, you can set it as your motto. #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]= pointy[0]; pointx[N] = pointx[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;} Please reply !! 3 1.2 12.24 13.34 0.00 24.75 -33.36 70.12 153.41 your program is too complicated to read I will tell you about my program. I am first calculating the distance between each point and summing it (perimeter). Then I am calculating the angle; of rope wound around each nail. I am adding the angles and then finding the total length by; perimeter + radius*angle. As my angle is in radians. Now, my answer is slightly above your answer in this test case; as I can see. But, if I change my angle to be always just 2 * PI * r, then I get it right !! Now, first I can see the intuition for always setting angle to be 2*PI*r, but I cannot find any proof of why this will be always true. So, I am calculating it always for each nail. ( I think maybe, my calculation algorithm either gives a rounding error; or I am making a mistake)!! Please do reply, and tell me why? Okay, I found my mistake. And the proof;(the reason) is got to do with exterior angles of a polygon sum up to 360 degrees! :) thank you tianchb Well, I suppose perhaps float is not accurate enough... Since triangle functions in math.h are all float. Congratulations anyway. VladimirZagorodskih Suggestion [1] 16 янв 2010 16:15 Why don't add a button "Random Problem" ?? Random problem from those which have not already solved. Edited by author 16.01.2010 17:56 Please, show 9 test. Who make this problem, public your solution, please. Probably you should try to find a bug in your code. It doesn't look like this problem have any troubles with test data. Without test very hardly found bugz in code :-( But actually you have to obtain this useful skill. I have WA9 too. try test: 3 1 2 1 1 3 1 2 I don't think that 9 test has smth special) I had a very stupid bug in my code and so had WA#9) Failed test was 10 1 7 1 1 8 2 3 3 4 4 5 5 6 6 7 7 8 IMHO Cool problem) I also fall on test 9, but both of these tests work fine. What was the bug you corrected? Edited by author 27.05.2008 02:28 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 subj 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 Third test is the third test in the example. Странно, но со 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 Выводить надо в обратном порядке 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 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. 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 i ALSO GOT wA4. hELP Mistake because of wrong processing obstacles #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 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 What the answer to test: m k n 12 3 2 18 I got 53 and WA 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 May be anybody knows, what is specific of the second test? All my examples work correctly, but the second test...... }:-/ 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 |
|