SRM146
Div 1, Level 1
Div 1, Level 2
Div 1, Level 3
Div 2, Level 1
Div 2, Level 2
Div 2, Level 3
Tutorials:
Division One - Level Three:
Solution
Source Code:
Division One - Level Two:
Solution
Source Code:
Division One - Level One:
Solution
Source Code:
//2009/07/26 14:00:24
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class RectangularGrid
{
public:
long long countRectangles(int width, int height)
{
long long score = 0;
for (int i=0; i<height; i++)
{
for(int j=0; j<width; j++)
{
if(i == j) continue;
score += (height - i) * (width - j);
}
}
return score;
}
};
Division Two - Level Three:
Solution
Source Code:
//2009/07/26 14:49:01
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
class BridgeCrossing {
public:
int minTime(vector <int>);
int crossriver(vector<int> v, int T);
};
int BridgeCrossing::minTime(vector <int> times) {
sort(times.begin(), times.end());
return crossriver(times, times.size());
}
int BridgeCrossing::crossriver(vector<int> v, int T){
if (T == 1)
{
return v[0];
}
if (T == 2)
{
return v[1];
}
if (T == 3)
{
return v[0] + v[1] + v[2];
}
if (v[0] + 3 * v[1] + v[T - 1] > 2 * v[0] + v[1] + v[T - 2] + v[T - 1])
{
return 2 * v[0] + v[T - 2] + v[T - 1] + crossriver(v, T - 2);
}
else
{
return v[0] + 2 * v[1] + v[T - 1] + crossriver(v, T - 2);
}
}
//<%:testing-code%>
//Powered by [KawigiEdit] 2.0!
Division Two - Level Two:
Solution
Source Code:
//2009/07/26 14:00:24
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class RectangularGrid
{
public:
long long countRectangles(int width, int height)
{
long long score = 0;
for (int i=0; i<height; i++)
{
for(int j=0; j<width; j++)
{
if(i == j) continue;
score += (height - i) * (width - j);
}
}
return score;
}
};
Division Two - Level One:
Solution
Source Code:
//2009/07/25 20:06:30
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
class YahtzeeScore
{
public:
int maxPoints(vector <int> toss)
{
sort(toss.begin(), toss.end());
int Max = 0;
int count = 1;
int pre = toss[toss.size() -1];
for(int i=toss.size() - 2; i>=0; i--)
{
if(toss[i] != pre)
{
Max = max(Max, count*pre);
count = 1;
pre = toss[i];
}
else
{
count ++;
}
}
Max = max(Max, pre*count);
return Max;
}
};
No comments :
Post a Comment