sizeof

How can a template function 'know' the size of the array given as template argument?

点点圈 提交于 2019-11-28 05:53:41
问题 In the C++ code below, the templated Check function gives an output that is not what I would like: it's 1 instead of 3. I suspect that K is mapped to int* , not to int[3] (is that a type?). I would like it to give me the same output than the second (non templated) function, to which I explicitly give the size of the array... Short of using macros, is there a way to write a Check function that accepts a single argument but still knows the size of the array? #include <iostream> using namespace

线性基

大城市里の小女人 提交于 2019-11-28 04:28:15
•参考资料 [1]: 算法 | 线性基学习笔记 [ 2]: 线性基学习笔记 •理解 实数线性基就是n维空间的一个基底, 求线性基就是求他的基底, 也就是矩阵的最大线性无关组 可以用高斯消元来求。 异或线性基其实就是把一个数转化成二进制 转化成二进制后,最多的二进制位数就相当于他的维数 由于只有1和0,高斯消元的结果和异或的结果相同 故用异或来做可以把时间复杂度降到log •习题 洛谷P3812 【模板】线性基 (求最大) 牛客 xor序列 (查找) 洛谷P4570 [BJWC2011]元素 (插入/查找 线性基不为0) 洛谷P4301 [CQOI2013]新Nim游戏 (插入/查找 线性基不为0) 洛谷 P3265 [JLOI2015]装备购买 (实数线性基) hdu3494 XOR (第k大) cf1100F (可以用来练习区间线性基,氮素会TLE_(:з」∠)_,正解是离线做法) 洛谷P4839 P哥的桶 (线性基+线段树) 2019牛客多校第一场A (异或和为0的所有子集长度和) •初始线性基 1 ll n; 2 ll p[65]; 3 4 ///插入 5 void Insert(ll x) 6 { 7 for(int i=60;i>=0;i--) 8 { 9 if(x&(1ll<<i)) 10 { 11 if(!p[i]) 12 { 13 p[i]=x; 14 break;

what is the size of an enum type data in C++?

断了今生、忘了曾经 提交于 2019-11-28 04:17:08
This is a C++ interview test question not homework. #include <iostream> using namespace std; enum months_t { january, february, march, april, may, june, july, august, september, october, november, december} y2k; int main () { cout << "sizeof months_t is " << sizeof(months_t) << endl; cout << "sizeof y2k is " << sizeof(y2k) << endl; enum months_t1 { january, february, march, april, may, june, july, august, september, october, november, december} y2k1; cout << "sizeof months_t1 is " << sizeof(months_t1) << endl; cout << "sizeof y2k1 is " << sizeof(y2k1) << endl; } Output: sizeof months_t is 4

C++: getting the row size of a multidimensional array passed to a function

