poj3237 树链部分 边权模板

基于Android13的系统启动流程分析(三)之FirstStageMain阶段 init进程是Android系统中用户空间的第一个进程,作为第一个进程,它被赋予了很多极其重要的工作职责,比如创建zygote(孵化器)和属性服务等。init进程是由多个源文件共同组成的,这些文件位于源码目录system/core/init1. Bootloader 引导当按下设备电源键时,最先运行的就是 bootloader(固化在ROM的程序),bootloader 的主要作用就是硬件设备(如 CPU、flash、内存)的初始化并加载到RAM,通过建立内存空间映射,为装载 Linux 内核做好准备,。 阅读详情

Tree
Time Limit: 5000MS Memory Limit: 131072K
Total Submissions: 7384 Accepted: 2001

Description

You are given a tree with N nodes. The tree’s nodes are numbered 1 through N and its edges are numbered 1 through N − 1. Each edge is associated with a weight. Then you are to execute a series of instructions on the tree. The instructions can be one of the following forms:

CHANGE i vChange the weight of the ith edge to v
NEGATE a bNegate the weight of every edge on the path from a to b
QUERY a bFind the maximum weight of edges on the path from a to b

Input

The input contains multiple test cases. The first line of input contains an integer t (t ≤ 20), the number of test cases. Then follow the test cases.

Each test case is preceded by an empty line. The first nonempty line of its contains N (N ≤ 10,000). The next N − 1 lines each contains three integers a, b and c, describing an edge connecting nodes a and b with weight c. The edges are numbered in the order they appear in the input. Below them are the instructions, each sticking to the specification above. A lines with the word “DONE” ends the test case.

Output

For each “QUERY” instruction, output the result on a separate line.

Sample Input

1

3
1 2 1
2 3 2
QUERY 1 2
CHANGE 1 3
QUERY 1 2
DONE

Sample Output

1
3


/*
poj3237 树链部分
感觉是比较不错的题目,主要是线段树掌握不怎么好导致一直有问题。
查询最大值 + 修改边 + 区间置反
先处理出树链,然后再上值
push_up 和 push_down函数
hhh-2016-2-2 3:46:58
*/

#include <functional>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <Map>
using namespace std;
typedef long long ll;
typedef long double ld;

using namespace std;

const int maxn = 100010;

struct node
{
    int to,next;
} edge[maxn*2];

int head[maxn];
int top[maxn];  //链的顶端节点
int far[maxn];  //父亲
int dep[maxn];  //深度
int num[maxn];  //表示以x为根的子树的节点数
int p[maxn];    //p[u]表示边u所在的位置
int fp[maxn];   //与p相对应
int son[maxn];  //重儿子
int tot,pos;
void addedge(int u,int v)
{
    edge[tot].to = v;
    edge[tot].next = head[u];
    head[u] = tot ++;
}

void dfs(int u,int fa,int d)          //先处理出重儿子、dep、far、num
{
    dep[u] = d;
    far[u] = fa;
    num[u] = 1;
    for(int i = head[u]; i != -1; i = edge[i].next)
    {
        int v = edge[i].to;
        if(v != fa)
        {
            dfs(v,u,d+1);
            num[u] += num[v];
            if(son[u] == -1 || num[v] > num[son[u]])
                son[u] = v;
        }
    }
}

void getpos(int u,int sp)
{
    top[u] = sp;
    p[u] = pos++;
    fp[p[u]] = u;
    if(son[u] == -1) return ;
    getpos(son[u],sp);
    for(int i = head[u]; i != -1; i = edge[i].next)
    {
        int v = edge[i].to;
        if(v != far[u] && v != son[u])
            getpos(v,v);
    }
}

struct Node
{
    int l,r;
    int flag;
    int Max,Min;
} segtree[maxn*3];

void build(int i,int l,int r)
{
    segtree[i].l = l;
    segtree[i].r = r;
    segtree[i].Max = 0;
    segtree[i].Min = 0;
    segtree[i].flag = 0;
    if(l == r)
        return ;
    int mid = (l+r)/2;
    build(i<<1,l,mid);
    build((i<<1)|1,mid+1,r);
}

