memset

「网络流 24 题」方格取数

自闭症网瘾萝莉.ら 提交于 2020-01-22 01:25:39
嘛,你把图分类一下 分成横坐标+纵坐标为奇偶... 然后在图上跑一个二分图最大权匹配 然后就是max(ans, 全部的-ans) 我代码写得有点... 1 #include<bits/stdc++.h> 2 using namespace std; 3 4 int inf=9999999; 5 int m,n,h[30005],tot=(-1),ans=0,sum=0; 6 int tu[305][305]; 7 struct node{ 8 int from,to,next,rest; 9 }e[300005]; 10 11 int zb(int x,int y){ 12 return (x-1)*n+y; 13 } 14 15 void add(int x,int y,int z){ 16 tot++; 17 e[tot].next=h[x]; 18 h[x]=tot; 19 e[tot].from=x; 20 e[tot].to=y; 21 e[tot].rest=z; 22 } 23 24 int dis[3005],g[3005],flow[3005]; 25 bool vis[3005]; 26 27 int bfs(int s,int t){ 28 queue<int>q; 29 dis[s]=0; 30 q.push(s);vis[s]=true; 31 while

「网络流 24 题」圆桌聚餐

六月ゝ 毕业季﹏ 提交于 2020-01-22 01:19:38
网络流水题,详细看代码 1 #include<bits/stdc++.h> 2 using namespace std; 3 4 int n,m,tot=-1,h[3005],ans=0,sum=0; 5 struct node{ 6 int from,next,to,rest,full; 7 int last; 8 }e[100005]; 9 void add(int x,int y,int z){ 10 tot++; 11 e[tot].next=h[x]; 12 h[x]=tot; 13 e[tot].from=x; 14 e[tot].to=y; 15 e[tot].rest=z; 16 e[tot].full=z; 17 } 18 19 int dis[3005],g[3005],flow[3005]; 20 bool vis[3005]; 21 22 int bfs(int s,int t){ 23 queue<int>q; 24 dis[s]=0; 25 q.push(s);vis[s]=true; 26 while(!q.empty()){ 27 int u=q.front();vis[u]=false;q.pop(); 28 for(int i=h[u];i!=(-1);i=e[i].next){ 29 if(dis[e[i].to]>dis[u]+1&&g[e

「网络流 24 题」数字梯形

北城余情 提交于 2020-01-22 00:53:24
直接拆点做,但就是搞不懂为什么wa掉了第一小问.... 不管了 #include<bits/stdc++.h> using namespace std; long long tot=-1,sum=0,h[20005],flow[20005],g[20005],ans=0,dis[20005],ans2=0,inf=9999999; bool vis[20005]; struct node{ long long from,to,next,rest,cost; }e[10000005]; void add(long long x,long long y,long long z,long long hg){ tot++; e[tot].next=h[x]; h[x]=tot; e[tot].cost=hg; e[tot].from=x; e[tot].to=y; e[tot].rest=z; } int bfs(long long s,long long t){ queue<int>q; q.push(s);dis[s]=0;vis[s]=true; while(!q.empty()){ long long u=q.front();q.pop();//vis[u]=false; for(int i=h[u];i!=(-1);i=e[i].next){ if(e[i].rest>0&

餐巾计划问题

懵懂的女人 提交于 2020-01-21 20:06:17
这个题非常的好,真的......我半颓半打,打了一下午最后还是去看了题解,,,, 这个题对限制条件的转换非常的好 先贴代码 1 #include<bits/stdc++.h> 2 using namespace std; 3 4 long long tot=-1,sum=0,h[10005],flow[10005],g[10005],ans=0,dis[10005],ans2=0,inf=999999; 5 bool vis[10005]; 6 struct node{ 7 long long from,to,next,rest,cost; 8 }e[10000005]; 9 10 void add(long long x,long long y,long long z,long long hg){ 11 tot++; 12 e[tot].next=h[x]; 13 h[x]=tot; 14 e[tot].cost=hg; 15 e[tot].from=x; 16 e[tot].to=y; 17 e[tot].rest=z; 18 } 19 20 int bfs(long long s,long long t){ 21 queue<int>q; 22 q.push(s);dis[s]=0;vis[s]=true; 23 while(!q.empty()){ 24 long long

矩阵乘法题目汇总

