num

摘抄一篇:图的存储结构

筅森魡賤 提交于 2020-02-25 05:36:27
. 图的邻接矩阵(Adjacency Matrix)存储表示法        设图 A = (V, E)是一个有 n 个顶点的图, 图的邻接矩阵是一个二维数组 A.edge[n][n],  用来存放顶点的信息和边或弧的信息。定义为:       (1) 无向图的邻接矩阵是对称的;有向图的邻接矩阵可能是不对称的。 (2) 在有向图中, 统计第 i 行 1 的个数可得顶点 i 的出度,统计第 j 行 1 的个    数可得顶点j 的入度。在无向图中, 统计第 i 行 (列) 1 的个数可得顶点i的    度。 图的邻接矩阵存储表示: #define INFINITY INT_MAX // 最大值∞ #define MAX_VERTEX_NUM 20 // 最大顶点个数 typedef enum {DG, DN, AG, AN} GraphKind; // {有向图,有向网,无向图,无向网} typedef struct ArcCell { VRType adj; // VRType是顶点关系类型。对无权图,用1或0表示相邻否; // 对带权图,则为权值类型。 InfoType *info; // 该弧相关信息的指针 } ArcCell, AdjMatrix[MAX_VERTEX_NUM][MAX_VERTEX_NUM]; typedef struct { VertexType vexs

数组模拟邻接表

醉酒当歌 提交于 2020-02-25 05:24:54
1 const int N=maxn; 2 // maxn表示图中最大顶点数 3 const int E=maxe ; // maxe图中最大边数 4 struct Edge{ 5 int u,v; //边所邻接的两个顶点 6 int w; //边的权值 7 int next; //边指针,指向下一条边的内存地址 8 }edge[E]; // 静态内存,用于分配边 9 int head[N]; // 表头 10 int num; // 内存的指针 11 void init() 12 { 13 for(int i=0;i<E;i++) head[i]=-1; //这里为什么要设为-1 14 num= 0; 15 } 16 void addedge(int b,int e,int w) 17 { 18 edge[num].u=b; 19 edge[num].v=e; 20 edge[num].w=w; 21 edge[num].next=head[b]; 22 head[b]=num++; 23 } 24 来源: https://www.cnblogs.com/lyqlyq/p/6682588.html

算法竞赛入门经典第二章习题解答

空扰寡人 提交于 2020-02-25 01:59:03
本章的题目需用文件输入输出,如果题目代号为abc,那么输入文件为abc.in,输出文件为abc.out。如果对文件操作不熟练,请尽量把fopen和freopen两种方法都尝试一下。 注:本次解答中前4题给出两种方法,第五题采用fopen方法,其余均采用重定向方法。 习题2-1 位数(digit) 问题描述:输入一个不超过10^9的正整数,输出它的位数。例如12735的位数是5.请不要使用任何数学函数,只用四则运算和循环语句实现。 重定向版: #define LOCAL #include<iostream> #include<cstdlib> #include<cstdio> using namespace std; int main() { #ifdef LOCAL freopen("digit.in","r",stdin); freopen("digit.out","w",stdout); #endif // LOCAL int n,cnt=1; scanf("%d",&n); while(n/10) { cnt++; n/=10; } printf("位数:%d\n",cnt); } fopen版: #include<stdio.h> int main() { FILE *fin,*fout; fin=fopen("digit.in","rb"); fout=fopen(

递归函数-汉诺塔经典递归

非 Y 不嫁゛ 提交于 2020-02-25 01:15:06
前言 最近在读《JavaScript语言精粹》,对递归函数有了进一步的认识,希望总结下来: 递归是一种强大的编程技术,他把一个问题分解为一组相似的子问题,每一问题都用一个寻常解去解决。递归函数就是会直接或者间接调用自身的一种函数,一般来说,一个递归函数调用自身去解决它的子问题。 "汉诺塔"经典递归问题 "汉诺塔"是印度的一个古老传说,也是程序设计中的经典的递归问题,是一个著名的益智游戏:   题目如下:     塔上有三根柱子和一套直径各不相同的空心圆盘,开始时源柱子上的所有圆盘都按从大到小的顺序排列。目标是通过每一次移动一个圆盘到另一根柱子上,最终把一堆圆盘移动到目标柱子上,过程中不允许把较大的圆盘放置在较小的圆盘上;      寻找规律(把所有的圆盘移动到C):   1)n(圆盘个数) == 1     第一次:1号盘 A -> C sum(移动次数) = 1   2)n == 2     第一次:1号盘 A -> B     第二次:2号盘 A -> C     第三次:1号盘 B -> C  sum = 3   3)n == 3     第一次:1号盘 A -> C     第二次:2号盘 A -> B     第三次:1号盘 C -> B     第四次:3号盘 A -> C     第五次:1号盘 B -> A     第六次:2号盘 B -> C     第七次

带修莫队模版

我怕爱的太早我们不能终老 提交于 2020-02-25 01:04:30
https://www.luogu.com.cn/problem/P1903#submit #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <cmath> #include <cstdlib> #include <vector> #include <queue> #include <map> #define lson rt<<1 #define rson rt<<1|1 using namespace std; typedef pair<int, int> P; typedef pair<int, P> PP;//R L time count typedef long long ll; const int maxn=2e5+10; int a[maxn],num[maxn*10],kuai,time_,q,l,r,time_now,ans_now; struct nod{ int L,R,ti,coun; }; vector<nod> D; vector<P> ans; PP t[maxn]; bool cmp(nod n1,nod n2) { if(n1.L/kuai==n2.L/kuai) { if(n1.R/kuai==n2.R/kuai) {

