memset

Why do ZeroMemory, etc. exist when there are memset, etc. already?

我们两清 提交于 2019-11-27 03:05:31
问题 Why does ZeroMemory() , and similar calls exist in the Windows API when there are memset and related calls in the C standard library already? Which ones should I call? I can guess the answer is "depends". On what? 回答1: In C and C++, ZeroMemory() and memset() are the exact same thing. /* In winnt.h */ #define RtlZeroMemory(Destination,Length) memset((Destination),0,(Length)) /* In winbase.h */ #define ZeroMemory RtlZeroMemory Why use ZeroMemory() then? To make it obvious. But I prefer memset()

Why does memset take an int instead of a char?

风流意气都作罢 提交于 2019-11-27 01:23:45
Why does memset take an int as the second argument instead of a char , whereas wmemset takes a wchar_t instead of something like long or long long ? Jerry Coffin memset predates (by quite a bit) the addition of function prototypes to C. Without a prototype, you can't pass a char to a function -- when/if you try, it'll be promoted to int when you pass it, and what the function receives is an int . It's also worth noting that in C, (but not in C++) a character literal like 'a' does not have type char -- it has type int , so what you pass will usually start out as an int anyway. Essentially the

Eclipse giving me Invalid arguments ' Candidates are: void * memset(void *, int, ?) ' though I know the args are good

依然范特西╮ 提交于 2019-11-27 01:11:31
问题 I am getting an invalid arguments error in eclipse, though I am confident my arguments are good. The suggested arguments contains a '?' which I think may indicate the problem, though I do not know how to fix it. I have done my best to copy the example I saw here: http://www.cplusplus.com/reference/clibrary/cstring/memset/ In order to be certain that I am getting the args right. #include <stdio.h> #include <string.h> void foo() { char str[] = "why oh why does my IDE give me errors when I know

DFS序-树链剖序-欧拉序

ぐ巨炮叔叔 提交于 2019-11-27 01:05:37
,二叉树是一颗线段树,树状数组,树上的每个维护节点负责维护一个区间信息,节点之间又包含和属于的关系。例如线段树: DFS序: 我们通过对每个节点设置两个量,in和out。从根节点开始DFS搜索,in为第一次搜索到时的时间戳,out为退出出栈时的时间戳。 可以得到,例如我们要查询以b为根节点我们只需要查询区间[2,5];要查询以c为根节点子树的信息,我们可以查询区间[6,7];查询a需要查询区间[1,8]。在程序中,当要查询修改时,我们可以用线段树去维护,因为这些序列的性质和线段树太像了。我们要注意线段树的父区间等于两个子区间的和,而这个序列的区间等于父节点以及所有后代节点,例如b树,区间[2,5]包括了b点和d,e,f点,所以在线段树的区间中我们要保存的是原图中的子树。但是对于一些不规则的区间,例如查询[5,7]或是[2,4],虽然身在线段树上我们能找到它,但是在原图中没有什么实际意义或者我不易知道这个区间的意义。所以查找时,一般是通过点找区间,而不是直接查找区间。 [1,1],[2,2],[3,3]...[x,x]代表了原图中节点x的值,in[x],out[x]对应了以x为根节点子树的信息 来两道例题: 卡卡屋前有一株苹果树,每年秋天,树上长了许多苹果。卡卡很喜欢苹果。树上有 N 个节点,卡卡给他们编号1到 N ,根的编号永远是1.每个节点上最多结一个苹果

DP&图论 DAY 6 下午 考试

懵懂的女人 提交于 2019-11-27 00:45:17
DP&图论 DAY 6 下午 考试 3 5 10 3 1 3 437 1 2 282 1 5 328 1 2 519 1 2 990 2 3 837 2 4 267 2 3 502 3 5 613 4 5 132 1 3 4 10 13 4 1 6 484 1 3 342 2 3 695 2 3 791 2 8 974 3 9 526 4 9 584 4 7 550 5 9 914 6 7 444 6 8 779 6 10 350 8 8 394 9 10 3 7 10 9 4 1 2 330 1 3 374 1 6 194 2 4 395 2 5 970 2 10 117 3 8 209 4 9 253 5 7 864 8 5 10 6 样例输入 437 526 641 样例输出 题解 >50 pt dij 跑暴力 (Floyd太慢了QWQ O(n^3)) 枚举每个点作为起点,dijkstra,跑暴力 O( (n+m)logn ),寻找全局最短路 #include<iostream> #include<cstdio> #include<string> #include<cstring> #include<cmath> #include<cstdlib> #include<algorithm> #include<queue> using namespace std; inline

最短路径

