memset

牛客练习赛53 部分题解

孤街醉人 提交于 2019-12-01 05:40:51
A、签到,暴力打个表就发现规律是斐波那契数列 代码: #include <bits/stdc++.h> #define int long long #define sc(a) scanf("%lld",&a) #define scc(a,b) scanf("%lld %lld",&a,&b) #define sccc(a,b,c) scanf("%lld %lld %lld",&a,&b,&c) #define scs(a) scanf("%s",a) #define schar(a) scanf("%c",&a) #define pr(a) printf("%lld",a) #define fo(i,a,b) for(int i=a;i<b;++i) #define re(i,a,b) for(int i=a;i<=b;++i) #define rfo(i,a,b) for(int i=a;i>b;--i) #define rre(i,a,b) for(int i=a;i>=b;--i) #define prn() printf("\n") #define prs() printf(" ") #define mkp make_pair #define pii pair<int,int> #define pub(a) push_back(a) #define pob() pop

图论2 1010

♀尐吖头ヾ 提交于 2019-12-01 04:56:37
最小生成树 给你一个无向带权连通图,每条边是黑色或白色。让你求一棵恰好有need条白色边的权值和最小的生成树。题目保证有解。 对于所有数据,V,E<=100000,c为[1,1000]中的正整数。 题解 可以知道恰好选到need条白边就是最优的,考虑给所有白边加上一个值,随着值的增大,在生成树中的白边越少,所以可以二分。 取最后一次满足条件的值。 排序的时候,对于相同值的边白边优先。 #include<cstdio> #include<iostream> #include<algorithm> using namespace std; const int maxn=100005; int n,m,need; int fa[maxn],sum,cnt; struct edge{ int x,y,c,val; bool operator < (const edge a) const { if(val==a.val) return c<a.c; return val<a.val; } }e[maxn],cy[maxn]; template<class T>inline void read(T &x){ x=0;int f=0;char ch=getchar(); while(!isdigit(ch)) {f|=(ch=='-');ch=getchar();} while(isdigit

20191005-T1-U91354 地下党

戏子无情 提交于 2019-11-30 22:23:28
传送门: https://www.luogu.org/problem/U91354 这道题考场上打了一个dijkstra的暴力,出题人只给了50分。(tip—看dijkstra的性质,第一个访问到的地下党就是最近的,so,直接跳出) 可以看出上面的暴力要跑 k遍dijkstra 复杂度巨大 想想怎么优化呢? 我们可以看一个int的32位二进制的数,当第i位为0或1,那么这两个数一定不相等。 所以我们可以根据这一点,每次枚举int的第几位,建一个超级源点与那些第i位为1的党员连一条0的边,再建一个超级汇点与那些第i位为0的党员连一条0的边。 (实际代码书写,看你想怎么写,可以不真的建出来也可以建出来) 那么我们就只需要跑32遍dijkstra就可以。实测会T,那么怎么办? 你可以把那些党员离散化一下,那么你需要枚举的最高的位数就会变小些。 (真正实现你可以真的离散化,也可以不用离散化排个序即可) 我同学的代码(建出了图,离散化): #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<queue> #define INF 0x3f3f3f3f #define N 1000010 using namespace std; priority_queue<pair<int,int

7.30

时光总嘲笑我的痴心妄想 提交于 2019-11-30 18:47:09
索引 OI赞歌 刷题表 P1010 幂次方【打表】 南蛮图腾【分治】 连续自然数的和【数学】 末日的传说 【数学】 八皇后【回溯】 加分二叉树【DP,前序遍历】 P1030 求先序排列【前序中序后序遍历】 noip原题过手 积木大赛【过水】 乘积最大【DP】 进制转换【模拟,注意负进制的特点】 P1010 幂次方 /* translation: solution: trigger: note: * date: 2019.07.30 */ #include<bits/stdc++.h> using namespace std; #define ll long long #define rep(i,a,b) for(ll i=a;i<=b;++i) #define dwn(i,a,b) for(ll i=a;i>=b;--i) template <typename T> inline void rd(T &x){x=0;char c=getchar();int f=0;while(!isdigit(c)){f|=c=='-';c=getchar();}while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}x=f?-x:x;} #define mem(a,b) memset(a,b,sizeof(a)) #define N int n

What is the correct way to clear sensitive data from memory in iOS?

Deadly 提交于 2019-11-30 12:18:19
I want to clear sensitive data from memory in my iOS app. In Windows I used to use SecureZeroMemory. Now, in iOS, I use plain old memset, but I'm a little worried the compiler might optimize it: https://buildsecurityin.us-cert.gov/bsi/articles/knowledge/coding/771-BSI.html code snippet: NSData *someSensitiveData; memset((void *)someSensitiveData.bytes, 0, someSensitiveData.length); nalply Paraphrasing 771-BSI (link see OP): A way to avoid having the memset call optimized out by the compiler is to access the buffer again after the memset call in a way that would force the compiler not to

