Tuesday, June 7, 2011

TCCC2004 Online Round 01

Summary:
      Use the simplest way to implement your code, as long as it's right.


Div 1, Level 1
Div 1, Level 2
Div 1, Level 3

Tutorials:

Division One - Level Three:

Solution

Source Code:

Division One - Level One:

Solution

//Wed Jun 22 02:33:47 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 Hawaiian {
public:
    vector <string> getWords(string);
    bool letter(char c){
        c = tolower(c);
        if(c == 'a') return true;
        if(c == 'e') return true;
        if(c == 'i') return true;
        if(c == 'o') return true;
        if(c == 'u') return true;
        if(c == 'h') return true;
        if(c == 'k') return true;
        if(c == 'l') return true;
        if(c == 'm') return true;
        if(c == 'n') return true;
        if(c == 'p') return true;
        if(c == 'w') return true;
        return false;
    }
    bool check(string s){
        for(int i=0; i<s.size(); i++){
            if(letter(s[i])==false) return false;
        }
        return true;
    }
};

vector <string> Hawaiian::getWords(string sentence) {
    vector<string> ret;
    stringstream s(sentence);
    string str;
    while(s >> str){
        if(check(str)) ret.push_back(str);
    }
    return ret;
}


//Powered by [KawigiEdit] 2.0!

Source Code:

Division One - Level Two:

Solution

Source Code:

//Tue Jun  7 12:26:41 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 <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

class FlowerGarden {
public:
    vector <int> getOrdering(vector <int>, vector <int>, vector <int>);
};

vector <int> FlowerGarden::getOrdering(vector <int> height, vector <int> bloom, vector <int> wilt) {
    vector<int> ret;
    vector<pair<int, pair<int, int> > > flower;
    int N = height.size();
    for(int i=0; i<N; i++){
        flower.push_back(make_pair(height[i], make_pair(bloom[i], wilt[i])));
    }
    sort(flower.begin(), flower.end());
    bool grid[51][51];
    bool used[51];
    memset(grid, false, sizeof(grid));
    memset(used, false, sizeof(used));

    for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            if(flower[i].second.second < flower[j].second.first || flower[i].second.first > flower[j].second.second){
                grid[i][j] = true;
                grid[j][i] = true;
            }
        }
    }

    for(int i=0; i<N; i++){
        int j;
        for(j=N-1; j>=0; j--){
            if(!used[j]){
                bool flag = true;
                for(int k=0; k<j; k++){
                    if(!used[k] && !grid[k][j]) flag = false;
                }
                if(flag) break;
            }
        }
        used[j] = true;
        ret.push_back(flower[j].first);
    }
    return ret;
}

//<%:testing-code%>
//Powered by [KawigiEdit] 2.0!

No comments :