Artifact Content
Not logged in

Artifact b3187b46cfd5d3bbd5610c1c8253691fcfa46d83


#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
using namespace std;
typedef long long LL;

class LaserShooting
{
public:
	double numberOfHits(vector <int> x, vector <int> y1, vector <int> y2) 
	{
		double ans = 0.0;
		for(int i=0; i<x.size(); ++i)
		{
			double a1 = atan2(min(y1[i],y2[i]), x[i]);
			double a2 = atan2(max(y1[i],y2[i]), x[i]);
			ans += (a2-a1) / M_PI;
		}
		return ans;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time;string timer() { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }

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(); }
int verify_case(const double &Expected, const double &Received) { double diff = Expected - Received; if (diff < 0) diff = -diff; if (diff < 1e-9) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } return 0;}

template<int N> struct Case_ { Case_(){start_time=clock();} };
char Test_(...);
int Test_(Case_<0>) {
	int x_[] = {1};
	  vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 
	int y1_[] = {-1};
	  vector <int> y1(y1_, y1_+sizeof(y1_)/sizeof(*y1_)); 
	int y2_[] = {1};
	  vector <int> y2(y2_, y2_+sizeof(y2_)/sizeof(*y2_)); 
	double RetVal = 0.5; 
	return verify_case(RetVal, LaserShooting().numberOfHits(x, y1, y2)); }
int Test_(Case_<1>) {
	int x_[] = {1,2};
	  vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 
	int y1_[] = {-1,-2};
	  vector <int> y1(y1_, y1_+sizeof(y1_)/sizeof(*y1_)); 
	int y2_[] = {1,2};
	  vector <int> y2(y2_, y2_+sizeof(y2_)/sizeof(*y2_)); 
	double RetVal = 1.0; 
	return verify_case(RetVal, LaserShooting().numberOfHits(x, y1, y2)); }
int Test_(Case_<2>) {
	int x_[] = {3,4,7,1};
	  vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 
	int y1_[] = {1,2,3,4};
	  vector <int> y1(y1_, y1_+sizeof(y1_)/sizeof(*y1_)); 
	int y2_[] = {4,3,2,1};
	  vector <int> y2(y2_, y2_+sizeof(y2_)/sizeof(*y2_)); 
	double RetVal = 0.4623163952488826; 
	return verify_case(RetVal, LaserShooting().numberOfHits(x, y1, y2)); }
int Test_(Case_<3>) {
	int x_[] = {134,298,151,942};
	  vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 
	int y1_[] = {-753,-76,19,568};
	  vector <int> y1(y1_, y1_+sizeof(y1_)/sizeof(*y1_)); 
	int y2_[] = {440,689,-39,672};
	  vector <int> y2(y2_, y2_+sizeof(y2_)/sizeof(*y2_)); 
	double RetVal = 1.444210260641501; 
	return verify_case(RetVal, LaserShooting().numberOfHits(x, y1, y2)); }

template<int N> void Run_() { cerr << "Test Case #" << N << "..." << flush; Test_(Case_<N>()); Run_<sizeof(Test_(Case_<N+1>()))==1 ? -1 : N+1>(); }
template<>      void Run_<-1>() {}
int main() { Run_<0>(); }
// END CUT HERE