Show all threads Hide all threads Show all messages Hide all messages |
Hint for everybody! : ) | Pavel Nikolov | 1084. Goat in the Garden | 2 Dec 2021 10:06 | 6 |
Hi I think that we should help each other. If someone resolves a problem he/she must help the others with materials or links where the algorithm/formula is explained. This is the reason we are users of such sites - because we want to improve our programming skills. So I decided to help all of you who find this problem difficult. Here you can find help: http://en.wikipedia.org/wiki/Circular_segment http://www.mathopenref.com/segmentarea.html The rest is up to you! HTH Edited by author 22.10.2013 12:23 thanks dude, i didn't even understood what the question was asking :) Thanks, bro, you are real man! |
WA#4 | LittleStuart | 1084. Goat in the Garden | 23 Sep 2021 01:28 | 1 |
WA#4 LittleStuart 23 Sep 2021 01:28 Why I have WA? #include <iostream> #include <cmath> using namespace std; int main() { double const pi = 3.14159265358979323846; double a; double r; cin >> a >> r; long double s = pi * r * r; if (r <= a / 2) { cout << roundl(s * 1000) / 1000; } else if (r >= ((a / 2) * sqrt(2))) { cout << (int) (a * a) << endl; } else { double cosx; cosx = (a / 2) / r; double rad; rad = acos(cosx) * 2; double segm = (r * r / 2) * (rad - sin(rad)); s = s - 4 * segm; cout << round(s * 1000) / 1000 << endl; } return 0; } |
Why WA on test #4 | nikhil | 1084. Goat in the Garden | 22 Jun 2020 19:29 | 2 |
#include <bits/stdc++.h> #define gif(a,b) ((a)/(b)+((a)%(b)?1:0)) #define float long double #define int long long //#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define w(x) cout<<(#x)<<" is "<<(x)<<"\n"; using namespace std; int32_t main() { //IOS float a, r; cin >> a >> r; float theta = acos(a/(2*r));
float s = sin(theta);
float pi = acos(-1); if(a/2 > r) printf("%0.3Lf",pi*r*r); else if(r > a/pow(2, 0.5)) cout << a*a; else cout << (pi*r*r) - 4*(r*r*theta - a*r*s/2) ; return 0; } Проблема с точностью. исправьте "cout << (pi*r*r) - 4*(r*r*theta - a*r*s/2) ;" на "cout << fixed << setprecision(3) << (pi*r*r) - 4*(r*r*theta - a*r*s/2) ;". UPD: Попрошу не выкладывать свой код на форуме, он создан для обсуждения, а не для выкладывания на нем готовых решений. Поэтому прошу его убрать. Edited by author 22.06.2020 19:34 |
easy solution in c++ | Yucheng | 1084. Goat in the Garden | 2 Mar 2019 14:50 | 1 |
#include<iostream> #include<cmath> #include<iomanip> #define pi 3.1415926 using namespace std; int main(){ float side,len; cin>>side>>len; if(len>(side/2)*sqrt(2)){ cout<<fixed<<setprecision(3)<<side*side; return 0; } if((side/2)>=len){ cout<<fixed<<setprecision(3)<<len*len*pi; return 0; } float cosx=(side/2)/len; float sinx=sqrt(1-cosx*cosx); float cosA=2*sinx*cosx; float theta=acos(cosA); cout<<fixed<<setprecision(3)<<len*len*0.5*theta*4+sqrt(len*len-(side/2)*(side/2))*(side/2)*4;
return 0; } |
accepted | Mikhail | 1084. Goat in the Garden | 17 Nov 2018 22:18 | 2 |
//#pragma GCC optimize("Ofast,no-stack-protector") //#pragma GCC target("avx") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds; using namespace std;
#define re return #define pb push_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define fi first #define se second #define sqrt(x) sqrt(abs(x)) #define mp make_pair #define pi (3.14159265358979323846264338327950288419716939937510) #define fo(i, n) for(int i = 0; i < n; ++i) #define ro(i, n) for(int i = n - 1; i >= 0; --i) #define unique(v) v.resize(unique(all(v)) - v.begin())
template <class T> T abs (T x) { re x > 0 ? x : -x; } template <class T> T sqr (T x) { re x * x; } template <class T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; } template <class T> int sgn (T x) { re x > 0 ? 1 : (x < 0 ? -1 : 0); }
typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<string> vs; typedef double D; typedef long double ld; typedef long long ll; typedef pair<ll, ll> pll; typedef vector<ll> vll; typedef unsigned long long ull; typedef tree <pair<int, char>, null_type, less<pair<int, char>>, rb_tree_tag, tree_order_statistics_node_update> _tree; int main() { cout.precision(10); double r, a; cin >> a >> r; double h = 2 * sqrt(r * r - a * a / 4); if (r <= a / 2) cout << pi * r * r / 2 << endl; else if (r >= a * sqrt(2) / 2) cout << a * a << endl; else cout << pi * r * r + a * h - 2 * r * r * (double)asin(a * h / (2 * r * r)) << endl; re 0; } Look at this overkill and still Accepted #include <math.h> #include <iostream> #include <math.h> #include <iomanip> using namespace std; double n, r; double pi = 3.141592654; int main() { cin >> n >> r; if(r <= n / 2) { cout << fixed << setprecision(3) << pi * r * r; return 0; } if(r >= n * sqrt(2) / 2) { cout << fixed << setprecision(3) << n * n; return 0; } cout << fixed << setprecision(3) << (r * (r * asin(-sqrt(r * r - n * n / 4) / r) + (-sqrt(r * r - n * n / 4) * -sqrt(-(-sqrt(r * r - n * n / 4) - r) * (-sqrt(r * r - n * n / 4) + r))) / r) / 2 - r * (r * asin(-n / 2 / r) + (-n / 2 * -sqrt(-(-n / 2 - r) * (-n / 2 + r))) / r) / 2 + n / 2 * sqrt(r * r - n * n / 4)) * 4; return 0; } |
if you have WA | Alexander (201 - P TNU) | 1084. Goat in the Garden | 17 Sep 2017 00:46 | 6 |
I have WA, when I defined pi with 5 numbers after point. and when I have tried pi = 3.1415926535, I got AC. It's strange a little) Thanks! It really helps=) Thank you :). Your clue really helped; |
For whom, who get WA 4 | Gleb_Kazantaev(NNSTU) | 1084. Goat in the Garden | 12 Feb 2017 14:06 | 2 |
if(a/2. >= r) { printf("%.3lf", pi*r*r); return 0; } This is 4th test, use only "%.3lf" ! Yeah, thanks a lot. There are terrible tests |
WA #3 | Vishakha Banka | 1084. Goat in the Garden | 24 Oct 2016 18:58 | 1 |
WA #3 Vishakha Banka 24 Oct 2016 18:58 I'm getting wrong ans on test case 3. Can someone please give a hint? Here's my solution in Java: FastReader sc = new FastReader(System.in); double a = sc.nextDouble(); double r = sc.nextDouble(); double ans; if (r <= a / 2) { ans = Math.PI * r * r; } else { double angle = (2 * Math.PI) - (8 * Math.acos(a / (2 * r))); ans = (r * r * angle / 2) + (2 * a * Math.sqrt(r * r - a * a / 4)); } System.out.println(String.format("%.3f", ans)); |
If you WA on #9 | findslowly | 1084. Goat in the Garden | 1 Jan 2016 17:52 | 5 |
Maybe you can try to declare l,r as double not int :) Haha, define like this works, double sideLength = in.nextDouble(); double ropeLength = in.nextDouble(); that's so weired. |
Difficulty | Marius Žilėnas | 1084. Goat in the Garden | 23 Jul 2015 03:05 | 2 |
Simple but interesting problem. There are two ways to find angle: geometrically (i made it this way) or computationally :). |
Не хочет компилить, а в VS на компе всё равботает. | partizan1977 | 1084. Goat in the Garden | 31 Oct 2014 16:50 | 2 |
Может я чего-то не догоняю, но у меня всё работает на компе и высчитывает вроде верно, а при заливе кода на сайт пишет ошибку компиляции. Прошу помощи более опытных #include <iostream> #include <math.h> using namespace std; int main() { const double pi = 3.141592653589793238462643383279; int n = 0, r = 0; double k = 0, s = 0, x = 0, ot = 0, d = 0, a = 0,acos = 0; cin >> n >> r; a = double (sqrt(2 * n*n)) / 2; /*Нахождение диагонали квадрата, для сравнения с R*/ if (r <= n/2) ot = pi * r*r; if (r >= a) ot = n * n; else { d = n / 2; acos = (pi / 2) - atan((d / r) / sqrt(1 - (d / r)*(d / r))); x = 2 * acos; s = 4 * (0.5*r*r*(x - sin(x))); ot = pi*r*r - s; } ot = round(ot * 1000) / 1000; cout << ot; system("pause"); return 0; } "Compilation Error" is a link, click there and see what's wrong |
пусти козла в огород | 146110zol | 1084. Goat in the Garden | 31 Oct 2014 01:21 | 3 |
не фига ответ не такой 95.0.... я посчитал другой пусть нормально пишут Даже не знаю, что посоветовать тебе выучить - русский язык или геометрию. Ты кретин? Там радиус 6, сторона города по 10, нитка с центра, значит с каждой стороны круг выходит по метру, я считать нужно то, что внутри квадрате! |
anyone can tell me what's wrong? | mon | 1084. Goat in the Garden | 17 May 2014 17:54 | 6 |
thanks... #include <stdio.h> #include <math.h> #define PI 3.1416 int main() { double a, r, area; scanf("%lf%lf", &a, &r); a /= 2; if (a >= r) { printf("%.3f\n", PI * r * r); return 0; } if (r >= sqrt(2) * a) { printf("%.3f\n", 4 * a * a); return 0; } printf("%.3f\n", PI * r * r - 4 * (acos(a / r) * r * r - a * sqrt(r * r - a * a))); return 0; } > thanks... > > #include <stdio.h> > #include <math.h> ?????? You can use integral to calculate the area Instead of using any mathematic function. I should use ".3lf" instead of ".3f" in the format string of printf. > I should use ".3lf" instead of ".3f" in the format string > of printf. #define PI 3.1416 // no #define PI 3.1415926535897932 //yes Better to use standard M_PI Edited by author 17.05.2014 17:54 |
My AC program (do not see it if you want to think without help) | happylist | 1084. Goat in the Garden | 17 May 2014 17:51 | 3 |
var a,r:integer; az,s,stru,b:real; function ArcCos ( X : Real ): Real; var tmpArcCos : Real; begin if X = 0.0 then tmpArcCos := Pi / 2.0 else tmpArcCos := ArcTan ( Sqrt ( 1 - X * X ) / X ); if X < 0.0 then tmpArcCos := Pi - tmpArcCos; ArcCos := 180*tmpArcCos/pi; end; begin readln(a,r); if a/2>=r then writeln(pi*r*r:1:3) else if sqrt(2)/2*a<=r then writeln(a*a) else begin az:=2*arccos((a/2)/r); s:=pi*r*r*az/360; b:=2*sqrt((r-a/2)*(r+a/2)); stru:=a/4*b; s:=s-stru; s:=pi*r*r-4*s; writeln(s:1:3); end; readln; end. Edited by author 17.05.2014 17:52 It is easy to put your code, where nothing is clear and say: "Look idiots, how clever I am". Try to help people, instead of showing off yourself. |
WA #7 Why? | wolfpro | 1084. Goat in the Garden | 17 May 2014 17:44 | 2 |
#include <iostream> #include <cmath> #include <stdio.h> int main() { using namespace std; int nRadius, nLenght; double dAnswer, dPi = 3.141592654; cin >> nLenght >> nRadius; if (nRadius * nRadius >= nLenght * nLenght / 2) { dAnswer = nLenght * nLenght; } else if (nRadius <= nLenght / 2) { dAnswer = nRadius * nRadius * dPi; } else { double dX = sqrt(nRadius * nRadius - nLenght * nLenght / 4); double dSg = dPi * nRadius * nRadius / 360 * (360 - 8 * atan2(dX, nLenght / 2) * 57.296); dAnswer = dSg + 4 * nLenght / 2 * dX; } printf("%0.3f", dAnswer); return 0; } Edited by author 31.08.2013 17:00 Edited by author 31.08.2013 17:00 Firstly calculate all in radians, don't even think about degrees, because all of cmath functions works in radians. And you should change all integers to double. Example: change 8 to 8.0 and so on. Use standart pi constant M_PI Check all functions. Edited by author 17.05.2014 17:45 |
Precision problem... again | Vlad | 1084. Goat in the Garden | 25 Jan 2014 01:54 | 1 |
#include <iostream> #include <fstream> #include <cmath> #define PI 3.14159265358979323846 using namespace std; #ifndef ONLINE_JUDGE #define cin fin ifstream fin("input"); #endif double N, R; int main() { cin >> N >> R; N /= 2.0;
if (R <= N) { cout << PI * R * R << '\n'; return 0; } if (R >= N * sqrt(2.0)) { cout << 4.0 * N * N << '\n'; return 0; }
double A, B, C; A = N; C = R; B = sqrt(C * C - A * A); double angle = 90.0 - (acos(A / C) * 180.0 / PI) * 2.0;
printf("%.3lf\n", 4.0 * (A * B + PI * R * R * angle / 360.0)); } This program works fine on all the tests I saw on the forum. But I get WA #1 probably because of the wrong precision. I printed the value with 4 and 6 decimals but I get the same WA #1. Could anyone tell me please how can I solve the "error" ? It's annoying to have a good solution and take WA. Thanks a lot! LATER EDIT: It seems I succeeded with such a function: inline void precise(double X, const int &decimals) { cout << (int)(X); cout << '.'; X = X - (int)(X); for (int i = 1; i <= decimals; ++i) { X = X * 10.0; cout << (int)(X); X = X - (int)(X); } cout << '\n'; } ... precise((double)(4.0 * (A * B + PI * R * R * angle / 360.0)), 3); Have fun! Edited by author 25.01.2014 04:19 |
stupid but works :) | pera-zdera | 1084. Goat in the Garden | 17 May 2013 03:34 | 4 |
#include <stdio.h> #include <stdlib.h> #include <iostream> #include <cstdlib> #include <math.h> #define PI 3.141592653589793238462643383279502884197169399375 using namespace std; int main(int argc, char** argv){ double a, l, angle = 0.0; cin >> a >> l; if (l <= (a/2.0)) printf("%0.3f", (l*l*PI)); else if (l >= (a*sqrt(2.0)/2.0)) printf("%0.3f", (a*a)); else { while (l*cos(angle) > (a/2.0)) angle += 0.0000001; printf("%0.3f", 4.0*((a/2.0)*l*sin(angle)+(l*l*(PI/4.0-angle)))); } } please explain : else { while (l*cos(angle) > (a/2.0)) angle += 0.0000001; printf("%0.3f", 4.0*((a/2.0)*l*sin(angle)+(l*l*(PI/4.0-angle)))); } i don't understand with your way of thinking to get that calculation.. please explain to me.. His solution is not stupid instead it is great I tried with mathematic way to find l to the point where the circle crosess the rect but every time i got WA. l*cos(angle) -that means the length to the point where the circle crosses the rect-s side.At the begining it is equals to r but as we increase angel the cos(angel) decreases the value and we find the exact length. and here ("%0.3f", 4.0*((a/2.0)*l*sin(angle) we find the are of triangles and add the are of sectors +(l*l*(PI/4.0-angle))...that is all ..if you don't understand again contact me with the problem name.. imran_yusubov@yahoo.com please explain : else { while (l*cos(angle) > (a/2.0)) angle += 0.0000001; printf("%0.3f", 4.0*((a/2.0)*l*sin(angle)+(l*l*(PI/4.0-angle)))); } i don't understand with your way of thinking to get that calculation.. please explain to me.. Edited by author 07.08.2009 12:19 Edited by author 07.08.2009 12:20Why woudn`t you just use acos(a/(l*2)) to get an angle? ( its arc cos in the triangle we get there) |\ | \ | \ | \ l | \ |a/2 \ | \ |_______\ |
WA | Student_MAT-MEX | 1084. Goat in the Garden | 29 Jun 2012 18:44 | 2 |
WA Student_MAT-MEX 9 Feb 2012 14:04 Re: WA Soucup Adrian 29 Jun 2012 18:44 or like this: float const pi = 4.f * atanf(1.f); You don't need double precision to get AC Edited by author 29.06.2012 18:44 |
>.< | Jordan Team | 1084. Goat in the Garden | 26 Oct 2011 02:01 | 1 |
>.< Jordan Team 26 Oct 2011 02:01 please whate is the case # 4??????????? |
what's wrong with test9? | Berlin | 1084. Goat in the Garden | 1 Oct 2011 13:21 | 3 |
this is my programm (WA 9): #include <iostream> #include <cmath> #include <iomanip> #define PI 3.1415926535897932 using namespace std; int answer(int n, int k); int main() { int a,r; cin>>a>>r; double d=a/2; double O=2*acos(d/r); double s=2*r*r*(O-sin(O)); double sk=PI*r*r; double sq=a*a; if (r<=a/2) cout<<setiosflags(ios::fixed)<<setprecision(3)<<sk<<endl; else if (r>=a*(sqrt(2.0)/2)) cout<<setiosflags(ios::fixed)<<setprecision(3)<<sq<<endl; else cout<<setiosflags(ios::fixed)<<setprecision(3)<<sk-s<<endl; } should be "double d = a/2.0;" in line 3 in main function |