Do I have to call memset after I allocated new memory using malloc

六眼飞鱼酱① 提交于 2019-11-30 12:09:15
#include "stdlib.h" #include "stdio.h" #include "string.h" int main(int argc, char* argv[]) { int *test = malloc(15 * sizeof(int)); for(int i = 0;i < 15 ;i ++ ) printf("test is %i\n",test[i]); memset(test,0,sizeof(int) * 15); for(int i = 0 ; i < 15; i ++ ) printf("test after memset is %i\n",test[i]); return 0; } The output I get is very weird: test is 1142126264 test is 32526 ... test is 1701409394 test is 1869348978 test is 1694498930 test after memset is 0 test after memset is 0 test after memset is 0 test after memset is 0 test after memset is 0 ... test after memset is 0 test after memset

Codeforces Round #588 (Div. 2) Anadi and Domino (dfs)

两盒软妹~` 提交于 2019-11-30 11:26:17
题目链接: https://codeforces.com/contest/1230/problem/C 思路:暴搜,,,,赛后一遍过,为啥当时没想到。 1 #include<iostream> 2 #include<cstdio> 3 #include<ctime> 4 #include<cstring> 5 #include<cstdlib> 6 #include<cmath> 7 #include<queue> 8 #include<stack> 9 #include<map> 10 #include<algorithm> 11 #define Max(a,b) ((a)>(b)?(a):(b)) 12 #define Min(a,b) ((a)<(b)?(a):(b)) 13 #define Mem0(x) memset(x,0,sizeof(x)) 14 #define Mem1(x) memset(x,-1,sizeof(x)) 15 #define MemX(x) memset(x,0x3f,sizeof(x)) 16 using namespace std; 17 typedef long long ll; 18 const int inf=0x3f3f3f; 19 const double pi=acos(-1.0); 20 21 int cnt[30][30];

潜伏者

只愿长相守 提交于 2019-11-30 11:24:13
题面 水题喜加一 #include<iostream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> using namespace std; string x,y,z; int c[27],s=0; bool f[27],t[27]; int main() { memset(c,0,sizeof(c)); memset(f,false,sizeof(f)); memset(t,false,sizeof(t)); cin>>x>>y>>z; for(int i=0;i<x.size();++i) { if(!f[x[i]-'A'+1]&&!t[y[i]-'A'+1]) { c[x[i]-'A'+1]=y[i]; f[x[i]-'A'+1]=t[y[i]-'A'+1]=true; ++s; } else if(c[x[i]-'A'+1]!=y[i]) { cout<<"Failed"; return 0; } } if(s!=26) { cout<<"Failed"; return 0; } for(int i=0;i<z.size();++i) { printf("%c",c[z[i]-'A'+1]); } }    来源: https://www.cnblogs.com

【算法简述】图论专题:最短路

纵然是瞬间 提交于 2019-11-30 10:52:58
图论问题概述总结 对于**图论**,我们尊熟悉的算法是比较多的,这次,我就找了集中常用的算法。 ## 几种算法 1. **最短路**算法(Dijkstra,SPFE,FLOYD) - Dijkstra单源最短算法 首先,此算法适用于计算一个点到另一个点的最短路径,且算法绝对不能出现负环。这个算法的速度慢,只用于接觉小规模的问题,如图: ![在这里插入图片描述](https://img-blog.csdnimg.cn/20190609113100303.png)这个图就是求算法的基本思路。算法过程: - 从节点上找到最近点那个节点,将他标记,加入集合U。 - 将定点U连出边的邻点相连接,不在集合U中寻找。 - 重复前面的操作,用来指导V=U是,查找结束,最后结束流程。 本算法的算法流程图: https://wenku.baidu.com/view/8a5c11303968011ca300916a.html 参考代码: ``` #include <iostream> #include <cstring> using namespace std; const int N = 1e3 + 9; const int M = 1e4 + 9; const int inf = 0x3f3f3f3f; struct edge { int v, w, next; edge() {} edge(int

How to use VC++ intrinsic functions w/o run-time library

谁说胖子不能爱 提交于 2019-11-30 06:22:04
问题 I'm involved in one of those challenges where you try to produce the smallest possible binary, so I'm building my program without the C or C++ run-time libraries (RTL). I don't link to the DLL version or the static version. I don't even #include the header files. I have this working fine. Some RTL functions, like memset() , can be useful, so I tried adding my own implementation. It works fine in Debug builds (even for those places where the compiler generates an implicit call to memset() ).