SRM229
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
Same with Div2, Lvl2.
Source Code:
Division Two - Level Three:
Solution
Source Code:
Division Two - Level Two:
Solution
Source Code:
//Sat Jun 4 02:11:16 CDT 2011
#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 Time{
public:
int h;
int m;
Time(int a, int b){
h = a;
m = b;
}
static bool cmp(const Time &A, const Time &B){
if(A.h > B. h) return true;
if(A.h == B.h && A.m > B.m) return true;
return false;
}
};
class Cafeteria {
public:
string latestTime(vector <int>, vector <int>, vector <int>);
};
string Cafeteria::latestTime(vector <int> offset, vector <int> walkingTime, vector <int> drivingTime) {
vector<Time> res;
int N = offset.size();
for(int i=0; i<N; i++){
int hr = 14;
int min = 30;
min -= drivingTime[i];
while(min < 0){
min += 60;
hr --;
}
if(min < offset[i]) {
min += 60;
hr --;
}
while(min >= offset[i]){
offset[i] += 10;
}
min = offset[i] - 10;
min -= walkingTime[i];
if(min < 0){
min += 60;
hr --;
}
res.push_back(Time(hr, min));
}
sort(res.begin(), res.end(), Time::cmp);
char ch[10];
sprintf(ch, "%02d:%02d", res[0].h>12?res[0].h-12:res[0].h, res[0].m);
return string(ch);
}
//<%:testing-code%>
//Powered by [KawigiEdit] 2.0!
Division Two - Level One:
Solution
Source Code:
//2009/08/15 17:24:36
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>
using namespace std;
class Highscore
{
public:
int getRank(vector <int> scores, int newscore, int places)
{
int eq = 0;
int gt = 0;
//sort(scores.rbegin(), scores.rend());
for(int i=0; i<scores.size(); i++)
{
if(newscore < scores[i]) gt ++;
if(newscore == scores[i]) eq ++;
}
if(eq + gt + 1 > places) return -1;
return gt + 1;
}
};
No comments :
Post a Comment