摘要:
solution:const int N = 8;int position[N]; // Check if a position is safebool isSafe(int queen_number, int row_position){ // Check each queen before this one for(int i=0; i<queen_number; i++) { // Get another queen's row_position int other_row_pos = ... 阅读全文
posted @ 2013-07-25 10:21
pgu2
阅读(187)
评论(0)
推荐(0)
摘要:
A double-square number is an integerXwhich can be expressed as the sum of two perfect squares. For example, 10 is a double-square because 10 = 32+ 12. Your task in this problem is, given X, determine the number of ways in which it can be written as the sum of two squares.For example, 10 can only be 阅读全文
posted @ 2013-07-25 08:20
pgu2
阅读(398)
评论(0)
推荐(0)
摘要:
Design a stack that supports push, pop, and retrieving the minimum element in constant time. Can you do this?Solution:struct Node{ int min; int val; Node( int val) {this->min = val; this->val = val;}};class stackNode : public stack{public: void push(Node& sN); void pop(); int getMin(); };v 阅读全文
posted @ 2013-07-25 07:30
pgu2
阅读(327)
评论(0)
推荐(0)
摘要:
Given a function which generates a random integer in the range 1 to 7, write a function which generates a random integer in the range 1 to 10 uniformly.solution:int rand10() { int row, col, idx; do { row = rand7(); col = rand7(); idx = col + (row-1)*7; } while (idx > 40... 阅读全文
posted @ 2013-07-25 01:39
pgu2
阅读(271)
评论(0)
推荐(0)
摘要:
For example, given that the pattern ="abc", replace"abcdeffdfegabcabc"with"XdeffdfegX". Note that multiple occurrences ofabc's that are contiguous will be replaced with only one'X'. Solution:string& repalce(string& s, string ch) // the only problems 阅读全文
posted @ 2013-07-25 01:34
pgu2
阅读(199)
评论(0)
推荐(0)
浙公网安备 33010602011771号