数位dp

自闭症网瘾萝莉.ら 提交于 2020-02-25 00:33:28
bzoj3679 数字之积 题目大意:给定n、l、r,f(i)表示i的各位数字之积(不含前导0),求出0<f(i)<=n(l<=i<r)的个数。 思路:这是在夏令营中学长讲的题目,听到一种相对简单的方法。很显然要用1~r的个数-1~l的个数我们先用2、3、5、7(因为每一位都是0~9,所以只能有这几种质数乘起来)dfs出可能的乘积,放在一个数组num中,用f[i][j]表示i位数字(不含前导0)乘积在数组中的下表j的方案数,更新时,用能整除num[j]的k在num中的位置对应的f[i-1][pok]更新答案,然后把这个f数组做成前缀和,就表示下标对应数字<=j的个数了。然后就是数位的部分,把这个数分成一位一位的,首先把长度比这个数小的所有方案都加起来,然后考虑长度一样的,每次穷举严格小于这一位的数,找到可用的乘积在num中的位置,然后加给答案,每一位结束后,就将n除以这一位上的原数。这里有一个问题,就是0,如果这一位是0我们就直接break掉就可以了,因为后面不会有满足要求的答案了(乘起来肯定是0,不符合要求)。 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define LL long long using namespace std; LL num[100000]={0},f

Python for 循环语句实例

佐手、 提交于 2020-02-24 23:30:16
目录 for 循环语句(求列表中最大值) isinstance函数用法 实例应用: for 循环语句(求列表中最大值) ''' 此代码 for循环的使用案例 获取列表中多种元素中的最大值 ''' list1=[123,456,11111,55102,451,'你好','hello'] #list列表 max01=list1[0] print(max01) #a列表中的最大值 for num in list1: #for循环依次获取列表中每一个元素 print(num) if isinstance(num, int): #if判断是否为数值类型 if max01<num: max01=num #赋值max01为最大值 print('最大值为:',max01) isinstance函数用法 isinstance是Python中的一个内建函数 isinstance(object, classinfo) 举例: >>> isinstance(1, int)  判断是否是int型 True >>> isinstance(1.0, float) 判断是否是float型 True >>> isinstance(s,string) 判断是否是字符串型 实例应用: 更新中...... 来源: CSDN 作者: Thinklov 链接: https://blog.csdn.net/u010244992

5种PHP生成图片验证码实例

假如想象 提交于 2020-02-24 23:20:28
5种PHP生成图片验证码实例,包括数字验证码、数字+字母验证码、中文验证码、仿google验证码和算术验证码,PHP生成验证码的原理:通过GD库,生成一张带验证码的图片,并将验证码保存在Session中。 js验证 1 $(function() { 2 $("#getcode_num").click(function() { //数字验证 3 $(this).attr("src", 'code_num.php?' + Math.random()); 4 }); 5 $("#chk_num").click(function() { 6 var code_num = $("#code_num").val(); 7 $.post("chk_code.php?act=num", { 8 code: code_num 9 }, 10 function(msg) { 11 if (msg == 1) { 12 alert("验证码正确!"); 13 } else { 14 alert("验证码错误!"); 15 } 16 }); 17 }); 18 //数字+字母验证 19 $("#getcode_char").click(function() { 20 $(this).attr("src", 'code_char.php?' + Math.random()); 21 }); 22 $("

POJ3252——Round Number(组合数学)

余生颓废 提交于 2020-02-24 23:16:42
Round Numbers Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, Paper, Stone' (also known as 'Rock, Paper, Scissors', 'Ro, Sham, Bo', and a host of other names) in order to make arbitrary decisions such as who gets to be milked first. They can't even flip a coin because it's so hard to toss using hooves. They have thus resorted to "round number" matching. The first cow picks an integer less than two billion. The second cow does the same. If the numbers are both "round numbers", the first cow wins, otherwise the second cow wins. A positive

多层感知机的从零开始实现——2020.2.24

∥☆過路亽.° 提交于 2020-02-24 22:41:32
之前写过“多层感知机概述”,可点击查看 多层感知机概述——2020.2.15 下⾯实现⼀个多层感知机。⾸先导⼊实现所需的包或模块。 # 导包 import torch import numpy as np import sys sys.path.append("..") import d2lzh_pytorch as d2l 1. 获取和读取数据: 这⾥继续使⽤Fashion-MNIST数据集。我们将使⽤多层感知机对图像进⾏分类。 # 1.获取和读取数据 batch_size = 256 train_iter, test_iter = d2l.load_data_fashion_mnist(batch_size) 2. 定义模型参数 Fashion-MNIST数据集中图像形状为 \(28 \times 28\) ,类别数为 10 。本节中我们依然使⽤⻓度为 \(28 \times 28 = 784\) 的向量表示每⼀张图像。因此,输⼊个数为784,输出个数为10。实验中,我们设超参数隐藏单元个数为256。 # 2 定义模型参数 num_inputs, num_outputs, num_hiddens = 784, 10, 256 w1 = torch.tensor(np.random.normal(0, 0.01, (num_inputs, num_hiddens)),dtype