sizeof

01背包

亡梦爱人 提交于 2020-01-25 08:40:49
Charm Bracelet http://poj.org/problem?id=3624 01背包模板题带空间复杂度优化的。 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #define mt(a,b) memset(a,b,sizeof(a)) 5 using namespace std; 6 const int M=20010; 7 int n,v,dp[M],c[M],w[M]; 8 void ZeroOnePack(int cost,int weight){ 9 for(int i=v;i>=cost;i--){ 10 dp[i]=max(dp[i],dp[i-cost]+weight); 11 } 12 } 13 int main(){ 14 while(~scanf("%d%d",&n,&v)){ 15 for(int i=1;i<=n;i++){ 16 scanf("%d%d",&c[i],&w[i]); 17 } 18 mt(dp,0); 19 for(int i=1;i<=n;i++){ 20 ZeroOnePack(c[i],w[i]); 21 } 22 printf("%d\n",dp[v]); 23 } 24 return 0; 25 } View Code 饭卡 http:/

Warning: sizeof(): Parameter must be an array or an object that implements Countable php7.2

五迷三道 提交于 2020-01-25 06:44:27
问题 I updated to PHP 7.2 and it created an array (no pun intended) of issues. I've been knocking them out (mostly these sizeof and count() warnings. The one error we have : Warning: sizeof(): Parameter must be an array or an object that implements Countable in /usr/www/domain/phpmyd/includes/class_registry.php on line 236 I tried fixing it like this : if (sizeof($this->config) < 1) { To this: if (!empty($this->config) &&(sizeof($this->config) < 1)) { But it creates lots more errors shown below,

Warning: sizeof(): Parameter must be an array or an object that implements Countable php7.2

帅比萌擦擦* 提交于 2020-01-25 06:44:07
问题 I updated to PHP 7.2 and it created an array (no pun intended) of issues. I've been knocking them out (mostly these sizeof and count() warnings. The one error we have : Warning: sizeof(): Parameter must be an array or an object that implements Countable in /usr/www/domain/phpmyd/includes/class_registry.php on line 236 I tried fixing it like this : if (sizeof($this->config) < 1) { To this: if (!empty($this->config) &&(sizeof($this->config) < 1)) { But it creates lots more errors shown below,

单继承,多继承,虚拟继承,sizeof大小

冷暖自知 提交于 2020-01-24 23:48:34
1. 题目 #include<iostream>using namespace std;class S {};class A:S { virtual void fun() { ; }};class B:A { virtual void fun() { ; }};class C:B { virtual void fun() { ; }};class M { virtual void fun() {}};class N { virtual void fun() {}};class P:M,N { virtual void fun() {}};//------------------------------class T_S {};class T_A:virtual T_S { virtual void fun() { ; }};class T_B:virtual T_A { virtual void fun() { ; }};class T_C:virtual T_B { virtual void fun() { ; }};class T_M { virtual void fun() {}};class T_N { virtual void fun() {}};class T_P:virtual T_M,T_N { virtual void fun() {}};int main() {

Tarjan算法专练

左心房为你撑大大i 提交于 2020-01-24 16:46:32
1. 迷宫城堡 题意:给一个图判断是否是强连通图。 题解:利用Tarjan计算图中强连通分量的个数,如果为1则是强连通图,否则不是。 #include<bits/stdc++.h> using namespace std; const int N = 2e4+100; typedef long long ll; vector<int> G[N]; bool is_instack[N]; int dfn[N],low[N]; stack<int> sta; int n,m,index,scc; void init(){ index=scc=0; memset(dfn,0,sizeof(dfn)); memset(low,0,sizeof(low)); memset(is_instack,0,sizeof(is_instack)); while(!sta.empty()) sta.pop(); for(int i=1;i<=n;i++) G[i].clear(); } void Tarjan(int u){ dfn[u]=low[u]=++index; sta.push(u);is_instack[u]=1; for(auto v:G[u]){ if(!dfn[v]){ Tarjan(v); low[u]=min(low[u],low[v]); } else if(is_instack

memset()函数用法及其作用

人盡茶涼 提交于 2020-01-24 15:29:10
memset()函数原型是: extern void *memset(void *buffer, int c, int count) //buffer:为指针或是数组, //c:是赋给buffer的值, //count:是buffer的长度. 这个函数在socket中多用于清空数组.如:原型是: memset(buffer, 0, sizeof(buffer)) 2.memset 用来对一段内存空间全部设置为某个字符,一般用在对定义的字符串进行初始化为‘ ’或‘\0’; char a[100]; memset(a, '\0', sizeof(a)); 3.memset可以方便的清空一个结构类型的变量或数组,如: struct sample_struct { char csName[16]; int iSeq; int iType; }; 对于变量: struct sample_strcut stTest; 一般情况下,清空stTest的方法: stTest.csName[0]='/0'; stTest.iSeq=0; stTest.iType=0; 用memset就非常方便: memset(&stTest,0,sizeof(struct sample_struct)); 如果是数组: struct sample_struct TEST[10]; // 则用 memset(TEST

