03 2014 档案

摘要:宏M度量操作op所花时间,单位纳秒。#include "stdafx.h"#include "time.h"#include using namespace std;#define trails 5#define n 10000#define M(op) \ cout << #op; \ cout << "\t"; \ timesum = 0; \ for(int tr=0;tr<trails;++tr) \ { \ start = clock(); \ for(int i=1;i<=n;++i) 阅读全文
posted @ 2014-03-19 14:15 lqj_piaohong 阅读(135) 评论(0) 推荐(0) 编辑
摘要:此源码参考编程珠玑附录C时空开销源码例一。改动在于用template代替Macro。Measure 方法:连续new类型T十二次,查看系统为每一个对象分配的实际大小。结论:在64位的机器上,如果类型大小小于等于4字节,则分配64字节的空间。如果类型大小大于4字节,则最低分配72字节,以后每多出8字节,就分配多8字节。#include "stdafx.h"#include using namespace std;template void MEASURE() { cout struct structii { char c[i]; };int main... 阅读全文
posted @ 2014-03-19 13:01 lqj_piaohong 阅读(194) 评论(0) 推荐(0) 编辑
摘要:计算x的n次方。要求时间控制在log2n内。using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication3{ class Program { static void Main(string[] args) { const int n = 10; for (int i = 1; i <= 5; ++i) { ... 阅读全文
posted @ 2014-03-17 12:26 lqj_piaohong 阅读(214) 评论(0) 推荐(0) 编辑
摘要:找出给定整数在一个有序数组中的区间。比如,对于数组“1,3,5,7,10”,给定“2”,找到它在“3”和“5”区间内。要求用二分搜索。时间控制在log2n内。using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication3{ class Program { static void Main(string[] args) { int[] a = new int[] { 1, 3,... 阅读全文
posted @ 2014-03-17 12:22 lqj_piaohong 阅读(164) 评论(0) 推荐(0) 编辑
摘要:在一个已经排序的非降序整形数组中,找到被搜索整数首次出现的位置,如果该整数出现多次的话。要求在log2n次比交内完成。using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication3{ class Program { static void Main(string[] args) { int[] a = new int[] { 1, 1, 1, 1, 2, 2, 2, 2, 2... 阅读全文
posted @ 2014-03-12 13:50 lqj_piaohong 阅读(163) 评论(0) 推荐(0) 编辑