摘要: 位域 有些信息在存储时,并不需要占用一个完整的字节, 而只需占几个或一个二进制位。例如在存放一个开关量时,只有0和1 两种状态, 用一位二进位即可。为了节省存储空间,并使处理简便,C语言又提供了一种数据结构,称为“位域”或“位段”。所谓“位域”是把一个字节中的二进位划分为几 个不同的区域, 并说明每个区域的位数。每个域有一个域名,允许在程序中按域名进行操作。 这样就可以把几个不同的对象用一个字节的二进制位域来表示。 一、位域的定义和位域变量的说明位域定义与结构定义相仿,其形式为: struct 位域结构名 { 位域列表 }; 其中位域列表的形式为: 类型说明符 位域名:位域长度 ... 阅读全文
posted @ 2012-05-09 14:34 徐露 阅读(138) 评论(0) 推荐(0) 编辑
摘要: (1)用整型数据相除等特点,整除的余数来判断#include <iostream>#include <windows.h>using namespace std;int Count(BYTE i){ int num=0; while (i) { if (1==i%2) { ++num; } i/=2; } return num;}int main(){ BYTE i=12; cout<<Count(i)<<endl; return 0;}(2)通过与0x01做与运算#i... 阅读全文
posted @ 2012-05-09 14:21 徐露 阅读(138) 评论(0) 推荐(0) 编辑
摘要: 回溯法:#include <stdio.h>#include <stdlib.h>#include <time.h>int isShudu(int shudu[9][9], int i, int j){ int k; int temp=shudu[i][j]; int flag=1; for(k=0; k<9; ++k) { if (k!=i && shudu[k][j]==temp) { flag=0; } } for(k=0; k<9; ++k) { if (k!=j && shudu[i][k]==temp) 阅读全文
posted @ 2012-05-09 11:21 徐露 阅读(468) 评论(0) 推荐(0) 编辑
摘要: (1)在9×9的数组中心随机生成一个3×3的中心数组。(2)已3×3中心数组为对称进行循环置换。#include <stdio.h>#include <stdlib.h>#include <time.h>int main(){ int matrix[3][3]; int i; int j; int shudu[9][9]={0}; for (i=0; i<3; ++i) { for (j=0; j<3; ++j) { matrix[i][j]=i*3+j+1; } } /*随机初始化... 阅读全文
posted @ 2012-05-09 10:41 徐露 阅读(1094) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> #include <time.h> #include <cassert> using namespace std; const int totalFloorNum = 10; const int totalStopNum = 4; int nPerson[totalFloorNum + 1]; int minFloors[totalFloorNum + 1][totalStopNum + 1]; int targetFloors[totalFloorNum + 1][totalStopNum + 1]; //stopN 阅读全文
posted @ 2012-05-08 20:39 徐露 阅读(484) 评论(0) 推荐(0) 编辑