随笔分类 -  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 = ... 阅读全文
posted @ 2013-07-25 10:21 pgu2 阅读(190) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2013-07-16 22:27 pgu2 阅读(186) 评论(0) 推荐(0)
摘要: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- 阅读全文
posted @ 2013-07-08 21:20 pgu2 阅读(291) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2013-07-02 01:01 pgu2 阅读(213) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2013-06-29 02:23 pgu2 阅读(206) 评论(0) 推荐(0)