poj 1469 COURSES

亡梦爱人 提交于 2020-01-24 14:14:09
一、二分图的基本概念 【二分图】 二分图又称作二部图,是图论中的一种特殊模型。 设G=(V,E)是一个无向图,如果顶点V可分割为两个互不相交的子集(A,B),并且图中的每条边(i,j)所关联的两个顶点i和j分别属于这两个不同的顶点集(i in A,j in B),则称图G为一个二分图。 也就是说,只要两个点之间有边,那么这两个点就不能同属一个集合,必须分在两边。 这就带来一个问题,并不是所有的无向图G都能转化为二分图。 【二分图的判定】 定理:无向图G为二分图的充要条件是,G至少有两个顶点,且其所有回路的长度均为偶数。 判定方法:根据定义比根据定理更好判定,只需要从第一个点出发,将其染成颜色1,则与其所有相连的所有终点都染成颜色2,如果与其相连的点已经被染成颜色1,则图G不是二分图。 把该点的所有终点当成新的起点,重复以上过程。很显然,既可以用dfs染色,又可以用bfs染色。 dfs染色代码: #include<iostream> #include<vector> #include<cstring> using namespace std; const int maxn = 10010; int n,m;//顶点数 边数 vector<int> G[maxn]; int color[maxn] ; //0 没染色 1 -1不同色 bool dfs(int u, int c){

针对TCP连接异常断开的分析

最后都变了- 提交于 2020-01-24 04:43:44
我们知道,一个基于TCP/IP的客户端-服务器的程序中,正常情况下,我会是启动服务器使其在一个端口上监听请求,等待客户端的连接;通过TCP的三次握手,客户端能够通过socket建立一个到服务器的连接;然后,两者就可以基于这个socket连接通信了。连接结束后,客户端(进程)会退出;在不需要继续处理客户请求的情况下,服务器(进程)也将退出。而且,当一个进程退出的时候,内核会关闭所有由这个进程打开的套接字,这里将触发TCP的四次挥手进而关闭一个socket连接。但是,在一些异常的情况下,譬如:服务器进程终止、服务器主机奔溃/奔溃后重启、服务器关机的情况下,客户端向服务器发起请求的时候,将会发生什么呢?下边,我们来看看这几种情况。 注意:一下描述的各种情况所使用的示例程序在文章的最后贴出 一、服务器进程终止 我们启动客户/服务器对,然后杀死子进程(模拟服务器进程崩溃的情形,我们可从中查看客户端将发生什么)。 1:在同一个主机上启动服务器和客户,并在客户上输入一行文本,以验证一切正常。正常情况下,改行文本将由服务器回射给客户。 2:找到服务器子进程的ID,通过kill命令杀死它。作为进程终止处理的部分工作,子进程中所有打开着的描述字都被关闭。这就导致向客户发送一个FIN,而客户TCP则响应以一个ACK。这就是TCP连接终止的前一半工作。 3:子进程终止时

Why is a string's byte size longer than the length? [closed]

∥☆過路亽.° 提交于 2020-01-24 02:19:26
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . Why is it that sizeof("Bill") is 5 but sizeof(char) is 1 ? Shouldn't that make sizeof("Bill") be 4 since the length of the string is 4 chars ( 4 x 1 )? I

android4.3 Bluetooth(le)分析之startLeScan分析

梦想与她 提交于 2020-01-24 01:53:41
BluetoothAdapter.java中有low enery(le)的一些方法,android提供了这些方法,但源码中并未找到这些方法的调用之处。本文档主要分析这类方法的执行流程,来了解下le到底做了些什么。 本文主要就是分析下startLeScan方法(两个重载方法)。 public boolean startLeScan(LeScanCallback callback) { return startLeScan(null, callback); } public boolean startLeScan(UUID[] serviceUuids, LeScanCallback callback) { if (DBG) Log.d(TAG, "startLeScan(): " + serviceUuids); synchronized(mLeScanClients) { if (mLeScanClients.containsKey(callback)) { if (DBG) Log.e(TAG, "LE Scan has already started"); return false; } try { //获取BluetoothGattBinder类的实例,该类的定义在GattService.java中 IBluetoothGatt iGatt = mManagerService