TopCoder - "TCHS SRM 1" 答案 及 代码
来源:互联网 发布:网络推手的盈利模式 编辑:程序博客网 时间:2024/06/04 00:41
"TCHS SRM 1" 答案 及 代码
由于题目涉密以及英文, 不方便一一列出, 希望能坚持下去;
TopCoder具体网址:http://community.topcoder.com/
250-points: 雷达识别均值问题:
Code:
#include <string>#include <vector>#include <cstddef>using namespace std;class SpeedRadar {public: double averageSpeed (int minLimit, int maxLimit, std::vector <int> readings);};double SpeedRadar::averageSpeed (int minLimit, int maxLimit, std::vector <int> 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(i<minLimit || i>maxLimit){infCnt++;if(infCnt > lmtCnt){total = 0.0;break;}}else{total += i;}}return total/(cnt-infCnt);}
500-points: 语言的字母规律:
Code:
#include <string>#include <vector>#include <array>#include <numeric>#include <cmath>#include <limits>#include <cstddef>using namespace std;class SymbolFrequency {public:double language(vector <string> frequencies, vector <string> text);};double SymbolFrequency::language(vector <string> frequencies, vector <string> text){int asc(0); //asciidouble cnt(0.0); //the count of alphabetsdouble sum(0.0); //each language differencedouble result = std::numeric_limits<double>::max(); //resultstd::array<double, 26> alpText = {0};for(const auto& str : text){for(const auto& c : str){asc = static_cast<int>(c);++alpText[asc-97];}}cnt = std::accumulate(alpText.begin(), alpText.end(), 0);std::array<double, 26> alpFreq = {0};for(const auto& fre : frequencies){for(auto i=fre.cbegin(); i!=fre.cend(); i+=3){asc = static_cast<int>(*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 - "TCHS SRM 1" 答案 及 代码
- TCHS SRM 31 Problem 500
- topcoder srm 519 div 1
- Topcoder SRM 597 DIV 1
- Topcoder SRM 596 DIV 1
- Topcoder SRM 598 DIV 1
- TopCoder SRM 144 DIV 1
- TopCoder SRM 657 DIV 1
- TopCoder SRM 669 DIV 1
- topcoder SRM div 2 level 1
- topcoder SRM 144 DIV 1 by First_Blood
- Topcoder SRM 547 DIV1 Level 1: Pillars
- TopCoder SRM 597 Div1 第1题
- TopCoder SRM 598 Div1 第1题
- TopCoder SRM 602 Div1 第1题
- TopCoder SRM 604 Div1 第1题
- TopCoder SRM 612 DIV 1 450 SpecialCells
- topcoder SRM 348 Div.1 LostParentheses
- 辞职感言
- OpenCV中对Mat里面depth,dims,channels,step,data,elemSize和数据地址计算的理解
- H3C交换机流量镜像
- 炒股的鱼
- Linux下利用nc命令来监控检测服务器的端口使用情况
- TopCoder - "TCHS SRM 1" 答案 及 代码
- 合并排序
- 选择图形,计算面积
- UIWebView的一些总结
- 一个普普通通的计算机研究生找工作的感悟
- ios下获取所有实体/虚拟网卡的信息,并以此判断设备所处的网络状态
- msvcp100d.dll
- hdu2574(一个数的不同的质数因子个数)
- POJ 3469 - Dual Core CPU(Dinic最大流)