a= input().split() l = int(a[0]) h = int(a[1]) ω = int(a[2]) g = 9.81 ω = ω * 2 * 3.14159 / 60 t = (h / 100) / (g * 0.5) x = ω * t * l if x % l <= l/2: print("butter") else: print("bread") Edited by author 21.10.2021 22:47 w = N/t h = g*t*t/2 this is also if l/2 >= h you must print "BUTTER" and you stop your program else continue 1 1 1 butter 1 1 100 butter 1 1 900 bread 1 1 1000 bread 100 10 1000 butter 1 1 469 butter 1 1 470 bread Why you have 1 1 470 - bread and 1 1 469 - butter? 1 1 469 time = 0.045152364098573095 speed = 7.816666666666666 N = time*speed = 0.352940979370513 angle = 127.05875257338468. So it must be bread; and 1 1 470 time = 0.045152364098573095 speed = 7.833333333333333 N = time*speed= 0.3536935187721559 angle = 127.32966675797611 So for both variants we get bread. Am i not right ? Oh.. Proba, sorry. Now see problem. thank you for tests :) why you are using speed, you need only angle for which you dont need speed sorry it was stupid question:) Thanks for tests... If you have WA#23 usind C# remember that Math.Sqrt(-1) = NaN :) {bu-ga-ga}; Edited by author 29.01.2011 00:33 bazinga! =) ta - ka - aka. bu bu haha hu hu ni ni I can't understand what i do not correctly. Help me, please. Бутерброд изначально довольно близок к Земле At first I wrote a tricky solution using trigonometry and binary search. And I was unable to pass through test case No. 12. Then I wrote simple two-step solution and got AC. Can anybody help me with this test case? Accepted with additional check if (2*h - l < 0.0) { cout << "butter"; return 0; } I was trying many times to get past first test and fixed a few mistakes in the algorithm to no avail. And the reason to fail was that the output was in brackets. I think when the toast rotates an angle of w after t seconds, it will land if only the distance it traveled ( 0.5 * 981 * t * t ) plus its projection on the orthogonal ( 0.5 * l * |sin(w)| ) equals to h. But I got WA when implementing this approach, then change the latter expression into l/2 and got AC. Could anyone explain this? Edited by author 18.12.2011 02:22 l/2 works because when the middle of given toast is l/2 cm away from the ground, it won't change sides anymore. Projection approach would work too, but it's tricky to implement. Binary and ternary searches won't work because distance + projection is neither monotonous nor unimodal (think about case when h is small and the toast is spinning very fast). Where is the error in my code? Please, help... #include <stdio.h> #include <conio.h> #include <math.h> int main() { float l, h, w, n, t; scanf("%f%f%f", &l, &h, &w);
h /= 100; l /= 100; w /= 60;
h -= l/2; t = sqrt(2*h/9.81); n = t*w; n -= (int) n; if(n <= 0.25 || n >= 0.75) printf("butter"); else printf("bread");
return 0; } The first change float to double and respectivly change scanf like this double l, h, w, n, t; scanf("%lf%lf%lf", &l, &h, &w); and add the case if( l/2>h ){ printf("butter"); return 0; } and your get AC Sorry I didnot sea that your allready have AC on this problem 20:49:45 12 мар 2012 Got AC 0.015 with this magic code #define forn(i,n) for (int i = 0; i < (int)(n); i++) typedef long double ld; ld g = 9.81l; int main() { ld l, h, w; cin >> l >> h >> w; l /= 100, h /= 100, w *= acosl(0) / 15; ld t = 0; forn (i, 1000) { ld d = fabsl(sinl(w * t) * l / 2); //g x^2 /2 + (x-t)wl/2 + d = h //x^2 g/2 + x wl/2 - wlt/2+d-h = 0 t = (-w * l / 2 + sqrtl(w * w * l * l / 4 + 2 * g * (w * l * t / 2 - d + h))) / g; } cout << ((cosl(w * t) > 0) ? "butter": "bread"); } the next moment found the normal solution. Edited by author 19.10.2011 12:17 l/=100; h/=100; w/=60; if (l/2 >= h) cout<<"butter"<<endl; else { h -= l/2; t = sqrt(2*h/g); ob = t * w * 360;
if (ob >= 90 && ob <= 270 ) cout<<"bread"<<endl; else cout<<"butter"<<endl;
} Edited by author 29.04.2011 01:12 Edited by author 27.04.2011 00:25 var w,g,h,l,t:real; begin g:=981; read(l,h,w); if l/2>h then begin write('butter'); halt end; t:=sqrt(2*(h-l/2)/g); w:=frac(w*t/60); if ((w>=0) and (w<=1/4)) or ((w>=3/4) and (w<=1)) then write('butter') else write('bread'); end. var w,h,l:real; begin read(l,h,w); if l/2>h then begin write('butter'); halt end; if ((frac(w*sqrt(2*(h-l/2)/981)/60)>=0) and (frac(w*sqrt(2*(h-l/2)/981)/60)<=1/4)) or ((frac(w*sqrt(2*(h-l/2)/981)/60)>=3/4) and (frac(w*sqrt(2*(h-l/2)/981)/60)<=1)) then write('butter') else write('bread'); end. I thing that I don't need length of sandvich. t=sqrt(2*h/g) n=(t/60)*w May be it's wrong? Please answer. do anybody know why its wrong #include <cstdlib> #include <iostream> #include <math.h> using namespace std; int main(int argc, char *argv[]) { float l, h, omega; double long wynik, obroty_wykonane;
cin>> l >> h >> omega; obroty_wykonane=((omega/60)*sqrt(((h-(0.5*l))/450.5))); wynik=obroty_wykonane-floor(obroty_wykonane); if (wynik>0.25 && wynik<0.75) {cout << "bread"<< endl;} else {cout << "butter"<< endl;} return EXIT_SUCCESS; }
Try it: //-------------------- var c,l,h,w,t:real; begin readln(l,h,w); h:=h/100; l:=l/100; w:=w/60; if l/2>=h then writeln('butter') else begin h:=h-0.5*l; t:=sqrt(abs((2*h)/9.81)); c:=t*w; while c>1 do c:=c-1; if ((c<0.25)or(c>0.75)) then write('butter') else write('bread'); end; readln; end. //------------- Edited by author 29.01.2011 00:37 here is my code int main() { double l, h, w,N,angle; double P=3.14; double g=9.81,t,speed; cin>>l>>h>>w; t=sqrt(2*h/(g*100)); speed=w/60; N=t*speed; angle=N*360; while(angle>360) { angle=angle-1; } if(angle>90 && angle<270) cout<<"bread"; else cout<<"butter"; //system("pause"); } i think you need to remember about l in counting time te total hight should be h-0,5l because you must remember that after h-0,5l it can spin arround. and you have few more mistakes but i'm not sure of that because my one its not perfect to Edited by author 28.08.2011 02:03 В обоих случаях из примера бутерброд за время падения не совершает ни 1 полного оборота, соответственно он падает в обоих случаях маслом вниз. Скорость вращения - 1/4 оборота в секунду. Время падения 1 раз = 0,9. Количество оборотов 1 раз = 0,2258. Время падения 2 раз = 1,01. Количество оборотов 2 раз = 0,2524. В обоих случаях бутерброд НЕ совершает ни 1 полного оборота и должен упасть как и был, маслом вниз. Почему же ответы для 1 примера - "маслом вниз", а для 2 примера - "хлебом вниз"? во втором случае он совершает оборот за 1.005 с и 0,25 оборота в секунду т.е. за 1 секунду он повернется на 90 градусов и будет хлебом вниз Спасибо, разобрался =) Интересная задача. |
|