algorithm is this integration - andstudy/forge GitHub Wiki
[http://www.programming-challenges.com/pg.php?page=downloadproblem&probid=111307&format=html ๋ฌธ์ ๋ณด๊ธฐ] [http://www.programming-challenges.com/pg.php?page=studenthome&threshold=0&perpage=8&pagenum=12&orderby=12 13์ฅ Summit Pages]
- ๋ฐฑํฌ๋ ๋ํ๊ต 1ํ๋ !
- ์ค๋ซ๋ง์ ์ ๋ถํ๊บผ๋ด๋ค๊ณ ํ์์ต๋๋ค
- Programming-Challenges์์๋ WA, UVa์์๋ AC๋จ๋ค์.
- ์์ค๋ ๋ฏผ๋งํฉ๋๋ค.
- ๋๋ถ๋ถ์ ํ์ด๋ ์ข ์ด์ ๊ณ์ฐ๊ธฐ๋ก.
#include <stdio.h>
int main()
{
double in;
double s, d, r;
while( scanf("%lf", &in) >= 1 )
{
in *= in;
s = in*0.31514674363;
d = in*0.51129916633;
r = in*0.17355409004;
printf("%.3lf %.3lf %.3lf\n", s, d, r);
}
return 0;
}
-
wrong answer. ์?
- UVa์์๋ Accepted๋จ๋ค์! :D PC์ชฝ์ด ์ด์ํ๋ฏ...
- ์ฐ์ใ ๊ตณใ ๊ณ ๋ง์ต๋๋ค ^^
- UVa์์๋ Accepted๋จ๋ค์! :D PC์ชฝ์ด ์ด์ํ๋ฏ...
-
์ฌ๊ธฐ์ ๊ธฐ ์ ๊ทธ์ด์ ํ์ด
-
์ ๋ถ์ธ๊ฐ? ๋ผ๋ ์ง๋ฌธ์ ๋ํ ๋๋ต์ ์๋์ค
#include <iostream> #include <math.h> using namespace std; const double PI = 3.14159265359; double getStripedHeight(double radius) { double height = radius * (sqrt(3.0)-1) / 2; return height; } double getStriped(double radius) { double circlePart = (PI*radius*radius) / 12; double triangle = radius/2 * getStripedHeight(radius) / 2; double striped = 4 * (circlePart - 2*triangle); return striped; } double getDotted(double radius) { double circlePart = (PI*radius*radius)/4 - (radius*radius)/2; double dotted = 4 * (circlePart - getStriped(radius)/2); return dotted; } int main() { double length; while (cin >> length) { double striped = getStriped(length); double dotted = getDotted(length); double rest = length*length - striped - dotted; printf("%.3f %.3f %.3f\n", striped, dotted, rest); } return 0; }
- ์๊ณผ ์ ์ฌ๊ฐํ์ด ๊ต์ฐจ ํ ๋, ๊ฐ ๋ถ๋ถ ์์ญ์ ๋์ด ๊ตฌํ๊ธฐ
- ์ผ๊ฐํ๊ณผ ๋ถ์ฑ๊ผด์ ๋ณผ๋ก๋ถ๋ถ ๋์ด๋ฅผ ๊ตฌํด์ ํด๊ฒฐ
- ๋ต์ ์ฐจ์ด๊ฐ ๋๋ ์ด์ ๋ฅผ ๋ชจ๋ฅด๊ฒ ์;
- ์ ์๋ชป ํ์๋ค์.. ์ฌ๋ฆฌ๋ค ๋ฌธ์ ์ ๋ฐ๊ฒฌ ํ..
- ์, ์ ๋๋ก ๊ณ ์น๊ฑฐ ๊ฐ์๋ฐ.. Wrong Answer.. ํ..;
- UVa๊ฒฐ๊ณผ Accepted! Programming-challenges ํํ์ด์ง์ ๋ฌธ์ ๊ฐ ์๋๋ฏ^^;
// "Is This Integration" Solution By Outbreak
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
//#define _TDD
//---------------------------------------------------------------------------
namespace Solver
{
static const double PI = 3.14159265358979;
class ABCD
{
public:
ABCD(double r) : r(r) {}
public:
// ๊ฐ ์์ญ ๋์ด
double GetStripedArea()
{
return GetRectangleArea() + GetChordArea() * 4;
}
double GetDottedArea()
{
return GetTriangleArea() * 4 + GetChordArea() * 4;
}
double GetRestArea()
{
return r * r - GetStripedArea() - GetDottedArea();
}
private:
// ๋ถ์ฑ๊ผด ABD, CDB
double GetBigFanArea()
{
return (r * r * PI) / 4;
}
// ์ผ๊ฐํ ABD, CBD
double GetBigTriangleArea()
{
return r * r / 2;
}
// striped ์์ญ ๋ด๋ถ ์ ์ฌ๊ฐํ ๋์ด
double GetRectangleArea()
{
return GetChordLength() * GetChordLength();
}
// dotted ์์ญ ๋ด๋ถ ์ ์ผ๊ฐํ ๋์ด
double GetTriangleArea()
{
return sqrt((double)3)*GetChordLength()*GetChordLength()/4;
}
// striped ์ฌ๊ฐํ ๋๋ dotted ์ผ๊ฐํ์ ๋ณผ๋ก ๋ถ๋ถ ๋์ด
double GetChordArea()
{
return (GetBigFanArea() - GetBigTriangleArea() - GetRectangleArea()/2 - GetTriangleArea() ) / 3;
}
double GetChordLength()
{
return (r/2) / cos(PI/12);
}
private:
double r;
};
void Calculate(const double r, double& striped, double& dotted, double& rest)
{
ABCD abcd(r);
// striped
striped = abcd.GetStripedArea();
// dotted
dotted = abcd.GetDottedArea();
// rest
rest = abcd.GetRestArea();
}
}
//---------------------------------------------------------------------------
namespace Runner
{
void Execute(istream& in, ostream& out)
{
double a;
while( in >> a )
{
if( in.fail() )
break;
double striped = 0, dotted = 0, rest = 0;
// ๋ต ๊ตฌํ๊ธฐ
Solver::Calculate(a, striped, dotted, rest);
out << setprecision(3) << fixed << striped << " " << dotted << " " << rest << endl;
}
}
}
//---------------------------------------------------------------------------
#ifdef _TDD
#include "unittest++.h"
TEST(Output1)
{
stringstream input;
stringstream output;
input << "0.1";
Runner::Execute(input, output);
CHECK_EQUAL("0.003 0.005 0.002\n", output.str());
}
TEST(Output)
{
stringstream input;
stringstream output;
input << "0.1\n0.2\n0.3\n";
Runner::Execute(input, output);
CHECK_EQUAL("0.003 0.005 0.002\n0.013 0.020 0.007\n0.028 0.046 0.016\n", output.str());
}
#endif
//---------------------------------------------------------------------------
int main()
{
#ifdef _TDD
UnitTest::RunAllTests();
#else
Runner::Execute(cin, cout);
#endif // _TDD
return 0;
}
#include <iostream>
#include <cmath>
using namespace std;
float centerTriangleArea(float area)
{
//sqrt( 1-x^2 ) --> (x*sqrt(1 - x^2) + arcsin(x))/2;
//x=[0.5.. sqrt(3) / 2]
float center = 0.26179938090693;
float baseArea = 0.5 * ( sqrt(3.0) / 2.0 - 0.5 );
return 4*area*(center - baseArea);
}
float topTriangleArea(float area)
{
//sqrt( 1-x^2 ) --> (x*sqrt(1 - x^2) + arcsin(x))/2;
//x=[0..0.5]
float top = 0.47830573874525906;
return area * 8*(0.5 - top); //8์กฐ๊ฐ
}
float midTriangleArea(float area)
{
return area - centerTriangleArea(area) - topTriangleArea(area);
}
int main()
{
float scale;
while( std::cin >> scale )
{
if( std::cin.fail() )
break;
scale *= scale; //area
float center = centerTriangleArea(scale);
float top = topTriangleArea(scale);
float mid = midTriangleArea(scale);
printf("%.3f %.3f %.3f\n", center, mid, top );
}
return 0;
}