Topcoder high school SRM 1 250 pt - Level one - Speed Radar solution problem statement:
http://community.topcoder.com/stat?c=problem_statement&pm=6474&rd=10022
Topcoder high school SRM 1 250 pt - Level one - Speed Radar editorial:
http://community.topcoder.com/tc?module=Static&d1=hs&d2=match_editorials&d3=hs_srm1
Topcoder high school SRM 1 250 pt - Level one - Speed Radar solution: http://ideone.com/mnEM17
#include <iostream>
#include <vector>
#include <cmath>
#include <cstring>
using namespace std;
int cnt=0, sz;
double ans, tot=0, a;
class SpeedRadar {
public:
double averageSpeed(int minLimit, int maxLimit, vector <int> readings) {
sz=readings.size();
for(int i=0; i<sz; i++) {
if(readings[i]>maxLimit || readings[i]<minLimit) cnt++;
else tot += readings[i];
}
if(sz<cnt*10) return 0.0;
else {
a=sz-cnt;
ans=tot/a;
return ans;
}
}
};
note: it is really awful to be able to solve Topcoder problems. it is my first ever Topcoder problem that I was able to solve. i suggest you to learn C++ "class" and "method":
http://bit.ly/1o2A0zu
Launch Topcoder Arena. If you encounter problem when trying to launch Topcoder Arena then i suggest you to install Java. after installing Java activate Java web start by clicking on "javaws.exe" application in folder which might look like: C:\Program Files\Java\jre7\bin
Topcoder Arena itself automatically inputs the variables, one does not need to scanf() or cin>> it. and you just need to "return" it not printf() or cout<<.
You can also use KawigiEdit or some other editors:
http://community.topcoder.com/tc?module=Static&d1=applet&d2=plugins
Topcoder high school SRM 1 250 pt - Level one - Speed Radar solution version 2:
#include <iostream>
#include <vector>
using namespace std;
class SpeedRadar {
public: double averageSpeed(int minLimit, int maxLimit, vector <int> readings) {
double cnt=0, tot=0;
for(int i=0; i<readings.size(); i++) {
if(readings[i]<=maxLimit && readings[i]>=minLimit) tot+=readings[i];
else cnt++;
}
if(cnt*10>readings.size()) return 0.0;
else return tot/(readings.size()-cnt);
}
};