void push_up(int i)
{
    segtree[i].Max = max(segtree[i<<1].Max,segtree[(i<<1)|1].Max);
    segtree[i].Min = min(segtree[i<<1].Min,segtree[(i<<1)|1].Min);
}

void push_down(int i)
{
    if(segtree[i].l == segtree[i].r)
        return ;
    if(segtree[i].flag)
    {
        segtree[i<<1].Max = -segtree[i<<1].Max;
        segtree[i<<1].Min = -segtree[i<<1].Min;
        swap(segtree[i<<1].Max,segtree[i<<1].Min);
        segtree[i<<1].flag ^= 1;

        segtree[(i<<1)|1].Max = -segtree[(i<<1)|1].Max;
        segtree[(i<<1)|1].Min = -segtree[(i<<1)|1].Min;
        segtree[(i<<1)|1].flag ^= 1;
        swap(segtree[(i<<1)|1].Max,segtree[(i<<1)|1].Min);

        segtree[i].flag = 0;
    }
}

void update(int i,int k,int val)
{
    if(segtree[i].l == k && segtree[i].r == k)
    {
        segtree[i].Max = val;
        segtree[i].Min = val;
        segtree[i].flag = 0;
        return ;
    }
    push_down(i);
    int mid = (segtree[i].l+segtree[i].r)>>1;
    if(k <= mid) update(i<<1,k,val);
    else update((i<<1)|1,k,val);
    push_up(i);
}

void negat(int i,int l,int r)
{
    if((segtree[i].l == l && segtree[i].r == r))
    {
        segtree[i].Max = -segtree[i].Max;
        segtree[i].Min = -segtree[i].Min;
        swap(segtree[i].Max,segtree[i].Min);
        segtree[i].flag ^= 1;
        return;
    }
    push_down(i);
    int mid = (segtree[i].l+segtree[i].r)>>1;
    if(r <= mid) negat(i<<1,l,r);
    else if(l > mid) negat((i<<1)|1,l,r);
    else
    {
        negat(i<<1,l,mid);
        negat((i<<1)|1,mid+1,r);
    }
    push_up(i);
}

int query(int i,int l,int r)
{
    if(segtree[i].l == l && segtree[i].r == r)
    {
        return segtree[i].Max;
    }
    push_down(i);
    int mid = (segtree[i].l+segtree[i].r)>>1;
    if(r <= mid) return query(i<<1,l,r);
    else if(l > mid) return query((i<<1)|1,l,r);
    else return max(query(i<<1,l,mid),query((i<<1)|1,mid+1,r));
    push_up(i);
}

int fin(int l,int r)
{
    int f1 = top[l];
    int f2 = top[r];
    int tt = -100000000;
    while(f1 != f2)
    {
        if(dep[f1] < dep[f2])
        {
            swap(f1,f2);
            swap(l,r);
        }
        tt = max(query(1,p[f1],p[l]),tt);
        l = far[f1];
        f1 = top[l];
    }
    if(l == r)
        return tt;
    if(dep[l] > dep[r]) swap(l,r);
    return max(tt,query(1,p[son[l]],p[r]));
}

void change(int l,int r)
{
    int f1 = top[l];
    int f2 = top[r];
    while(f1 != f2)
    {
        if(dep[f1] < dep[f2])
        {
            swap(f1,f2);
            swap(l,r);
        }
        negat(1,p[f1],p[l]);
        l = far[f1];
        f1 = top[l];
    }
    if(l == r) return ;
    if(dep[l] > dep[r]) swap(l,r);
    negat(1,p[son[l]],p[r]);
}

void ini()
{
    tot = 0;
    pos = 1;
    memset(head,-1,sizeof(head));
    memset(son,-1,sizeof(son));
}

int me[maxn][2];
int va[maxn];

