TopCoder SRM 416 DIV 2

Problem Check Points
250 242.30
500 331.66
1000 - -


今日は練習会に@uwitenpen さん、@hogeover30 さんがゲスト参戦。
@uwitenpen さんが45分ほどで全ての問題を解き、圧倒。黄ネーム怖い。

Problem 250 MostCommonLetters

問題

It is commonly known that in a typical English text, some letters occur more frequently than others. For example, in a long text, approximately 12.31% of the letters will be 'e'. Your friend from the linguistics department has asked you to help him find the most common letters in a given text.

The text is given to you in the String[] text. Return the letter that occurs most frequently in text. If there are multiple letters that occur most frequently, return all of them in alphabetical order. See examples for further clarification.

My code
class MostCommonLetters {
public:
  string listMostCommon(vector <string> text) {
    string result;

	int alp[26];

	for(int i=0 ; i<26 ; i++){
		alp[i] = 0;
	}

	for(int i=0 ; i<text.size() ; i++){
		for(int j=0 ; j<text[i].size() ; j++){
			if(text[i][j]!=' '){
				alp[text[i][j]-97]++;
			}
		}
	}

	string s;

	int maxa = 0;
	for(int i=0 ; i<26 ; i++){
		maxa = max(maxa, alp[i]);
	}

	for(int i=0 ; i<26 ; i++){
		if(maxa == alp[i]) s.push_back(i+97);
	}

	sort(s.begin(), s.end());
    return s;
  }
};

Problem 500 NextNumber

問題

The binary weight of a positive integer is the number of 1's in its binary representation. For example, the decimal number 1 has a binary weight of 1, and the decimal number 1717 (which is 11010110101 in binary) has a binary weight of 7.

Given a positive integer N, return the smallest integer greater than N that has the same binary weight as N.

My code
const int bitsize = sizeof(int)*8;
deque<int> v;

int countBit(int N){
	int bit = 1, count=0;

	for(int i=0 ; i<bitsize ; i++){
		if(N&bit) v.push_front(1);
		else v.push_front(0);
		bit <<=1;
	}
	return count;
}

int fromBit(void){
	int n=0, bit=1;

	for(int i=bitsize-1 ; i>=0 ; i--){
		if(v[i]==1) n+=bit;
		bit <<= 1;
	}
	return n;
}

class NextNumber {
public:
  int getNextNumber(int N) {
	  v.clear();

	countBit(N);
	next_permutation(v.begin(),v.end());
    return fromBit();
  }
};

Problem 1000 DancingCouples

問題

There are N boys and M girls in a dance school. The teachers are organizing a performance and they need exactly K boy-girl couples for their show. Unfortunately, this is not a straightforward task since some children cannot be paired with each other (due to differences in height, skill, etc.). One of the teachers is a computer science graduate, and has decided to count the number of ways to select K couples.

You are given a String[] canDance containing exactly N elements, each with exactly M characters. The j-th character of the i-th element of canDance is 'Y' if boy i can be paired with girl j, and 'N' otherwise. Return the number of distinct valid ways to select exactly K boy-girl pairs.