TopCoder SRM 487 DIV 2

Problem Check Points
250 ?
500 × -
900 - -

500は先頭と最後しか考慮に入れておらず死亡。
そういえばTopcoder側のコンパイルで、 vector>と書くと、 >> の部分が演算子として構文解析されてちょっと困ったりしました。


Login - TopCoder Wiki

Problem 250 BunnyExamAfter

問題

Bunnies like programming but they don't like programming exams.

Three bunnies, Black, Gray and White, had completed their final exam. While they were discussing the problems, the Professor came and said, "Black, you got zero points! To improve your knowledge, write a program which calculates the maximum possible sum of points that Gray and White could have gotten."

There were N problems in the exam. All bunnies were presented with the same problems. For each problem, they had to write an uppercase letter ('A' - 'Z') as its answer. Only one letter is considered to be a correct answer for a problem, and all other 25 letters are considered to be incorrect answers. Each correct answer was worth 1 point, so the number of points received by a bunny was equal to the number of problems she answered correctly.

You are given three Strings black, gray and white representing the answers Black, Gray and White wrote, respectively. Each contains exacty N characters and the i-th character represents the answer for the i-th problem of the respective bunny. Return the maximum possible sum of points that Gray and White could have gotten for the exam, considering all possible answers that leave Black with 0 points.

My code
class BunnyExamAfter {
public:
  int getMaximum(string black, string gray, string white) {
	  int size = black.size();
	  int ans=0;

	  for(int i=0 ; i<size; i++){
		  if(black[i]!=gray[i]) ans++;
		  if(black[i]!=white[i]) ans++;
		  if(black[i]!=gray[i] && black[i]!=white[i] && gray[i]!=white[i]) ans--;

	  }
	  return ans;
  }
};

Problem 500 BunnyComputer

問題

Bunnies like programming and they often practice for contests.

There is a special computer named B-Computer, which all bunnies are eager to use. All bunnies want to solve a difficult problem using B-Computer. Because they type very fast, each of them wants to solve the problem according to the following process that consists of 3 stages (no delay is allowed between subsequent stages):

  1. Use B-Computer for exactly one time unit.
  2. Think and calculate on paper for exactly k time units, not using B-Computer.
  3. Use B-Computer for exactly one time unit again to complete.

B-Computer cannot be used by more than one bunny at the same time, but when a bunny is thinking and calculating on paper, another bunny may use B-Computer.

A day is divided into a number of equal time units, and each time unit has an associated positive integer value called preference. You are given a int[] preference, which contains the preference values for a day. The number of elements in preference is the number of time units in the day, and the i-th element of preference is the preference of the i-th time unit.

Bunnies want to design a B-Computer schedule for a single day so that the sum of preferences of time units in which one of them uses B-Computer is maximized. The schedule must be such that each bunny uses B-computer exactly as described above and both time units at which the same bunny uses B-computer are in the same day. Return the maximum possible sum of preferences. You can assume that there are infinitely many bunnies.

My code
int size;

bool inRange(int x){ return 0<=x && x < size; }

class BunnyComputer {
public:
  int getMaximum(vector <int> preference, int k) {

	size = preference.size();

	if(k>= size) return 0;

	if(size%(2*(k+1))==0){
		int sum = 0;
		for(int i=0 ; i<size ; i++){
			sum += preference[i];
		}
		return sum;
	}

	vector< vector<int> > v;

	for(int i=0 ; i<(k+1) ; i++){
		v.push_back(vector<int>());
	}

	for(int i=0 ; i<size; i++){
		v[i%(k+1)].push_back(preference[i]);
	}

	int ans=0;
	for(int i=0 ; i<v.size() ; i++){
		for(int j=0 ; j<v[i].size() ; j++){
			ans += v[i][j];
		}
		if(v[i].size()%2!=0){
			int minnum = 9999999;
			for(int k=0 ; k<v[i].size() ; k+=2){
				minnum = min(minnum, v[i][k]);
			}
			ans -= minnum;
		}
	}

    return ans;
  }
};

Problem 900 BunnyConverter

問題

Bunnies like programming and they sometimes make useless devices.

One group of bunnies made a device called Converter. Converter has two fixed integers, n and z, and works as follows:
It receives a card on which an integer x is written. This card will not be returned.
It selects an integer y between 1 and n, inclusive, such that x + y^2 + z^3 is a multiple of n. If there is more than one such y, Converter allows the user to choose exactly one of them. If there is no such y, Converter will break and will never be usable again.
It returns a card on which the integer y is written.
Initially you have a card on which an integer start is written. Your goal is to get a card on which an integer goal is written. Return the minimum number of times you must use Converter in order to achieve the goal. If it is impossible to get such a card, return -1 instead.