Artifact Content
Not logged in

Artifact 70860f519d844ba538f20bb5f7c7abb7da603acd


#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 <cstring>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class Inequalities { public:
	int maximumSubset(vector <string> inequalities) 
	{
		set<double> v;

		for(int i=0; i<inequalities.size(); ++i)
		{
			stringstream ss(inequalities[i]);
			char _; string OP; double C;
			ss >> _ >> OP >> C;

			v.insert(C);
		}

		set<double> vv = v;
		vv.insert( *v.begin() - 1 );
		vv.insert( *v.rbegin() + 1 );

		for(set<double>::iterator it=v.begin(); it!=v.end(); ++it)
		for(set<double>::iterator jt=v.begin(); jt!=v.end(); ++jt)
			vv.insert( (*it + *jt)/2 );

		int maxSat = 0;
		for(set<double>::iterator it=vv.begin(); it!=vv.end(); ++it)
		{
			double X = *it;

			int sat = 0;
			for(int i=0; i<inequalities.size(); ++i)
			{
				stringstream ss(inequalities[i]);
				char _; string OP; double C;
				ss >> _ >> OP >> C;

				if( (OP=="<" && X<C)
				 || (OP=="<=" && X<=C)
				 || (OP=="=" && X==C)
				 || (OP==">" && X>C)
				 || (OP==">=" && X>=C) )
					++sat;
			}
			maxSat = max(maxSat, sat);
		}
		return maxSat;
	}
};

// 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 int& Expected, const int& Received) {
 bool ok = (Expected == Received);
 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(_, Inequalities().maximumSubset(inequalities));}
int main(){

CASE(0)
	string inequalities_[] = {"X <= 12","X = 13","X > 9","X < 10","X >= 14"};
	  vector <string> inequalities(inequalities_, inequalities_+sizeof(inequalities_)/sizeof(*inequalities_)); 
	int _ = 3; 
END
CASE(1)
	string inequalities_[] = {"X < 0","X <= 0"};
	  vector <string> inequalities(inequalities_, inequalities_+sizeof(inequalities_)/sizeof(*inequalities_)); 
	int _ = 2; 
END
CASE(2)
	string inequalities_[] = {"X = 1","X = 2","X = 3","X > 0"};
	  vector <string> inequalities(inequalities_, inequalities_+sizeof(inequalities_)/sizeof(*inequalities_)); 
	int _ = 2; 
END
CASE(3)
	string inequalities_[] = {"X <= 521","X >= 521","X = 521","X > 902","X > 12","X <= 1000"};
	  vector <string> inequalities(inequalities_, inequalities_+sizeof(inequalities_)/sizeof(*inequalities_)); 
	int _ = 5; 
END
CASE(4)
	string inequalities_[] = {"X > 0"};
	  vector <string> inequalities(inequalities_, inequalities_+sizeof(inequalities_)/sizeof(*inequalities_)); 
	int _ = 1; 
END
CASE(5)
	string inequalities_[] = {"X > 0", "X <= 0"};
	  vector <string> inequalities(inequalities_, inequalities_+sizeof(inequalities_)/sizeof(*inequalities_)); 
	int _ = 1; 
END
CASE(6)
	string inequalities_[] = {"X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", "X = 0", };
	  vector <string> inequalities(inequalities_, inequalities_+sizeof(inequalities_)/sizeof(*inequalities_)); 
	int _ = 50; 
END

}
// END CUT HERE