codeforces 593D 树链剖分

树链剖分模板题 #include <cstdio> #include <iostream> #include <vector> #define N 30003 #define INF 2147483647 using namespace std; int n,f[N][20],dep[N],siz[N],son[N],top[N],tot,pos[N],w[N]; int Max[N*4],Sum[N*4]; vector <int> to[N]; void dfs1(int x){ siz[x]=1; int sz=to[x].size(); for(int i=0;i<sz;++i){ int y=to[x][i]; if(y==f[x][0])continue; f[y][0]=x; dep[y]=dep[x]+1; dfs1(y); siz[x]+=siz[y]; if(siz[y]>siz[son[x]])son[x]=y; } } void dfs2(int x,int root){ top[x]=root; pos[x]=++tot; if(son[x])dfs2(son[x],root); int sz=to[x].size(); for(int i=0;i<sz;++i){ int y=to[x][i]; if(y==f[x][0] || y==son[x])continue; dfs2(y,y); } } void update(int k,int l,int r,int P,int V){ if(l==r){ Max[k]=Sum[k]=V; return; } int mid=(l+r)>>1; if(P<=mid)update(k*2,l,mid,P,V); else update(k*2+1,mid+1,r,P,V); Max[k]=max(Max[k*2],Max[k*2+1]); Sum[k]=Sum[k*2]+Sum[k*2+1]; } void up(int &x,int goal){ for(int i=15;i>=0;--i) if(dep[f[x][i]]>=goal)x=f[x][i]; } int lca(int x,int y){ if(dep[x]>dep[y])up(x,dep[y]); if(dep[x]<dep[y])up(y,dep[x]); if(x==y)return x; for(int i=15;i>=0;--i) if(f[x][i]!=f[y][i])x=f[x][i],y=f[y][i]; return f[x][0]; } int getm(int k,int l,int r,int L,int R){ if(L<=l && r<=R)return Max[k]; int res=-INF,mid=(l+r)>>1; if(L<=mid)res=max(res,getm(k*2,l,mid,L,R)); if(R>mid)res=max(res,getm(k*2+1,mid+1,r,L,R)); return res; } int gets(int k,int l,int r,int L,int R){ if(L<=l && r<=R)return Sum[k]; int res=0,mid=(l+r)>>1; if(L<=mid)res+=gets(k*2,l,mid,L,R); if(R>mid)res+=gets(k*2+1,mid+1,r,L,R); return res; } int main(){ scanf("%d",&n); for(int i=1,a,b;i<n;++i){ scanf("%d%d",&a,&b); to[a].push_back(b); to[b].push_back(a); } dep[1]=1; dfs1(1); dfs2(1,1); for(int i=1;i<=15;++i) for(int j=1;j<=n;++j)f[j][i]=f[f[j][i-1]][i-1]; for(int i=1;i<=n;++i){ scanf("%d",&w[i]); update(1,1,n,pos[i],w[i]); } int q; scanf("%d",&q); while(q--){ char s[10]; int u,v,t; scanf("%s",s); if(s[1]=='H'){ scanf("%d%d",&u,&t); w[u]=t; update(1,1,n,pos[u],t); } if(s[1]=='M'){ scanf("%d%d",&u,&v); int ans=-INF,t=lca(u,v); for(int i=u;i;i=f[top[i]][0]) if(dep[t]<dep[top[i]]) ans=max(ans,getm(1,1,n,pos[top[i]],pos[i])); else{ ans=max(ans,getm(1,1,n,pos[t],pos[i])); break; } for(int i=v;i;i=f[top[i]][0]) if(dep[t]<dep[top[i]]) ans=max(ans,getm(1,1,n,pos[top[i]],pos[i])); else{ ans=max(ans,getm(1,1,n,pos[t],pos[i])); break; } printf("%d\n",ans); } if(s[1]=='S'){ scanf("%d%d",&u,&v); int ans=0,t=lca(u,v); for(int i=u;i;i=f[top[i]][0]) if(dep[t]<dep[top[i]]) ans+=gets(1,1,n,pos[top[i]],pos[i]); else{ ans+=gets(1,1,n,pos[t],pos[i]); break; } for(int i=v;i;i=f[top[i]][0]) if(dep[t]<dep[top[i]]) ans+=gets(1,1,n,pos[top[i]],pos[i]); else{ ans+=gets(1,1,n,pos[t],pos[i]); break; } printf("%d\n",ans-w[t]); } } } 立即下载