痴心易碎 提交于 2019-11-27 00:27:50
没有用的话qaq : Ummmm…图论的大部分知识本来早就有学过,只是一直没有写成博文来梳理,但既然上了qbxt DP图论就写一篇来总结下, 主要是来听DP的,但…由于太菜的原因,DP听得天花乱坠QWQ 图中的最短路算法分为单源最短路算法(dijkstra,Bellman-food,spfa)和多源最短路算法(floyd),单源最短路算法是求图上一点到其他任意一点的最短路径,多源最短路算法是求图上任意两点之间的最短路。 一,多源最短路算法 Floyd弗洛伊德算法,运用了动态规划的思想,用邻接矩阵存储,期初将从任何一点到其他所有点的最短路都置成正无穷,然后输入时修改有的权值,其主要思想是动态规划,在最外围枚举点,看看有没有一个点可以更新两点之间的最短路。 代码简单易懂 memset(dis,0x3f,sizeof(dis)); for(int k=1;k<=n;k++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]); 时间复杂度为O(n^3 ),空间复杂度为O(n^2),时间和空间均不是很优,一般较少采用,一般在求n范围较小的多源最短路题中才有出现。 可以适用于有负权边的情况,可以判断图的连通性,可以传递闭包 二,多源最短路算法 1,Dijkstra a

Why use bzero over memset?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 22:30:11
问题 In a Systems Programming class I took this previous semester, we had to implement a basic client/server in C. When initializing the structs, like sock_addr_in , or char buffers (that we used to send data back and forth between client and server) the professor instructed us to only use bzero and not memset to initialize them. He never explained why, and I'm curious if there is a valid reason for this? I see here: http://fdiv.net/2009/01/14/memset-vs-bzero-ultimate-showdown that bzero is more

hello大家好,我是拓扑排序

你。 提交于 2019-11-26 22:22:48
发几个以前写的拓扑排序,回顾一下。 拓扑排序,一般不会单独考,主要要求还是掌握好这个概念,有个感性的认识,以及能快速的写出求拓扑排序的程序,进而继续接下来对图的处理,或是比如dp之类的算法,又或者是判断有无环之类。求拓扑序主要就是运用队列,push入度为0的点,删掉它们出去的边,重复这个操作。像要是求字典序最小,就可以用优先队列。 TOJ 3993 求字典序最小的拓扑排序 1 #include<cstdio> 2 #include<queue> 3 #include<cstring> 4 using namespace std; 5 6 int ans[110], in[110]; 7 bool e[110][110]; 8 int n, m; 9 int main() 10 { 11 int T, x, y; 12 scanf("%d", &T); 13 while(T--) 14 { 15 memset(e, 0, sizeof(e)); 16 memset(in, 0, sizeof(in)); 17 scanf("%d %d", &n, &m); 18 for (int i = 0; i < m; i++){ 19 scanf("%d %d", &x, &y); 20 if (!e[x][y]){ 21 e[x][y] = 1; 22 in[y]++; 23 } 24 }

poj 1511-- Invitation Cards (dijkstra+优先队列)

陌路散爱 提交于 2019-11-26 20:44:58
刚开始想复杂了,一直做不出来,,,其实就是 两遍dijkstra+优先队列 (其实就是板子题,只要能有个好的板子, 剩下的都不是事 ),做出来感觉好简单...... 题意:有n个车站和n个志愿者,早上每个志愿者去一个站点,晚上回去,问最少的开销是多少。 是一个有向图 先一遍dijkstra求出早上的开销,在把车站倒过来及1到4变成4到1,然后再一遍dijkstra求出晚上的开销。 不要用memset去初始化为INF, 本题如果用memset会wa,记得开long long; 1 #include<cstdio> 2 #include<cstring> 3 #include<queue> 4 using namespace std; 5 6 const int INF = 1e9+10; 7 const int N = 1000010; 8 const int M = 1000010; 9 int tot; 10 11 struct Edge //dijkstra+优先队列板子 12 { 13 int v, cost, next; 14 }edge[M]; 15 16 struct qnode 17 { 18 int v,c; 19 bool operator < (const qnode &x) const { 20 return c > x. c; 21 } 22 }; 23

UVA11374 Airport Express

橙三吉。 提交于 2019-11-26 20:22:18
题目链接 在刘汝佳的那本书上看到了这道题,思路:先预处理出起点到所有点以及终点到所有点的最短路径,然后就是枚举所有的商务边,因为只能有一条商务边,所以最优的路径肯定要么就是起点->商务边起点->商务边终点->终点,要么就是直接起点->终点。时间复杂度为预处理的mlogn加上k次枚举。最后还要递归输出路径。 代码如下,UVA的输出有毒,一直过不了,但肯定是对的。 //不知道是怎么回事,可能是输出格式的问题。 #include<bits/stdc++.h> using namespace std; const int maxn=1e6+7; struct node{ int nxt,to,val; }edge[maxn*3]; int head[maxn],cnt; int dis[maxn],dis1[maxn]; int ans; inline void add(int x,int y,int v){ edge[++cnt].nxt=head[x]; edge[cnt].to=y; edge[cnt].val=v; head[x]=cnt; } int n,s,e,m,k,x,y,z; int o,p,t; bool vis[maxn],vis1[maxn]; int pre1[maxn],pre2[maxn]; int ljb; priority_queue< pair<int