很機車的實作題,這種題目就是要面面俱到,把所有的情況用if表達出來
// BEGIN CUT HERE
// END CUT HERE
#line 5 "GCAcode.cpp"
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
#ifdef DEBUG
#define VAR(a,b) __typeof(b) a=(b)
#define debug(...) printf("DEBUG: "),printf(__VA_ARGS__)
#else
#define VAR(a,b) __typeof(b) a=(b)
#define debug(...)
#endif
typedef unsigned int uint;
typedef long long int Int;
typedef unsigned long long int UInt;
#define Set(a,s) memset(a,s,sizeof(a))
#define Pln() printf("\n")
#define For(i,x)for(int i=0;i<x;i++)
#define CON(x,y) x##y
#define M MAX_LIMITS
#define PB push_back
#define oo INT_MAX
#define FOR(a,b) for(VAR(a,(b).begin());a!=(b).end();++a)
#define eps 1e-9
#define X first
#define Y second
inline bool xdy(double x,double y){return x>y+eps;}
inline bool xddy(double x,double y){return x>y-eps;}
inline bool xcy(double x,double y){return x<y-eps;}
inline bool xcdy(double x,double y){return x<y+eps;}
const Int mod=1000000007;
class WaterLevel
{
public:
double netAmt(int evapNormal, int evapFlood, vector <int> rain)
{
double now=0;
double part=1.;
for(int i=0;i<rain.size();){
if(now==0){//central
double t=rain[i]*part-evapNormal*part;
if(t<=0){
now+=t;
}
else{
t=rain[i]*part-evapFlood*part;
if(t>0){
now+=t;
}else{
now=0;
}
}
part=1.;
i++;
}else if(now<0){
double t=rain[i]*part-evapNormal*part;
if(t+now>=0){//can reach flood stage
part=1-(-now/t);
now=0;
}else{
now+=t;
part=1.;
i++;
}
}else{//now over flood stage
double t=rain[i]*part-evapFlood*part;
if(t+now<=0){
part=(1-(-now)/t);
now=0;
}else{
now+=t;
part=1.;
i++;
}
}
printf("%.2f %d\n",now,i);
}
return now;
}
// BEGIN CUT HERE
public:
void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); if ((Case == -1) || (Case == 4)) test_case_4();}
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) { cout << "Test Case #" << Case << "..."; if (Expected == Received) cout << "PASSED" << endl; else { cout << "FAILED" << endl; cout << "\tExpected: \"" << Expected << '\"' << endl; cout << "\tReceived: \"" << Received << '\"' << endl; } }
void test_case_0() { int Arg0 = 20; int Arg1 = 40; int Arr2[] = {0,60,0,0}; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); double Arg3 = -35.0; verify_case(0, Arg3, netAmt(Arg0, Arg1, Arg2)); }
void test_case_1() { int Arg0 = 20; int Arg1 = 39; int Arr2[] = {0,60}; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); double Arg3 = 10.5; verify_case(1, Arg3, netAmt(Arg0, Arg1, Arg2)); }
void test_case_2() { int Arg0 = 20; int Arg1 = 40; int Arr2[] = {0}; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); double Arg3 = -20.0; verify_case(2, Arg3, netAmt(Arg0, Arg1, Arg2)); }
void test_case_3() { int Arg0 = 200; int Arg1 = 800; int Arr2[] = {0,600}; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); double Arg3 = 0.0; verify_case(3, Arg3, netAmt(Arg0, Arg1, Arg2)); }
void test_case_4() { int Arg0 = 300; int Arg1 = 379; int Arr2[] = {0, 800, 0, 800, 512, 555, 1000}; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); double Arg3 = 0.0; verify_case(4, Arg3, netAmt(Arg0, Arg1, Arg2)); }
// END CUT HERE
};
// BEGIN CUT HERE
int main()
{
WaterLevel ___test;
___test.run_test(-1);
return 0;
}
// END CUT HERE
留言
張貼留言