题目链接
新地址链接
给出一棵树,每棵树有value值,两种操作:1 u v x, 用x依次除以u到v路径上的数,然后
输出x,2 p x, 把第p条边的权值改为x. 直接树链剖分,然后用线段树维护乘积即可。注意
乘积可能爆long long , 可以用inf/a如果

#include <cstdio>
#include <cstring>
#include <algorithm>
#define lson o<<1,l,m
#define rson o<<1|1,m+1,r
using namespace std; 
typedef long long Long;
const int maxn = 2e5 + 10;
const int maxe = maxn*2;
const Long inf = 1e18 + 10000;

struct divTree
{
    void add_edge(int u, int v, Long c)
    {
        edges[cnt_edge] = Edge(u, v, c, fir[u]);
        fir[u] = cnt_edge++;
    }
    void init()
    {
        memset(fir, -1, sizeof(fir));
        cnt_edge = 0;
    }
    void dfs1(int u)
    {
        sz[u] = 1; son[u] = 0;
        for (int e = fir[u]; e != -1; e = edges[e].x)
        {
            int v = edges[e].v; if (v == fa[u]) continue;
            dep[v] = dep[u]+1; fa[v] = u;
            dfs1(v);
            sz[u] += sz[v];
            if (sz[son[u]] < sz[v])
            {
                son[u] = v;
            }
        }
    }
    void dfs2(int u)
    {
        if (son[u]) 
        {
            faEdge[son[u]] = ++no;
            train[son[u]] = train[u];
            dfs2(son[u]);
        }
        for (int e = fir[u]; e != -1; e = edges[e].x)
        {
            int v = edges[e].v; if (v == fa[u]) continue;
            if (v == son[u])
            {
                val[faEdge[v]] = edges[e].c;
                mp[e/2+1] = faEdge[v];
            }
            else
            {
                faEdge[v] = ++no;
                val[no] = edges[e].c; mp[e/2+1] = no;
                train[v] = v;
                dfs2(v);
            }
        }
    }
    void pushUp(int o)
    {
        if (inf / sum[o<<1] < sum[o<<1|1]) sum[o] = inf;
        else sum[o] = sum[o<<1]*sum[o<<1|1];
    }
    void build(int o, int l, int r)
    {
        if (l == r)
        {
            sum[o] = val[l];
            return ;
        }
        int m = (l + r) >> 1;
        build(lson); build(rson);
        pushUp(o);
    }
    void run(int rt)
    {
        dep[rt] = 1; fa[rt] = rt;
        dfs1(rt);
        no = 0; train[rt] = rt;
        dfs2(rt);
        build(1, 1, no);
    }

    void update(int p, Long v, int o, int l, int r)
    {
        if (l == r)
        {
            sum[o] = v;
            return ;
        }
        int m = (l + r) >> 1;
        if (p <= m) update(p, v, lson);
        else update(p, v, rson);
        pushUp(o);
    }
    Long query(int a, int b, int o, int l, int r)
    {
        if (a <= l && b >= r)
        {
            return sum[o];
        }
        int m = (l + r) >> 1;
        if (a <= m && b > m)
        {
            Long v1 = query(a, b, lson), v2 = query(a, b, rson);
            if (inf/v1 < v2) return inf;
            else return v1*v2;
        }
        else if (a <= m) return query(a, b, lson);
        else return query(a, b, rson);
    }
    Long gao(int u, int v)
    {
        Long ret = 1;
        for (int fu=train[u], fv=train[v]; fu != fv; fu=train[u],fv=train[v])
        {
            if (dep[fu] < dep[fv])
            {
                swap(u, v); swap(fu, fv);
            }
            Long now = query(faEdge[fu], faEdge[u], 1, 1, no);
            if (inf/now < ret) ret = inf;
            else ret = ret * now;
            u = fa[fu];
        }
        if (u == v) return ret;
        if (dep[u] > dep[v]) swap(u, v);
        Long now = query(faEdge[son[u]], faEdge[v], 1, 1, no);
        if (inf/now < ret) ret = inf;
        else ret = ret * now;
        return ret;
    }   
    struct Edge
    {
        int u, v, x;
        Long c;
        Edge(int u = 0, int v = 0, Long c = 0, int x = 0) : u(u), v(v), c(c), x(x) {}
    } edges[maxe];
    int fir[maxn], cnt_edge, no;
    int dep[maxn], sz[maxn], fa[maxn], son[maxn];
    int train[maxn], mp[maxn], faEdge[maxn];
    Long val[maxn], sum[maxn<<2];
} divt;
int main()
{
    int n, m; scanf("%d%d", &n, &m);

    divt.init();
    for (int i = 0; i < n-1; i++)
    {
        int u, v; Long c; scanf("%d%d%I64d", &u, &v, &c);
        divt.add_edge(u, v, c);
        divt.add_edge(v, u, c);
    }
    divt.run(1);
    for (int i = 0; i < m; i++)
    {
        int cmd; scanf("%d", &cmd);
        if (cmd == 1) 
        {
            int a, b; Long v; scanf("%d%d%I64d", &a, &b, &v);
            Long now = divt.gao(a, b);
            printf("%I64d\n", v/now);
        } 
        else 
        {
            int p; Long v; scanf("%d%I64d", &p, &v);
            divt.update(divt.mp[p], v, 1, 1, divt.no);
        }
    }

    return 0;
}
Xilinx ERNIC RoCEv2 FPGA实现与QP队列深度解析 本文深入解析Xilinx ERNIC RoCEv2在FPGA上的实现,重点剖析QP队列对的管理机制与深度优化策略。通过Verilog代码示例和工程实战,详细介绍了如何实现高吞吐量、低延迟的RDMA硬件卸载方案,为金融交易和数据中心应用提供性能优化指导。 阅读详情

