/** * \brief Executes a two sample T test for the "Planning" example on the exercise sheet. */ void StatisticalTesting::planning() { const double confidenceLevel = 0.95; const double myPlanner[] = { 90, 104, 142, 143, 121, 190, 92, 93, 166, 110, 191, 122, 129, 176, 110, 45, 78, 166, 173, 115, 197, 63, 156, 124, 98 }; const double baselinePlanner[] = { 56, 92, 145, 117, 121, 91, 147, 174, 122, 111, 143, 142, 189, 129, 92, 112, 122, 120, 125, 200, 137, 147, 89, 101, 108 }; TestCase test; Hypothesis a("My planner produces longer paths than the baseline.", GREATER); Hypothesis b("My planner produces shorter paths than the baseline.", LESS); Hypothesis c("My plans are at most as long as the baseline plans.", AT_MOST); Hypothesis d("My plans are at least as long as the baseline plans.", AT_LEAST); Hypothesis e("My plans are as long as the baseline paths.", EQUAL); Hypothesis f("My plans have different lengths than the baseline paths.", DIFFERENT); test.setHypothesis(f); test.setNullHypothesis(e); twoSampleTTest(arrayToVector(myPlanner), arrayToVector(baselinePlanner), confidenceLevel, test); }
/** * \brief Executes a Z test for the "German students test" example on the slides. */ void StatisticalTesting::germanStudentsTest() { const double testResults[] = { 97, 77, 100, 99, 100, 75, 76, 95, 96, 90, 96, 70, 71, 98, 97, 97, 67, 100, 97, 100, 92, 130, 100, 100, 95, 100, 92, 94, 89, 89, 82, 65, 100, 98, 85, 100, 93, 87, 100, 97, 73, 100, 93, 110, 95, 110, 79, 92, 96, 100, 87, 92, 110, 110, 100 }; const double distributionMean = 100; const double distributionStandardDeviation = 12; const double confidenceLevel = 0.95; TestCase test; Hypothesis a("Bonn students are better than other students", GREATER); Hypothesis b("Bonn students are worse than other students", LESS); Hypothesis c("Bonn students are at least as good as other students", AT_LEAST); Hypothesis d("Bonn students are at most as good as other students", AT_MOST); Hypothesis e("Bonn students are as good as other students", EQUAL); Hypothesis f("Bonn students perform differently from other students", DIFFERENT); /* TODO: Select a hypothesis and a null hypothesis from the above choices a-f and * call test.setHypothesis(...) and test.setNullHypothesis(...) with the chosen * variable. */ test.setHypothesis(b); test.setNullHypothesis(c); oneSampleZTest(arrayToVector(testResults), distributionMean, distributionStandardDeviation, confidenceLevel, test); }
int main() { pair<int, int> a[] = {pair<int,int>(0,1), pair<int,int>(1,2), pair<int,int>(1,3)}; vector<pair<int, int> > b = arrayToVector(a); vector<int> r = findMinHeightTrees(4, b); printVector(r); return 0; }
int trap(int A[], int n) { vector<int> height(n, 0), presum(n, 0), right_pair_pos(n, 0); arrayToVector(A, n, height); calcRightPairPos(height, right_pair_pos); calcHeightPresum(height, presum); return getWaterTrapped(height, presum, right_pair_pos); }
int main() { unordered_set<string> d; string a[] = {"a", "abc", "b", "cd"}; vector<string> b = arrayToVector(a); for(int i = 0;i < b.size();i++) { d.insert(b[i]); } cout<<wordBreak("abcd", d)<<endl; return 0; }
int main() { char a[][4] = {{'A','B','C','E'}, {'S','F','C','S'}, {'A','D','E','E'}}; vector<vector<char> > board; for(int i = 0;i < 3;i++) { vector<char> t = arrayToVector(a[i]); board.push_back(t); } cout<<exist(board, "ABCB")<<endl; return 0; }
int main() { char a[][4] = {{'X','X','X','X'}, {'X','O','O','X'}, {'X','X','O','X'}, {'X','O','X','X'}}; vector<vector<char> > board; for(int i = 0;i < 4;i++) { board.push_back(arrayToVector(a[i])); } solve(board); print(board); return 0; }
/** * \brief Executes a one sample T test for the "Cars" example on the slides. */ void StatisticalTesting::cars() { const double prices[] = {11492.70, 23848.70, 15096.80, 27376.10, 15576.50}; const double distributionMean = 12000; const double confidenceLevel = 0.95; TestCase test; Hypothesis a("The cars are more expensive than in the rest of the city", GREATER); Hypothesis b("The cars are cheaper than in the rest of the city", LESS); Hypothesis c("The cars are at least as expensive as in the rest of the city", AT_LEAST); Hypothesis d("The cars are at most as expensive as in the rest of the city", AT_MOST); Hypothesis e("The cars are as expensive as in the rest of the city", EQUAL); Hypothesis f("The prices of the cars are different from the rest of the city", DIFFERENT); /* TODO: Select a hypothesis and a null hypothesis from the above choices a-f and * call test.setHypothesis(...) and test.setNullHypothesis(...) with the chosen * variable. */ test.setHypothesis(a); test.setNullHypothesis(d); oneSampleTTest(arrayToVector(prices), distributionMean, confidenceLevel, test); }
int main() { int a[] = {4,3,2,6}; vector<int> A = arrayToVector(a); cout<<maxRotateFunction(A)<<endl; return 0; }
int main() { int a[] = {2,1,1,2}; vector<int> b = arrayToVector(a); cout<<isSelfCrossing(b)<<endl; return 0; }
int main() { int a[] = {1,4,2}; vector<int> b = arrayToVector(a); cout<<maxProfit(b)<<endl; return 0; }
int main() { int a[] = {4,5,6,7,0,1,2}; vector<int> b = arrayToVector(a); cout<<findMin(b)<<endl; return 0; }
int main() { int a[] = {1,2,0}; vector<int> b = arrayToVector(a); cout<<firstMissingPositive(b)<<endl; return 0; }
int main() { int a[] = {5,2,4,1,3,6,0}; vector<int> b = arrayToVector(a, 7); cout<<findKthLargest(b, 4)<<endl; return 0; }