Artifact Content
Not logged in

Artifact 3ccaf00d30fae699d9869a77f09fbf398ba9c699


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

class RadioRange { public:
	double RadiusProbability(vector <int> X, vector <int> Y, vector <int> R, int Z)
	{
		vector<pair<double, bool>> ev;

		const int N = X.size();
		for(int i=0; i<N; ++i)
		{
			double x = X[i];
			double y = Y[i];
			double r = R[i];
			double d = sqrt(x*x+y*y);
			// (s,e) is bad
			double s = max(0.0, d-r);
			double e = min(double(Z), d+r);
			ev.emplace_back(s, true);
			ev.emplace_back(e, false);
		}

		double total_bad = 0.0;

		sort(ev.begin(), ev.end());
		int nest = 0;
		double prev_beg;
		for(auto ei: ev) {
			double x = ei.first;
			bool beg = ei.second;
			if(beg) {
				if(++nest == 1)
					prev_beg = x;
			}
			else {
				if(--nest == 0)
					total_bad += (x-prev_beg);
			}
		}

		return (Z - total_bad) / Z;
	}
};

// 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> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const double& Expected, const double& Received) {
 bool ok = (abs(Expected - Received) < 1e-9);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, RadioRange().RadiusProbability(X, Y, R, Z));}
int main(){

CASE(0)
	int X_[] = {0};
	  vector <int> X(X_, X_+sizeof(X_)/sizeof(*X_)); 
	int Y_[] = {0};
	  vector <int> Y(Y_, Y_+sizeof(Y_)/sizeof(*Y_)); 
	int R_[] = {5};
	  vector <int> R(R_, R_+sizeof(R_)/sizeof(*R_)); 
	int Z = 10; 
	double _ = 0.5; 
END
CASE(1)
	int X_[] = {0};
	  vector <int> X(X_, X_+sizeof(X_)/sizeof(*X_)); 
	int Y_[] = {0};
	  vector <int> Y(Y_, Y_+sizeof(Y_)/sizeof(*Y_)); 
	int R_[] = {10};
	  vector <int> R(R_, R_+sizeof(R_)/sizeof(*R_)); 
	int Z = 10; 
	double _ = 0.0; 
END
CASE(2)
	int X_[] = {10};
	  vector <int> X(X_, X_+sizeof(X_)/sizeof(*X_)); 
	int Y_[] = {10};
	  vector <int> Y(Y_, Y_+sizeof(Y_)/sizeof(*Y_)); 
	int R_[] = {10};
	  vector <int> R(R_, R_+sizeof(R_)/sizeof(*R_)); 
	int Z = 10; 
	double _ = 0.4142135623730951; 
END
CASE(3)
	int X_[] = {11, -11, 0, 0};
	  vector <int> X(X_, X_+sizeof(X_)/sizeof(*X_)); 
	int Y_[] = {0, 0, 11, -11};
	  vector <int> Y(Y_, Y_+sizeof(Y_)/sizeof(*Y_)); 
	int R_[] = {10, 10, 10, 10};
	  vector <int> R(R_, R_+sizeof(R_)/sizeof(*R_)); 
	int Z = 31; 
	double _ = 0.3548387096774194; 
END
CASE(4)
	int X_[] = {100};
	  vector <int> X(X_, X_+sizeof(X_)/sizeof(*X_)); 
	int Y_[] = {100};
	  vector <int> Y(Y_, Y_+sizeof(Y_)/sizeof(*Y_)); 
	int R_[] = {1};
	  vector <int> R(R_, R_+sizeof(R_)/sizeof(*R_)); 
	int Z = 10; 
	double _ = 1.0; 
END
CASE(5)
	int X_[] = {1000000000};
	  vector <int> X(X_, X_+sizeof(X_)/sizeof(*X_)); 
	int Y_[] = {1000000000};
	  vector <int> Y(Y_, Y_+sizeof(Y_)/sizeof(*Y_)); 
	int R_[] = {1000000000};
	  vector <int> R(R_, R_+sizeof(R_)/sizeof(*R_)); 
	int Z = 1000000000; 
	double _ = 0.41421356237309503; 
END
CASE(6)
	int X_[] = {20, -20, 0, 0};
	  vector <int> X(X_, X_+sizeof(X_)/sizeof(*X_)); 
	int Y_[] = {0, 0, 20, -20};
	  vector <int> Y(Y_, Y_+sizeof(Y_)/sizeof(*Y_)); 
	int R_[] = {50, 50, 50, 50};
	  vector <int> R(R_, R_+sizeof(R_)/sizeof(*R_)); 
	int Z = 100; 
	double _ = 0.3; 
END
CASE(7)
	int X_[] = {0, -60, -62, -60, 63, -97};
	  vector <int> X(X_, X_+sizeof(X_)/sizeof(*X_)); 
	int Y_[] = {-72, 67, 61, -8, -32, 89};
	  vector <int> Y(Y_, Y_+sizeof(Y_)/sizeof(*Y_)); 
	int R_[] = {6, 7, 8, 7, 5, 6};
	  vector <int> R(R_, R_+sizeof(R_)/sizeof(*R_)); 
	int Z = 918; 
	double _ = 0.9407071068962471; 
END
/*
CASE(8)
	int X_[] = ;
	  vector <int> X(X_, X_+sizeof(X_)/sizeof(*X_)); 
	int Y_[] = ;
	  vector <int> Y(Y_, Y_+sizeof(Y_)/sizeof(*Y_)); 
	int R_[] = ;
	  vector <int> R(R_, R_+sizeof(R_)/sizeof(*R_)); 
	int Z = ; 
	double _ = ; 
END
CASE(9)
	int X_[] = ;
	  vector <int> X(X_, X_+sizeof(X_)/sizeof(*X_)); 
	int Y_[] = ;
	  vector <int> Y(Y_, Y_+sizeof(Y_)/sizeof(*Y_)); 
	int R_[] = ;
	  vector <int> R(R_, R_+sizeof(R_)/sizeof(*R_)); 
	int Z = ; 
	double _ = ; 
END
*/
}
// END CUT HERE