memset

神奇脑洞题解——HDU1853 Cyclic Tour

流过昼夜 提交于 2019-12-03 08:21:52
对于二分图的最大匹配和对于带权二分图的最优匹配,B站上 CSU ACM—ICPC 的大佬们讲的已经很清楚了。 有需求的同学们可以去B站上学习一下。 悄悄说一声,讲课的陈佳妮小姐姐也曾经是位OIer,曾在CTSC2016上夺得银牌(因为在HN,好像没能去成NOI),讲解的方式也令OIers十分舒适。 题目大意:给一张有向图,要求选择任意多个环(可重复,非自环,环可以任选,不用相连),使得每个点都被访问过,而且经过的边权之和最小,求最小值 。 乍一看和二分图没有关系,但是仔细想一下,如果给图中每个点拆成两个(一个连接这个点的入点,一个连出点),那么因为要走环,那么最优情况肯定是每个环中有一个点会被访问两次,其他点都是一次,那这不就是赤果果的在拆点图上求最优匹配吗? 假设我们有一张图:1——>2——>3——>1,设拆出来的点i,用来连接入点的是i,连接出点的是i+n(此处n=4),那么我们拆点图长这样:5——>2,6——>3, 7——>1,这样就实际上是对拆出来的六个点进行了一次完全匹配。 那么,我们只要先判断拆点图能不能形成完美匹配,然后再跑一边KM就可以了(KM算法要求二分图存在完美匹配,否则会陷入死循环)。 放代码吧: #include<iostream> #include<cstdio> #include<vector> #include<algorithm> #include

is memset() more efficient than for loop in C?

强颜欢笑 提交于 2019-12-03 08:14:41
问题 is memset more efficient than for loop. so if i have char x[500]; memset(x,0,sizeof(x)); or char x[500]; for(int i = 0 ; i < 500 ; i ++) x[i] = 0; which one is more efficient and why? is there any special instruction in hardware to do block level initialization. 回答1: Most certainly, memset will be much faster than that loop. Note how you treat one character at a time, but those functions are so optimized that set several bytes at a time, even using, when available, MMX and SSE instructions. I

模板

亡梦爱人 提交于 2019-12-03 07:17:27
负环 1 #include<bits/stdc++.h> 2 #define I inline 3 using namespace std; 4 using namespace std; 5 const int N=2010; 6 const int M=3010; 7 I int read() 8 { 9 int x=0,f=1;char ch=getchar(); 10 while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} 11 while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} 12 return x*f; 13 } 14 15 struct node 16 { 17 int nxt,to,dis; 18 }g[M<<1]; 19 int head[N],tot; 20 int T,n,m; 21 int dist[N],cnt[N]; 22 bool vis[N]; 23 24 I void addedge(int u,int v,int dis) 25 { 26 g[++tot].nxt=head[u]; 27 g[tot].to=v; 28 g[tot].dis=dis; 29 head[u]=tot; 30 } 31 32 I bool spfa() 33 {

memset function in c language

孤人 提交于 2019-12-03 03:54:57
问题 I am studying the memset function now, but all the examples are regarding to char array as following: char a[100]; memset(a, 0, 100); it will set every element in this char array to 0. I wondered if memset can apply to int array or float array? 回答1: Yes, it can apply to any memory buffer, but you must input the correct memory buffer size ... memset treats any memory buffer as a series of bytes, so whether it's char , int , float , double , etc, doesn't really matter. Keep in mind though that

Default-inserting into a vector isn&#039;t default initialization?

匿名 (未验证) 提交于 2019-12-03 03:10:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: One of the std::vector constructors is stipulated as, emphasis mine: explicit vector(size_type n, const Allocator& = Allocator()); Effects: Constructs a vector with n default-inserted elements using the specified allocator. Requires: T shall be DefaultInsertable into *this. Complexity: Linear in n . Is default-insertion in any way related to default initialization? On this code: std::vector<char> v(66000); gcc 5.2 optimized produces: 400d18: bf d0 01 01 00 mov $0x101d0,%edi 400d1d: 48 83 c5 01 add $0x1,%rbp 400d21: e8 1a fd ff ff callq

How to fast initialize with 1 really big array

匿名 (未验证) 提交于 2019-12-03 03:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have enermous array: int* arr = new int[BIGNUMBER]; How to fullfil it with 1 number really fast. Normally I would do for(int i = 0; i < BIGNUMBER; i++) arr[i] = 1 but I think it would take long. Can I use memcpy or similar? 回答1: You could try using the standard function std::uninitialized_fill_n : #include <memory> // ... std::uninitialized_fill_n(arr, BIGNUMBER, 1); In any case, when it comes to performance, the rule is to always make measurements to back up your assumptions - especially if you are going to abandon a clear, simple design

[TJOI2017] DNA - 后缀数组,稀疏表

点点圈 提交于 2019-12-03 02:11:58
[TJOI2017] DNA Description 求模式串与主串的匹配次数,容错不超过三个字符。 Solution 枚举每个开始位置,进行暴力匹配,直到失配次数用光或者匹配成功。考虑到容错量很小,所以每个位置开始的匹配过程中大部分与普通匹配是同样操作,而我们需要的其实就是 LCP 长度,所以预处理出后缀数组和高度数组,建 ST 表支持 RMQ 询问,来加速暴力匹配的过程。时间复杂度 \(O(n \log n)\) #include <bits/stdc++.h> using namespace std; int n,k,l0,m=256,sa[250005],y[250005],u[250005],v[250005],o[250005],r[250005],h[250005],T; char str[250005]; int lg2[250005]; struct clsst { int a[250005][21]; void build(int *src,int n) { for(int i=1;i<=n;i++) a[i][0]=src[i]; for(int i=1;i<=20;i++) for(int j=1;j<=n-(1<<i)+1;j++) a[j][i]=min(a[j][i-1],a[j+(1<<(i-1))][i-1]); } int query(int l

What is the equivalent of memset in C#?

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I need to fill a byte[] with a single non-zero value. How can I do this in C# without looping through each byte in the array? Update: The comments seem to have split this into two questions - Is there a Framework method to fill a byte[] that might be akin to memset What is the most efficient way to do it when we are dealing with a very large array? I totally agree that using a simple loop works just fine, as Eric and others have pointed out. The point of the question was to see if I could learn something new about C# :) I think Juliet's

SCTP Multihoming

匿名 (未验证) 提交于 2019-12-03 02:04:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've been developing this simple client - server application with C where the client is just sending random data to the server and the server just listens to what the client sends. The protocol I'm using is SCTP and I'm interested on how to implement the multihoming feature to it. I've been searching through the internet about SCTP and multihoming and haven't been able to find any examples about how to instruct SCTP to use multiple addresses for communication. I've only managed to find what commands one should use when trying to setup SCTP

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

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 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 #include void foo() { char str[] = "why oh why does my IDE give me errors when I know my args are good?"; memset(str, '-', 4); puts(str); } Eclipse gives me