题意:按一定方法生成n个分数,求他们的和。n <= 20
解法:暴力。我只是没想到,10000^20用double算也能被接受0 0
tag:brute-force
// BEGIN CUT HERE
/*
* Author: plum rain
* score :
*/
/* */
// END CUT HERE
#line 11 "ApproximateDivision.cpp"
#include <sstream>
#include <stdexcept>
#include <functional>
#include <iomanip>
#include <numeric>
#include <fstream>
#include <cctype>
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <set>
#include <queue>
#include <bitset>
#include <list>
#include <string>
#include <utility>
#include <map>
#include <ctime>
#include <stack> using namespace std; #define clr0(x) memset(x, 0, sizeof(x))
#define clr1(x) memset(x, -1, sizeof(x))
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(t) t.begin(),t.end()
#define zero(x) (((x)>0?(x):-(x))<eps)
#define out(x) cout<<#x<<":"<<(x)<<endl
#define tst(a) cout<<a<<" "
#define tst1(a) cout<<#a<<endl
#define CINBEQUICKER std::ios::sync_with_stdio(false) typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef long long int64; const double eps = 1e-;
const double PI = atan(1.0)*;
const int inf = / ; class ApproximateDivision
{
public:
double quotient(int a, int b, int terms){
int t = ;
while (t <= b){
if (t == b) return (double)a / b;
t *= ;
}
int c = t - b, cnt = ;
double t1 = 1.0, t2 = t;
double sum = ;
while (cnt < terms){
sum += a * t1 / t2;
t1 *= c; t2 *= t;
++ cnt;
}
return sum;
} // BEGIN CUT HERE
public:
void run_test(int Case) { if ((Case == -) || (Case == )) test_case_0(); if ((Case == -) || (Case == )) test_case_1(); if ((Case == -) || (Case == )) test_case_2(); if ((Case == -) || (Case == )) test_case_3(); if ((Case == -) || (Case == )) test_case_4(); if ((Case == -) || (Case == )) test_case_5(); if ((Case == -) || (Case == )) test_case_6(); }
private:
template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
void verify_case(int Case, const double &Expected, const double &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
void test_case_0() { int Arg0 = ; int Arg1 = ; int Arg2 = ; double Arg3 = 0.34375; verify_case(, Arg3, quotient(Arg0, Arg1, Arg2)); }
void test_case_1() { int Arg0 = ; int Arg1 = ; int Arg2 = ; double Arg3 = 0.875; verify_case(, Arg3, quotient(Arg0, Arg1, Arg2)); }
void test_case_2() { int Arg0 = ; int Arg1 = ; int Arg2 = ; double Arg3 = 0.33333301544189453; verify_case(, Arg3, quotient(Arg0, Arg1, Arg2)); }
void test_case_3() { int Arg0 = ; int Arg1 = ; int Arg2 = ; double Arg3 = 8.481740951538086E-5; verify_case(, Arg3, quotient(Arg0, Arg1, Arg2)); }
void test_case_4() { int Arg0 = ; int Arg1 = ; int Arg2 = ; double Arg3 = 0.14285714285714285; verify_case(, Arg3, quotient(Arg0, Arg1, Arg2)); }
void test_case_5() { int Arg0 = ; int Arg1 = ; int Arg2 = ; double Arg3 = 0.0; verify_case(, Arg3, quotient(Arg0, Arg1, Arg2)); }
void test_case_6() { int Arg0 = ; int Arg1 = ; int Arg2 = ; double Arg3 = 0.78125; verify_case(, Arg3, quotient(Arg0, Arg1, Arg2)); } // END CUT HERE }; // BEGIN CUT HERE
int main()
{
// freopen( "a.out" , "w" , stdout );
ApproximateDivision ___test;
___test.run_test(-);
return ;
}
// END CUT HERE