相关推荐

深入解析Cuk、Zeta和Sepic拓扑:非隔离型开关电源的设计奥秘

本文深入解析了Cuk、Zeta和Sepic三种非隔离型开关电源拓扑的设计奥秘。它们均能实现升降压转换,但特性各异:Cuk拓扑输出反向电压,输入输出纹波极低;Sepic拓扑输出同极性电压,应用广泛;Zeta拓扑输出纹波小,适合精密供电。文章详细对比了其电路结构、工作原理、核心公式及选型指南,帮助工程师根据输入电压范围、输出极性及纹波要求,灵活选择最合适的拓扑方案。

weixin_28308325的博客 476

CodeForces - 1046A (动态开线段树)

CodeForces - 1046A 题意: 给一组机器人,每个机器人有x,r,q三个属性。x:坐标,r:视野范围,q:IQ值。 每个机器人视野为:[x-r,x+r],如果一对机器人相互可以看到,且它们的智商差距不大于K,那么他们可以聊天。问多少对机器人可以聊天。   题解: 先按视野降序排序,后面能看到前面的话,则前面的一定也可以看见后面。 然后对于当前机器人来说,看在他前面有几...

sgh666666的博客 277

电商智能客服Agent开发实战:从零到一构建企业级AI助手

电商智能客服Agent是下一代AI应用的核心形态,它不仅能够回答用户问题,还能自主规划任务、调用工具并执行完整工作流程。本文将深入探讨AI Agent的基本概念、技术实现方式及电商场景中的应用,提供完整的开发流程和代码示例,帮助开发者从零开始构建一个功能强大的电商智能客服系统。通过模块化设计、多轮对话记忆管理和工具集成,这个Agent能够处理订单查询、商品推荐、退换货流程等复杂任务,同时具备企业级的安全性和稳定性保障。通过本文的介绍,读者已经掌握了构建电商智能客服Agent的核心技术与实现方法。

m0_64363449的博客 1360

CodeForces830B【树状数组+线段树】

思路: 就是 你好像就是要维护一下,你pop的当前值与之前的pop值的位置之间有多少个要移一移,然后算一下,然后就变成了模拟。。 线段树维护 值 和 位置,树状数组维护已经取了没有。 7 6 3 1 5 4 4 3 代码:#include<bits/stdc++.h> using namespace std; typedef long long LL;const int INF = 0

ONE MORE TRY 547

利用Python搭建用户画像系统

用户画像是当下很多企业都会提及的概念,多数情况下会和大数据以及营销挂钩。本文将对用户画像的相关知识进行进行简单的介绍,并利用Python去实现一个简单的用户画像系统。 1.什么是用户画像 用户画像可以理解成是海量数据的标签,根据用户的目标、行为和观点的差异,将他们区分为不同的类型,然后每种类型中抽取出典型特征,赋予名字、照片、一些人口统计学要素、场景等描述,形成一个人物原型 。 用户画像 =...

黎荣恒的博客 3万+

树莓派安装snowboy

