1.结构体对齐问题32位机器例子1:结果:例子2:struct A{ char c1; int i; short s; int j;}a;struct B{ int i; int j; short s; char c1;}b;结构A没有遵守字节对齐原则(为了区分,我将它叫做对齐声明原则),结构B遵守...
分类:
其他好文 时间:
2014-09-19 20:53:15
阅读次数:
212
这里的交叉链表,是Y型交叉链表。话不多说,上代码:首先定义一些用到的宏和链表节点,这里使用最简单的单向链表1 #define ARRAY_SIZE(a) sizeof((a)) / sizeof((a)[0])2 #define ABS(a) (a) > 0 ? (a) ...
分类:
其他好文 时间:
2014-09-19 11:56:55
阅读次数:
259
check here.Basically the compiler will insert unused memory into a structure so that data members are optimally aligned for better performance.
分类:
其他好文 时间:
2014-09-19 05:31:24
阅读次数:
270
题目:uva 10003 Cutting Sticks
题意:给出一根长度 l 的木棍,要截断从某些点,然后截断的花费是当前木棍的长度,求总的最小花费?
分析:典型的区间dp,其实和石子归并是一样的,花费就是石子的和,那么久不用多说了。
AC代码:
#include
#include
#include
#include
#include
#include
#in...
分类:
其他好文 时间:
2014-09-18 18:53:24
阅读次数:
201
#include
#include
#include
int main(void)
{
int i;
int *str = NULL;
str = (int*)calloc(10, sizeof(int));
if(str==NULL)
{
printf("calloc error!\n");
...
分类:
其他好文 时间:
2014-09-18 14:55:54
阅读次数:
257
#include
#include
#include
#include
int main(void)
{
int *str1 = NULL;
int *str2 = NULL;
str1 = (int*)malloc(2*1024*sizeof(char));
if(str1==NULL)
{
printf("m...
分类:
其他好文 时间:
2014-09-18 14:55:44
阅读次数:
224
#include
#include
#include
#include
int main(void)
{
int *str1 = NULL;
int *str2 = NULL;
str1 = (int*)malloc(2*1024*sizeof(char));
str2 = (int*)malloc(6*1024*sizeof(char))...
分类:
其他好文 时间:
2014-09-18 14:55:34
阅读次数:
148
在C#中,sizeof用来计算类型的大小,单位是字节。有这样的一个类: public class MyUglyClass { public char myChar1; public int myInt; public char myChar2; } 在客户端,试图使用sizeof计算该类型的大小。 ...
分类:
其他好文 时间:
2014-09-16 23:31:21
阅读次数:
272
1 NSLog(@"char-%zu",sizeof(char)); 2 3 NSLog(@"int-%zu\n,float-%zu\n,double-%zu\n",sizeof(int),sizeof(float),sizeof(double)); 4 5 NSLog...
分类:
其他好文 时间:
2014-09-16 20:34:01
阅读次数:
182
第一种思路是:
dp(i):到位置i所需要的最少步数
dp(i)一定是递增的,所以从j=A[i]开始(从最远的位置开始),更新数组直到dp(j+i)
如果去掉,会TLE
int jump(int A[], int n) {
int* dp = new int[n];//dp[i]到i所需的最小步数
memset(dp, 0x3f, sizeof(int)...
分类:
其他好文 时间:
2014-09-16 01:38:29
阅读次数:
241