int main()
{
    int T;
    int n;
    //freopen("in.txt","r",stdin);
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        ini();
        for(int i = 1; i < n; i++)
        {
            scanf("%d%d%d",&me[i][0],&me[i][1],&va[i]);
            addedge(me[i][0],me[i][1]);
            addedge(me[i][1],me[i][0]);
        }

        dfs(1,0,0);
        getpos(1,1);
        build(1,1,n);
        for(int i = 1; i < n; i++)
        {
            if(dep[me[i][0]] > dep[me[i][1]])
                swap(me[i][0],me[i][1]);
            update(1,p[me[i][1]],va[i]);
        }
        char ch[10];
        while(scanf("%s",ch) == 1)
        {
            ;
            if(ch[0] == 'D') break;
            int u,v;
            scanf("%d%d",&u,&v);
            if(ch[0] == 'Q')
                printf("%d\n",fin(u,v));
            else if(ch[0] == 'N')
                change(u,v);
            else
                update(1,p[me[u][1]],v);
        }
    }
    return 0;
}





Unlocking Decoding-time Controllability: Gradient-FreeMulti-Objective Alignment with Contrastive Pr 将基于庞大网络语料库训练的大型语言模型(LLMs)(OpenAI,2023;Touvron 等,2023;Google,2023)与人类偏好对齐,是减少产生不安全(Wei 等,2023)、幻觉(Zhang 等,2023b)和有偏见(Gallegos 等,2023)内容的重要一步。随着偏好学习技术(如 PPO(Schulman 等,2017)、DPO(Rafailov 等,2023)及其他变体(Azar 等,2023;Ethayarajh 等,2024; 阅读详情

相关推荐

用deepseek对GPU服务器进行压力测试

利用 DeepSeek 模型对 GPU 服务器进行压力测试,核心思路是通过,验证 GPU 服务器在计算、显存、网络等维度的承载能力,同时观察稳定性与性能瓶颈。

weixin_42795092的博客 1618

树链剖分详解

顾名思义,树链剖分就是将整棵树剖分为若干条链,使它组合成一个线性结构,然后用其他的数据结构维护树上的信息。 **重链剖分** 可以将树上的任意一条路径划分成不超过 $O(\log n)$ 条连续的链,保证划分出的每条链上的节点 **DFS 序** 连续,因此可以方便地使用 **线段树** 之类的数据结构来维护树上的信息。

fk__boy的博客 463

AD936x Evaluation Software 详细配置

作者:ShownSun 工作室:时沿科技 文章目录AD936x Evaluation Software详细配置1 系统概述2 AD9361 Wireless Transceiver Evaluation Setup2.1 标签描述2.2 用户参数2.3详细配置3 AD936x RF Wizard3.1 标签描述3.2 用户参数3.3 详细配置4 AD936x Digital Filter Wizard4.1 标签描述4.1.1 时钟配置4.1.2 滤波器配置4.1.3 接收滤波器配置4.1.4 发射滤..

ShownSun博客 5211

边权化点权的树链剖分

Tree 其实不难想,需要边权下传到,临近的深度较深的节点,边数为n−1n-1n−1,除根外点数也是n−1n-1n−1,所以可以这么做。 插入就是这么做的。 另外在修改链和查询链的时候,一定要注意最后的链,查询和修改的最后的区间是[dfn[son[x]],dfn[y]][dfn[son[x]],dfn[y]][dfn[son[x]],dfn[y]] 要注意的是这里求最大值,有取反,所以要维护最小值,因为去反后,最小变最大 别的一般的树剖一样没什么好说的。 #include <iostream>

lcl1234567890lcl的博客 190

FairyGUI编辑器自定义菜单扩展插件

本文涉及到的软件有:FairyGUI,VSCode代码环境涉及到了:LuaVSCode插件:EmmyLua在编写FairyGUI编辑器菜单前,了解一下FairyGUIEditor的API会有效的帮助我们解决很多问题。FairyGUI的扩展是通过编辑器自带的插件功能实现的,插件中我使用的是lua环境模板。导入编辑器的LuaAPI,文件可以在FairyGUI-Editor源码的插件目录中找到。接下来将通过功能来说明对应的API作用。

Aili_Xiao的博客 4506

springboot 启动方式 装配流程 自定义starter 文件加载顺序 常见设计模式

springboot 启动方式 装配流程 自定义starter 文件加载顺序 常见设计模式

sv 944

树链剖分 边权下放点权

首先,对于一条边,它有两个顶点,那么肯定是让深度较浅的点,也就是父节点的点权来作为这条边的边权。然后最后我们要查边权的时候,只要查它对应的子节点就可以了。2.树上路径更新的时候,你稍微手玩一下就会发现两个节点的lca是不应该被更新的,所以在最后一步更新的时候,我们的代码要有所改变。3.查询树上路径权值和时(如果有这个操作),同理两点的lca的点权不应该被算进去,因为它对应的边不属于这两点的路径上。同理,你也可以这么写,意思我就不解释了。其实就是把lca的更新的结果给改回去。就那么些操作,没有大意。

sophilex的博客 351

建议收藏:华为海思IC设计笔试题,含解析(附下载)

接触过的部门有麒麟芯片、CPU/GPU,总体面试感觉非常好,规范且认真,第一轮手撕代码状态机+复盘机考题+瞄准几个知识点深挖,时间1hour+;一二轮面试是连着的,所以很累。但是岗位就那么多,在面试的时候,很多同学因为准备不充分,与岗位失之交臂,无缘进入该公司。时序电路有记忆功能,不会产生锁存器,锁存器一般在组合逻辑中case写不全,else写不全,或者敏感列表写不全。

nuoweishizi的博客 3294

【例题记录】树链剖分·线段树·边权点权化

有一棵以 1 为根节点,具有 n 个节点的有根树,树上的每条边都具有边权,初始时所有边权均为 0。共有 m 次操作,每次操作将选定两个。上的所有边权值均 +1。求每次操作结束后,每条边的权值。的节点 u,v,使从 u 到 v 的。

Ctrl AC的博客 307

基于滤波反投影的图像重建算法matlab仿真

基于滤波反投影的图像重建算法是一种用于医学影像重建的计算机辅助技术。该算法可以从投影数据中重建出高质量的三维图像,被广泛应用于医学影像学、CT、PET等领域。本文将详细介绍基于滤波反投影的图像重建算法的原理、步骤和应用。一、原理介绍基于滤波反投影的图像重建算法基于X射线CT成像原理,它的主要思想是通过对投影数据进行处理,反推出被成像物体的三维形状。其核心原理是投影数据与目标物体之间的线性关系,即通过估计目标物体的吸收率来计算投影数据的变化,从而反推出目标物体的三维形状。

平时工作较为繁忙,私信消息一般晚上回复,谢谢大家~~ 390

(8)(8.19) GPIOs

Ardupilot官网关于《Copter》的翻译 —《(8.19) GPIOs》。

无人机开发(开源Ardupilot) 1万+

树链剖分基础及进阶

树链剖分和树上启发式合并一,树链剖分1,重链剖分剖分过程索引过程板子:(小清新写法)树剖应用1,边权转点3,注意事项: 一,树链剖分 思路: 把树上问题转化到线段树上维护,树上转为序列 1,重链剖分 意义:重链剖分可以将树上的任意一条路径划分成不超过O(logn)O(log n)O(logn)条连续的链,每条链上的点深度互不相同(即是自底向上的一条链,链上所有点的 LCA 为链的一个端点)(一种求lca的新方法!!) 重子节点 表示其子节点中子树最大的子结点。如果有多个子树最大的子结点,取其一;如果没有

qq_42852687的博客 722

【基础-单选】Row组件中有两个Text组件,如果使用justifyContent对齐方式,下面哪个属性可以实现左右两端对齐:

Row组件中有两个Text组件,如果使用justifyContent对齐方式,下面哪个属性可以实现左右两端对齐

江拥羡橙的博客 1309

POJ 3237 Tree /BZOJ 2157旅游 -- 树链剖分边权处理+取反

类似SPOJ QTREE模板题,还是要注意跳过LCA!!!(因为用最深的点权维护边权,LCA其实是上一个点的边权,不管update还是query) 只不过多了个取相反数操作 关于区间取相反数,如果是维护区间和,就加个负号;但如果是维护最大值,应该最大值最小值互换。 注释部分,表示按位取反如何维护最值(与本题无关) ①POJ 3237 Tree #include <stdio...

zjyang12345的博客 282

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

POJ 3237(树链剖分)

这道题算是树链剖分的模板题吧(其实也是我过的第一道树链剖分的题目)。历尽千辛万苦,终于把两百多行的代码敲出来了,ac的一瞬间还是挺爽的。 在学会了树链剖分之后,这道题不算很难的了,主要是在区间取反的部分注意一下细节。树链剖分代码挺长的,很多地方都是容易写错。我也是通过讨论区的acmer给出的数据找出一些错误的地方。 #include #include #include #include

84970000的专栏 485

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

poj 3237 树链剖分模板(用到线段树lazy操作)

/* 本体在spoj375的基础上加了一些操作,用到线段树的lazy操作模板类型 */ #include #include #include #include #include #include #include using namespace std; #define N 11000 #define inf 0x3fffffff int head[N]; int son[N];//记录与当前点

晴朗的博客 572

深度学习工具包 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")

【POJ3237】Tree(树链剖分)

纵然相思入骨,纵然万劫不复。我也只愿你眉眼如初,风华如故。

zyf2000 581

[点分治] 模板 POJ - 3237 Tree | CF161D Distance in Tree

首先理解模板 一.概念 ​ 是处理树上路径的一个极好的方法。如果你需要大规模的处理一些树上路径的问题时,点分治是一个离线的方法 一般而言 对于一棵树 我们能选取一个点 将其分割为几个棵子树 如果想要dfs每次进行的少 我们最好就要找到数得重心 这样深度就变为了 log2(n) int siz[maxn],SIZ,dp[maxn],root; // 这里部分是之后用的 bool use[maxn]...

蒟蒻的最后的倔强 297

BZOJ、HDU、POJ等评测平台的部分题目梳理

题目

Hawo11的博客 1151

3月15日

这几天主要是a dp的题与思维的题,并看了几道树链剖分的题,树链剖分基础题是求lca与维护,看了poj 2763 Housewife Wind与poj 3237 Tree,几乎就是裸的树链剖分,然后是SPOJ QTREE - Query on a tree,给你一颗树,现在有两个操作,一种是改变某条边的权值,一种是查询点u到v之间的路径的最大边权。也是树剖的裸题。还有是BZOJ 2243: [SD...

qq_37808579的博客 201

POJ - 3237 Tree (树链剖分+线段树+区间修改)

Tree Description You are given a tree with N nodes. The tree’s nodes are numbered 1 through N and its edges are numbered 1 through N − 1. Each edge is associated with a weight. Then you are to e

LP_Cong 737

树链剖分(边权)

#include&lt;bits/stdc++.h&gt; #define MAX 123466 #define ll long long using namespace std; struct Front_Link_Star{ int next,to; }edge[MAX&lt;&lt;1]; ll Ma,Mi; ll tree[MAX &lt;&lt; 2],lazy[MAX &l...

gebixiaofang的博客 483

树链剖分——边权poj2763

边权操作起来也和点权一样,只要把边的权值映射到点上即可,要注意的地方是向上爬的过程中和点权不太一样,还有个特判(WA了几次。。) 完整代码 #include<cstring> #include<cstdio> #include<iostream> using namespace std; #define maxn 100005 struct...

weixin_30369041的博客 192

【数据结构】trie树

一个处理字符串查找 和xort问题的常用工具 1>最长异或路径 给定一棵n个点的带权树,结点下标从1开始到N。寻找树中找两个结点,求最长的异或路径。 异或路径指的是指两个结点之间唯一路径上的所有边权的异或。 1≤n≤100000 0≤w<2^31 题意:一颗最小生成树,带边权求 所有路径中,边权异或后得到的值,最大是多少 1)最小生成树,那就先拎出来一个顶...

dimei7686的博客 157

【树链剖分】【边权】

QTREE - Query on a treeno tags You are given a tree (an acyclic undirected connected graph) with N nodes, and edges numbered 1, 2, 3…N-1.We will ask you to perfrom some instructions of the following

Vampire 1813

POJ 3237 Tree (树链剖分+线段树)

题意: http://poj.org/problem?id=3237 给一棵树,操作三种  CHANGE i v Change the weight of the ith edge to v NEGATE a b Negate the weight of every edge on the path from a to b QUERY 

缺氧 704
上一篇: poj 2019 二维RMQ
下一篇: SPOJ DQUERY树状数组离线or主席树
Tyuio28
博客等级 码龄11年 12粉丝 279原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值