摘要: 约瑟夫环问题: 输入:1)总共人数;2)每次被杀的序号数; 输出:最后一个活着的序号python代码如下:n=int (input('please input the number of people:') )k=int (input('please input the discard number:'))a=[]for i in range(n): a.append(i+1)print 'all the serial number of people:'print ai=0j=1while len(a)>1: if j==k: d... 阅读全文
posted @ 2014-03-19 18:35 samu 阅读(175) 评论(0) 推荐(0) 编辑
摘要: 普通表达式一般由数字、变量与+-*/()运算符号组成。例如:(a+b)*3 - (a-b)/2其逆波兰表达式是:a b + 3 * a b - 2 / -本质上,普通表达式是中序表达式,逆波兰表达式是后序表达式。一)、由普通表达式生成逆波兰表达式 1、初始化1个逆波兰字符串变量outstr,以及1个符号栈;自左向右输入表达式串; 2、如果当前字符为数值或变量,则直接添加到逆波兰字符串后outstr; 3、如果当前字符为运算符号,如果是“(”,则直接压入符号栈;如果是“)”,则从栈中逐项pop运算符号,追加在outstr后;如果是其他运算符号,比较当前与栈顶的运算符优先级,如果当前低,则pop栈 阅读全文
posted @ 2014-03-18 13:12 samu 阅读(1637) 评论(0) 推荐(1) 编辑
摘要: //8-bucket sortvoid bucket_sort( int *arr, int n ){ vector > buckets; int i; for( i=0; i tmps; buckets.push_back( tmps ); } int base; int *backup = new int[n]; int *pos = new int[n]; for( i=0; i<n; backup[i]=arr[i], pos[i]=i, ++... 阅读全文
posted @ 2014-03-18 12:54 samu 阅读(133) 评论(0) 推荐(0) 编辑
摘要: 堆排序//7-heap sort methodvoid build_heap( int *arr, int start, int n ){ if( (start+1)*2 > n ) return; if( (start+1)*2 == n ) { if( arr[start] 1; offset-=2 ) { if( arr[offset/2-1] 1; ) { --offset; ... 阅读全文
posted @ 2014-03-18 12:53 samu 阅读(153) 评论(0) 推荐(0) 编辑
摘要: #includeusing namespace std;//1-insert sort methodvoid insert_sort( int *arr, int n ){ int i, k; for( i=1; i0; --k ) { if( arr[k] 0; --k ) { for( i=0; i arr[i+1] ) { int tm... 阅读全文
posted @ 2014-03-10 21:29 samu 阅读(199) 评论(0) 推荐(0) 编辑
摘要: 基类为抽象类,在不同的动态库中实现不同的执行行为,但是每个动态库要提供2个统一的方法:1) baseClass * create(); 2) void destroy( baseClass* );,调用该实际类的上下文,通过dlopen,dlsym( dl, "create"), dlsym( dl, "destroy")来获得实际对象的句柄。实际上是一种工厂/builder模型。1. 基类//base.h#include class baseClass {public: virtual void test(){}; virtual ~baseClass 阅读全文
posted @ 2014-03-06 20:59 samu 阅读(575) 评论(0) 推荐(0) 编辑
摘要: char* urlencode(const void* buf, size_t size) { _assert_(buf && size = 'A' && c = 'a' && c = '0' && c > 4; if (num = ep) break; c = *str; if (c >= '0' && c = 'a' && c = 'A' && c = ep) break; 阅读全文
posted @ 2014-03-01 15:41 samu 阅读(1924) 评论(0) 推荐(0) 编辑
摘要: http://www.infoq.com/cn/articles/designing-restful-http-apps-roth摘要:本文对RESTful HTTP的基础原理做了一个概览,探讨了开发者在设计RESTful HTTP应用时所面临的典型问题,展示了如何在实践中应用REST架构风格,描述了常用的URI命名方法,讨论了如何使用统一接口进行资源交互,何时使用PUT或POST以及如何支持非CURD操作等。Java 调用HttpClient httpClient = new HttpClient();IHttpRequest request = new GetRequest(central 阅读全文
posted @ 2014-03-01 08:29 samu 阅读(402) 评论(0) 推荐(0) 编辑
摘要: 一个数据矩阵,选定某个位置的数据元作为参考,寻找与该数据元值相同的连成一片的最大范围。如下二维数组中所示,选择arr[1][3]作为参考对象,从位置(1,3)开始寻找所有相连的值为‘1’的元素。 阅读全文
posted @ 2014-02-28 19:28 samu 阅读(611) 评论(1) 推荐(0) 编辑
摘要: // QuickSort.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"int partition( int*p, int l, int r ){ int val,ml, mr, tmp; val = p[l]; ml=l+1; mr=r; /// while(1) { for( ; ml val ) break; } for( ; mr>ml; mr-- ) { if( p[mr] val ) ... 阅读全文
posted @ 2014-02-26 14:15 samu 阅读(205) 评论(0) 推荐(0) 编辑