1、树莓派换源 参考链接:https://blog.youkuaiyun.com/qq_43556844/article/details/113615915 2、更新pip3 参考链接:https://blog.youkuaiyun.com/qq_43556844/article/details/113616214 3、存取麦克风 我们使用PortAudio作为音频输入/输出的跨平台支持。我们还使用sox作为快速实用程序来检查麦克风设置是否正确。 sudo apt-get install python-pyaudio python

qq_43556844的博客 1923

codeforces-191C (树链剖分+边的区间修改)

题意:给出一棵树,每次可以使任意两点间的路径的权值加1,最后求出每条边的权值题解:可以作为基于边权的树链剖分的模板,有个技巧是用eg数组来将边的序号和点关联起来代码:#include&lt;iostream&gt; #include&lt;cstdio&gt; #include&lt;cstring&gt; #include&lt;algorithm&gt; using namespace st...

GrimCake的博客 797

task5:在本地搭建大模型(ollama 和 LM studio 对比),接入 openclaw

关于大模型,大家千万不要想着在本地部署,根本不可行,没有那个财力。另外大模型迭代快,不可能每周都在下载大模型。再次,还是国外的模型好用,国内的模型真的在 deepresearch 上就有很大问题,你们懂的。所以本篇文章,还是聚焦在探索层面+实操,并不会实战。

这里是 AI 食用指南,持续分享有用的AI 实操和应用! 1968

[树链剖分 线段树] Codeforces 860E. Arkady and a Nobody-men

按照深度从小大加入,就是一个很典型的熟练剖分加线段树实现路径修改、询问的模型复杂度是 O(nlog2n)O(n\log^2n)最后一个点加个标记永久化、记忆化什么的卡一卡才能过…#include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <set> #in

CE玩家 582

【02】【VisionMaster V4.0.0 】安装教程—— 授权文件更新报错:应用程序与本地LM通讯出错(怀疑电脑加密 和 上网受限 造成的 )

本文详细介绍了海康VisionMaster 4.0试用版的安装流程及常见问题解决方案。主要内容包括:1)从官网下载基础安装包、试用补丁和授权文件;2)按顺序安装主程序、补丁和授权文件;3)针对授权失败问题提供两种解决方案(更换未加密电脑或使用加密狗);4)说明试用版的功能限制(30天试用期、2个流程限制等)。文章特别指出电脑加密可能导致授权失败,并提供了安装报错时的处理建议,为初次使用者提供了完整的安装指导。

程序员,他们想的是什么?他们想的永远都是技术,他们崇尚的也永远都是技术。 7152

GameFramework 框架详解之 Network网络模块 工具链

GameFramework(下面简称GF)Demo中,已经给我们提供了Network模块使用的protobuf使用的动态链接库protobuf-net.dll,但是GF并没有给我们提供protobuf相关的工具链,比如:1.proto文件自动导出对应c#的Packet类和PacketHandler类2.导出Packet类继承IReference以便使用引用池。3.自动生成Packet类和PacketHandler的Id,且保持和服务器Id一一对应。

TxNet 2902

Codeforces 1111C Creating Snap (动态开点线段树)

wow 出题人太良心了放动态开点线段树过了 理解题意,发现我们要维护的是一个长度为 2n2^n2n 的区间。 于是我们想到用线段树来维护。 线段树的每个节点维护区间内的人数和价值,然后按照题意 pushuppushuppushup 即可。 注意如果一个区间内的人数为 000,这个区间的价值为 AAA 。 由于 2n2^n2n 很大,所以我们要动态开节点。 建树的时候将所有人依次插入线段树中。 最后...

Hacheylight 575

IGBT基础知识及应用电路仿真(Multisim)

本文系统介绍了IGBT(绝缘栅双极晶体管)及其应用电路。首先详细解析了IGBT的基本结构、工作原理和特性参数,重点阐述了其五层半导体结构、电导调制效应和电压驱动特性。随后通过Multisim仿真展示了IGBT在四种典型功率变换电路中的应用:半桥驱动电路实现隔离式互补驱动;全桥逆变电路完成DC-AC转换;三相桥式逆变电路生成三相交流电;直流斩波电路(BUCK/BOOST/BUCK-BOOST)实现电压升降变换。文章通过理论分析与仿真波形相结合,全面呈现了IGBT在中高压大功率场景下的优异性能和灵活应用。

XU157303764的博客 1217

codeforces 593D happy tree party 树链剖分

