随笔分类 - algorithms
摘要: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 = ...
阅读全文
摘要:Given the sequenceS1= {a,b,c,d,...,x,y,z,aa,ab,ac.... } and given that this sequence corresponds (term for term) to the sequenceS2= {0,1,2,3,....}. Write code to convert an element ofS2to the corresponding element ofS1.solution:// ExcelSheetRowNumbers.cpp : Defines the entry point for the console ap
阅读全文
摘要:Given a singly linked list, find if there exist a loop.Solution:#include "stdafx.h"#include using namespace std;class Node{public: void addNode(Node* node); void loopStart(); void loopEnd(); void setVal(int val) {this->val = val;} int getVal() {return this->val;} Node(int val) {this-
阅读全文
摘要:ProblemOn our planet, Jamcode IX, three Great Events occurred. They happened 26000, 11000 and 6000 slarboseconds ago. In 4000 slarboseconds, the amount of time since all of those events will be multiples of 5000 slarboseconds, the largest possible amount... and the apocalypse will come.Luckily for y
阅读全文
摘要:Problemhttp://code.google.com/codejam/contest/dashboard?c=433101#s=p0TheSnapperis a clever little device that, on one side, plugs its input plug into an output socket, and, on the other side, exposes an output socket for plugging in a light or other device.When aSnapperis in the ON state and is rece
阅读全文
浙公网安备 33010602011771号