核能气质少年 提交于 2019-11-28 03:47:35
问题 I'm trying to write a function that will print out the contents of a multidimensional array. I know the size of the columns, but not the size of the rows. EDIT: Since I didn't make this clear, the arrays passed to this function are NOT dynamically allocated. The sizes are known at compile time. I am testing it using a 3x2 array. Here is the function as it stands: void printArrays(int array1[][2], int array2[][2]) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { cout << "\narray1[

hdu5111 树链剖分,主席树

≯℡__Kan透↙ 提交于 2019-11-28 03:28:13
hdu5111 链接 hdu hdu挂了,我也不知道这份代码对不对,反正过了对拍了 思路 先考虑序列上如何解决。 1 3 2 5 4 1 2 4 5 3 这个序列变成 1 2 3 4 5 1 3 5 5 2 是对答案没有影响的(显然)。 然后查询操作 \(l,r,L,R\) 就是, 一段连续的区间 \([L,R]\) 内包含几个值在 \([l,r]\) 的数字个数. 主席树就可以做了。 \(query(rt[L-1],rt[R],[l,r]的和)\) 可以用树链剖分把树上问题转化成链上。 左边一棵树树链剖分,每一条链子都是一段连续的。 右边一棵树根据父子关系建立主席树。 然后向上跳统计贡献。 错误 一遍过样例,然而清空死了。 而且这错误找了之后我也不感觉他错。 对,我感觉是c++的错。 代码 #include <iostream> #include <map> #include <cstring> #include <algorithm> #define ls(x) (t[x].ls) #define rs(x) (t[x].rs) using namespace std; const int _=1e5+7; int read() { int x=0,f=1;char s=getchar(); for(;s>'9'||s<'0';s=getchar()) if(s=='-') f

pak文件的打包和解包

夙愿已清 提交于 2019-11-28 03:08:16
pak格式的文件 一般游戏有资源 游戏素材会打包放进去 比如游戏语音 游戏多加点语音 多加一些贴图资源 外部文件实现的 素材--->pak文件--->用的时候从文件中取出来 文件的打包 1 #include<iostream> 2 #include<fstream>//观于文件的头函数 3 using namespace std; 4 5 struct fileInfo 6 { 7 int fileSize;//文件大小 8 int fileOff;//文件在pak中的偏移 9 int fileNameSize;//文件名的长度 10 char* fileName;//文件名 11 }; 12 int main() 13 { 14 fileInfo pic[4] = { { 0, 0, 0, "背景.jpg" }, { 0, 0, 0, "人物.jpg" }, { 0, 0, 0, "箱子.jpg" }, { 0, 0, 0, "目的地.jpg" } }; 15 //初始化结构体 给结构体内存放数据 16 int listNum = 4, listSize = 8; 17 18 fstream resFile[4];//源文件 19 fstream srcFile;//打包之后的文件 20 for (int i = 0; i < 4; i++) 21 { 22 resFile[i]

[COCOS2DX-LUA]0-004.cocos2dx中的DrawNode的init的方法问题

余生颓废 提交于 2019-11-28 02:43:35
1.诱因   近期,项目接入了Bugly, 上报了一些平常测试不出来,或者很难重现的bug,这类bug非常难排查。原因有二,第一,问题无法重现,第二,修改了无法立即验证结果。有一个问题困恼了我很久,就是一直报这块的代码出错。(dispatchEvent报错) void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h) { auto director = cocos2d::Director::getInstance(); auto glview = director->getOpenGLView(); if (!glview) { glview = cocos2d::GLViewImpl::create("Android app"); glview->setFrameSize(w, h); director->setOpenGLView(glview); //cocos_android_app_init(env, thiz); cocos2d::Application::getInstance()->run(); } else { cocos2d::GL::invalidateStateCache(); cocos2d::GLProgramCache

poj3983(牛人啊)

亡梦爱人 提交于 2019-11-28 02:11:19
View Code // POJ 3983 第二届顶嵌杯决赛A题 计算4个数等于24 // 搜索 数据较小,不用剪枝就过了 // 利用类似层叠那样,每运算一次,就合并两个数,所以少一个数,每次计算的值都保存在curVal中 // 注意浮点数1/3 *3 会等于1 // 格式化输出时用到sprintf,挺不错的 #include < stdio.h > #include < string .h > #include < math.h > #define bool int int option[ 5 ]; int order[ 5 ]; float number[ 5 ]; float curVal[ 4 ][ 5 ]; // 输出时用到的临时变量 char outputStr[ 15 ]; char outputStr2[ 15 ]; char tempStr[ 15 ]; char tempStr2[ 15 ]; bool bfs( int k) { int m; if (k == 3 ) { if (fabs( 24.0 - curVal[ 3 ][ 0 ]) == 0 ) return 1 ; else return 0 ; } else { int i,j; for (i = 0 ;i < 3 - k;i ++ ) { for (j = 0 ;j < 4 ;j ++ ) {

七种qsort排序方法 [转]

末鹿安然 提交于 2019-11-28 02:11:10
<本文中排序都是采用的从小到大排序> 一、对int类型数组排序 int num[100]; Sample: int cmp ( const void *a , const void *b ) { return *(int *)a - *(int *)b; } qsort(num,100,sizeof(num[0]),cmp); 二、对char类型数组排序(同int类型) char word[100]; Sample: int cmp( const void *a , const void *b ) { return *(char *)a - *(int *)b; } qsort(word,100,sizeof(word[0]),cmp); 三、对double类型数组排序(特别要注意) double in[100]; int cmp( const void *a , const void *b ) { return *(double *)a > *(double *)b ? 1 : -1; } qsort(in,100,sizeof(in[0]),cmp); 四、对结构体一级排序 struct In { double data; int other; }s[100] //按照data的值从小到大将结构体排序,关于结构体内的排序关键数据data的类型可以很多种,参考上面的例子写 int

动态规划专题 - 解题报告

旧街凉风 提交于 2019-11-28 01:04:44
https://acm.uestc.edu.cn/contest/15/summary/?tdsourcetag=s_pctim_aiomsg dp专题要刷完!! A - oy环游世界 - 解题报告 状态压缩dp入门题 注意要开long long #include<bits/stdc++.h> using namespace std; #define ll long long ll dp[1<<18][18]; ll e[20][20]; ll x[20],y[20]; const ll INF=1e18; int main() { int n,s; scanf("%d%d",&n,&s); int tot=0; for(int i=1; i<=n; i++) { ll a,b; scanf("%lld%lld",&a,&b); if(s==i) { x[n-1]=a; y[n-1]=b; } else { x[tot]=a; y[tot]=b; tot++; } } for(int i=0; i<tot; i++) for(int j=0; j<tot; j++) { e[i][j]=abs(x[i]-x[j])+abs(y[i]-y[j]); } for(int s=0;s<(1<<tot);s++) for(int i=0;i<tot;i++) dp[s][i]=INF;