/* 题目描述:给定一棵树及其边权,有两种操作 1 u v y 用y依次去除uv的公共路径上的每一条边的边权,注意这里的除法是整数的除法 2 x p 把第x条输入边的边权变为p 方法:容易证明,依次去除每一条边权,等于除以这条路径上所有边权的乘积,原因是前者相当于除一次保留一次,后者相当于 每次除完保留小数,最后保留一次,根据这个理论可以证明二者结果

jijijix的博客 372

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

Codeforces 593D - Happy Tree Party(树链剖分)

#include #include #include #include #include #define lson l, m, rt<<1 #define rson m+1, r, rt<<1|1 using namespace std; const int maxn = 200020; const long long INF = 1e18; int n, m, total, edg

diary_yang的专栏 985

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

Codeforces Round #329 (Div. 2) 593D. Happy Tree Party(树链剖分)

题意:给你一棵树,每条边上有权值。有两个操作 1. u v p 从u~v的路径上用p除每跳边的权值,向下取整 2. u p 将第u条边的权值改为p 思路:树链剖分 呃…算是模板题吧 因为这道题学了十几个小时的树链剖分 照着卿神的blog理解的Orz 这里写链接内容#include<stdio.h> #include<string.h> #include<iostream> #includ

humeay的博客 485

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

CodeForces 593D Happy Tree Party(树链剖分(边权) or LCA+并查集)

题意:给你一棵数,n个点n-1条边,每条边有个权值,q次询问,询问有两种: 1 a b y : a到b的路径上不断进行y = y/xi(像下取整),问最后y的值 2 p c :  将第p条边的权值改为c,c一定比原来这条边的值小 思路: 树剖:线段树记录区间的乘积,查询的时候当两者重链的top相等的时候注意去掉top点的权值。 每条边的权值都是在1e18内,所以如果线段树某个元素

CillyB的博客 760

Codeforces 593

593 B 题意 给你 \(n\) 条直线(没有与y轴平行的直线),问有没有一个交点在 \((X_1,X_2)\) 内。( \(2 ≤ n ≤ 100000\) ) Examples Input 4 1 2 1 2 1 0 0 1 0 2 Output NO Input 2 1 3 1 0 -1 3 Output YES Input 2 1 3 1 0 0 2 Output YES Input 2...

weixin_30793643的博客 96

Codeforces 593D-Happy Tree Party

Happy Tree Party time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Bogdan has a birthday today and mom gave h

wang_128的博客 446

CodeForces 593D Happy Tree Party

Description Bogdan has a birthday today and mom gave him a tree consisting of n vertecies. For every edge of the tree i, some number xi was written on it. In case you forget, a tree is a connecte

Occult 605

Codeforces Round #329 (Div. 2)D LCA+并查集路径压缩

链接:http://codeforces.com/problemset/problem/593/D 题意:一棵树,有边权, 两种操作:其一,改变边权(边权只能越改越小并且大于1)。其二,给一个X(1----1e18),和a,b两点,问X / (简单路径的边权乘积) 思路:1.裸树链剖分,维护区间乘积就可以。。爆LL的区间直接记做一个inf。。但是不太会树链剖分,考虑一个退而求

zxl博客 304

codeforces #329 D. Happy Tree Party (LCA+并查集 || 树链剖分)

题目:http://codeforces.com/contest/593/problem/D 题意:给定一棵n个节点的树。有两种操作:①给定 u v p, 求p除u--->v这条链上所有的边权的值(每次上下取整)②修改某一条边的边权。 分析: 解法一:由于p 具体做法:u-->lca (deep(u)>deep(lca)), v-->lca (deep(v)>deep(lca)) 代码:

w20810的专栏 542

Codeforces Round #329 (Div. 2) D. Happy Tree Party 树链剖分

D. Happy Tree Party Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/593/problem/D Description Bogdan has a birthday today and mom gave him a tree consisting of...

weixin_34240657的博客 171

CodeForces 165D Beard Graph(树链剖分)

树链剖分偏模板题。 #include #include #include #include #include #include #include using namespace std; const int maxn = 100000 + 7; const int INF = ~0U >> 1; typedef long long LL; typedef pair P; st

THE___BEST的专栏 642

[Codeforces343D]Water Tree(树链剖分)

题目描述传送门题解题如其名代码#include<algorithm> #include<iostream> #include<cstring> #include<cstdio> #include<cmath> using namespace std; #define N 500005int n,m,dfs_clock; int tot,point[N],nxt[N*2],v[N*2]; int si

zyf2000 534
上一篇: 2015-2016 ACM ICPC Baltic Selection Contest [解题报告]
吃掉吃掉
博客等级 码龄12年 7粉丝 30原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值