烈酒焚心 提交于 2020-01-21 08:44:16
矩阵,学过线性代数的都知道,矩阵满足结合律,但不满足交换律 关于矩阵,有很多经典的应用,可以看下大牛的博客 http://www.matrix67.com/blog/archives/276 下面的题目中,最常见的一种应用就是利用矩阵求递推式,可以通过构造矩阵求幂 在这方面,最常见的就是在斐波那契数列方面,可以看下这个博客,超牛的 http://www.cnblogs.com/Knuth/archive/2009/09/04/1559951.html 很容易构造出关于斐波那契的矩阵,累乘求幂,就可以求出斐波那契的对应的项 直接开始题目吧 hdu1575 Tr A 题目,直接矩阵求幂,再求该矩阵的迹,注意,利用矩阵乘法满足结合律,我看可以利用二进制优化求幂次数。比如:A^7=A^4 * A^2 * A^1 具体的结合代码很容易理解的 View Code #include<iostream>#include<algorithm>#include<string>using namespace std;const int MOD = 9973;const int N = 11;int ret[N][N],init[N][N],temp[N][N];int n;void init_(){ for(int i=0;i<n;i++) for(int j=0;j<n;j++) ret[i][j]=

wenbao与动态规划

守給你的承諾、 提交于 2020-01-20 04:05:30
终于要开始了。。。。。。。。 万能的dp ------------------------------------------------------------------------------------------------------------------------------------------------------------------ 动规入门级题目 数字三角形 不多说 http://lx.lanqiao.cn/problem.page?gpid=T312 1 #include <iostream> 2 using namespace std; 3 int a[105][105]; 4 int main(){ 5 int n; 6 scanf("%d", &n); 7 for(int i = 0; i < n; ++i){ 8 for(int j = 0; j <= i; ++j){ 9 scanf("%d", &a[i][j]); 10 } 11 } 12 for(int i = n-2; i >= 0; --i){ 13 for(int j = 0; j <= i; ++j){ 14 a[i][j] = a[i][j] + max(a[i+1][j], a[i+1][j+1]); 15 //cout<<i<<" "<<j<<" "<<a[i][j]

memset 在c++中使用细节注意

独自空忆成欢 提交于 2020-01-18 00:41:48
C语言,在利用struct进行数据封装时,经常会使用memset(this,0,sizeof(*this))来初始化。而C++中,有时候也会用到struct,在利用memset进行初始化时,非常容易踩坑,有些地方需要注意。 C++利用memset初始化struct注意点 1. memset 是按字节对内存块进行初始化的函数,用来给某一块内存空间进行赋值的; 2. memset 作用是在一段内存块中填充某个给定的值,它是对较大的结构体或数组进行清零操作的一种最快方法; 3. 成员变量可以是简单的内置类型(short、int、long、char、float、double); 4. memset函数不能将int数组初始化为0和-1之外的其他值( 除非该值高字节和低字节相同 !!!!这是撞大运的 ): memset是逐字节进行初始化,比如对整型数进行初始化,int是32位的共四个字节,每个字节设置为n,则 如果n=1,1为00000001 00000001 00000001 00000001,转为十进制数是1+1*2^8+1*2^16+1*2^24=16843009,而不是1; 如果n=0,0为 00000000 00000000 00000000 00000000,转化为十进制为0; 如果n=-1,-1为 11111111 11111111 11111111 11111111

memset使用注意事项

China☆狼群 提交于 2020-01-17 23:08:44
Linux下的原型声明 NAME memset - fill memory with a constant byte SYNOPSIS #include <string.h> void *memset(void *s, int c, size_t n); DESCRIPTION The memset() function fills the first n bytes of the memory area pointed to by s with the constant byte c. RETURN VALUE The memset() function returns a pointer to the memory area s. ============================================== memset 函数是内存赋值函数,用来给某一块内存空间进行赋值的。 其原型是:void* memset(void *_Dst, int _Val, size_t _Size); 使用时在文件头加上#include "stdlib.h" 。 _Dst是目标起始地址,_Val是要赋的值, _Size是要赋值的 字节数 。 例1: char str[9]; 我们用memset给str初始化为“00000000”,用法如下 memset(str,0,8); 注意

SPFA判负环-Wormholes POJ - 3259

早过忘川 提交于 2020-01-17 16:29:29
SPFA判负环-Wormholes POJ - 3259 题目: While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destination at a time that is BEFORE you entered the wormhole! Each of FJ’s farms comprises N (1 ≤ N ≤ 500) fields conveniently numbered 1…N, M (1 ≤ M ≤ 2500) paths, and W (1 ≤ W ≤ 200) wormholes. As FJ is an avid time-traveling fan, he wants to do the following: start at some field, travel through some paths and wormholes, and return to the starting field a time before his initial departure.

Avoiding memset for a multi-type structure

孤街醉人 提交于 2020-01-17 16:26:27
问题 I would like to avoid using memset() on a structure like this: typedef struct { int size; float param1; } StructA; typedef struct { StructA a; unsigned int state; float param2; } Object; Can I do something like this (pseudo code, I can't check right now)? Object obj; int *adr = (int*)&obj; for (int i; i < sizeof(obj); i++) { *adr++ = 0; } Will it set every member of obj to zero? EDIT : to answer questions on comments. I have been working on some cases (with uni-type structures), where memset