TopCoder-「TCHS SRM 1」答えとコード


「TCHS SRM 1」の答えとコード
 
テーマが密で英語にかかわるため、一つ一つリストするのは不便で、堅持したいと思っています.
TopCoderの具体的なURL:http://community.topcoder.com/
  TopCoder -
250-points:レーダー識別平均値の問題:
Code:
#include  #include  #include   using namespace std;  class SpeedRadar { public:     double averageSpeed (int minLimit, int maxLimit, std::vector  readings); };  double SpeedRadar::averageSpeed (int minLimit, int maxLimit, std::vector  readings){ 	size_t cnt = readings.size(); 	size_t lmtCnt = 0.1*cnt; 	double total(0.0); 	size_t infCnt(0); 	for (const auto& i : readings){ 		if(imaxLimit){ 			infCnt++; 			if(infCnt > lmtCnt){ 				total = 0.0; 				break; 			} 		}else{ 			total += i; 		} 	} 	return total/(cnt-infCnt); }

500-points:言語のアルファベット法則:
Code:
#include  #include  #include  #include  #include  #include  #include   using namespace std;  class SymbolFrequency { public: 	double language(vector  frequencies, vector  text); };  double SymbolFrequency::language(vector  frequencies, vector  text){ 	int asc(0); //ascii 	double cnt(0.0); //the count of alphabets 	double sum(0.0); //each language difference 	double result = std::numeric_limits::max(); //result 	std::array alpText = {0}; 	for(const auto& str : text){ 		for(const auto& c : str){ 			asc = static_cast(c); 			++alpText[asc-97]; 		} 	} 	cnt = std::accumulate(alpText.begin(), alpText.end(), 0); 	std::array alpFreq = {0}; 	for(const auto& fre : frequencies){ 		for(auto i=fre.cbegin(); i!=fre.cend(); i+=3){ 			asc = static_cast(*i); 			std::string fig = std::string(i+1, i+3); 			alpFreq[asc-97] = std::stod(fig)*cnt/100.0; 		} 		for(size_t i=0; i<26; ++i){ 			sum += std::pow(std::abs(alpFreq[i] - alpText[i]), 2.0); 		} 		result = (sum < result) ? sum : result; 		sum = 0; //reset 	} 	return result; }

 
TopCoder -