【POJ3237】【树链剖分】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 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

Source

【分析】
好久没写了。
写一道练练手。
  1 /*
  2 宋代苏轼
  3 《南乡子·重九涵辉楼呈徐君猷》
  4 霜降水痕收。浅碧鳞鳞露远洲。酒力渐消风力软,飕飕。破帽多情却恋头。
  5 佳节若为酬。但把清尊断送秋。万事到头都是梦,休休。明日黄花蝶也愁。
  6 */
  7 #include <iostream>
  8 #include <cstdio>
  9 #include <algorithm>
 10 #include <cstring>
 11 #include <vector>
 12 #include <utility>
 13 #include <iomanip>
 14 #include <string>
 15 #include <cmath>
 16 #include <queue>
 17 #include <assert.h>
 18 #include <map>
 19 #include <ctime>
 20 #include <cstdlib>
 21 #include <stack>
 22 #define LOCAL
 23 const int INF = 0x3f3f3f3f;
 24 const int maxn=100000 + 10;
 25 const int maxnode = 100000;
 26 const int maxm=100000 * 2 + 10;
 27 using namespace std;
 28 struct Node{//权值线段树 
 29        int l, r;
 30        int Max, Min;
 31        bool neg;//取反标记 
 32 }tree[maxn * 4];
 33 struct Edge{
 34        int u, v, w;
 35 }edges[maxn];//输入的边 
 36 
 37 int n, fa[maxn], size[maxn];
 38 int son[maxn], dep[maxn], top[maxn];
 39 int pos[maxn], Time;
 40 int M, head[maxn], next[maxm], to[maxm], w[maxm];
 41 
 42 //第一次dfs 
 43 void dfs_1(int u){
 44      size[u] = 1;
 45      son[u] = 0;
 46      for (int i = head[u]; i != -1; i = next[i]){
 47          int v = to[i];
 48          if (v == fa[u]) continue;
 49          dep[v] = dep[u] + 1;
 50          fa[v] = u;
 51          dfs_1(v);
 52          size[u] += size[v];
 53          if (size[v] > size[son[u]]) son[u] = v;
 54      }
 55      return;
 56 }
 57 void dfs_2(int u, int top_node){
 58      top[u] = top_node;
 59      pos[u] = ++Time;//给他和他的父亲的边在线段树中的位置 
 60      //重边
 61      if (son[u]) dfs_2(son[u], top_node); 
 62      //轻边 
 63      for (int i = head[u]; i != -1; i = next[i]){
 64          int v = to[i];
 65          if (v == fa[u] || v == son[u]) continue;
 66          dfs_2(v, v);
 67      }
 68 }
 69 //建树 
 70 void build(int x, int l, int r){
 71      tree[x].l = l;tree[x].r = r;
 72      tree[x].Max = -INF;
 73      tree[x].Min = INF;
 74      tree[x].neg = 0;
 75      if (l == r) return;
 76      
 77      int mid = (l + r) >> 1;
 78      build(x << 1, l, mid);
 79      build((x << 1) | 1, mid + 1, r);
 80 }
 81 void update(int x){
 82      tree[x].Max = max(tree[x << 1].Max, tree[(x << 1) | 1].Max);
 83      tree[x].Min = min(tree[x << 1].Min, tree[(x << 1) | 1].Min);
 84      return;
 85 }
 86 //标记下传 
 87 void pushdown(int x){
 88      if (tree[x].l == tree[x].r) return;
 89      
 90      if (tree[x].neg){
 91         int l = (x << 1), r = l | 1;
 92         tree[l].neg ^= 1;
 93         tree[l].Min *= -1;
 94         tree[l].Max *= -1;
 95         swap(tree[l].Min, tree[l].Max);
 96         
 97         tree[r].neg ^= 1;
 98         tree[r].Min *= -1;
 99         tree[r].Max *= -1;
100         swap(tree[r].Min, tree[r].Max);
101         
102         tree[x].neg = 0;
103      }
104 }
105 //在线段树中修改l,r为val 
106 void change2(int x, int l, int r, int val){
107      pushdown(x);
108      if (tree[x].l == l && tree[x].r == r){
109         if (val == INF){//取反操作,注意已经pushdown过了 
110            tree[x].neg = 1;
111            tree[x].Min *= -1;
112            tree[x].Max *= -1;
113            swap(tree[x].Min, tree[x].Max);
114         } else tree[x].Min = tree[x].Max = val;//更新val 
115         return;
116      }
117      
118      int mid = (tree[x].l + tree[x].r) >> 1;
119      if (r <= mid) change2(x << 1, l, r, val);
120      else if (l > mid) change2((x << 1) | 1, l, r, val);
121      else{
122           change2(x << 1, l, mid, val);
123           change2((x << 1) | 1, mid + 1, r, val);
124      }
125      update(x);
126 }
127 int query2(int x, int l, int r){
128      pushdown(x);
129      if (tree[x].l == l && tree[x].r == r) return tree[x].Max;
130      
131      int mid = (tree[x].l + tree[x].r) >> 1; 
132      if (r <= mid) return query2(x << 1, l, r);
133      else if (l > mid) return query2((x << 1) | 1, l, r);
134      else return max(query2((x << 1), l, mid), query2((x << 1) | 1, mid + 1, r));
135 }
136 //树链剖分部分 
137 void change(int x, int y, int v){
138      while (top[x] != top[y]){
139            //总是矮的往上爬.. 
140            //保证dep[top[x]] >= dep[top[y]] 
141            if (dep[top[x]] < dep[top[y]]) swap(x, y);
142            
143            change2(1, pos[top[x]], pos[x], v);
144            x = fa[top[x]];
145      }
146      
147      if (x == y) return;
148      if (dep[x] > dep[y]) swap(x, y);
149      change2(1, pos[son[x]], pos[y], v);
150 }
151 int query(int x, int y){
152     int Ans = -INF;
153     while (top[x] != top[y]){
154           if (dep[top[x]] < dep[top[y]]) swap(x, y);
155           
156           Ans = max(Ans, query2(1, pos[top[x]], pos[x]));
157           x = fa[top[x]];
158     }
159     if (x == y) return Ans;
160     if (dep[x] > dep[y]) swap(x, y);
161     Ans = max(Ans, query2(1, pos[son[x]], pos[y]));
162     return Ans == -INF ? 0 : Ans;
163 }
164 void work(){
165     while(1){
166         char str[20];
167         scanf("%s", str);
168         if(str[0] == 'C'){
169             int x, v;
170             scanf("%d%d", &x, &v);
171             change2(1, pos[edges[x].v], pos[edges[x].v], v);
172         }else if(str[0] == 'N'){
173             int l, r;
174             scanf("%d%d", &l, &r);
175             change(l, r, INF);
176         }else if(str[0] == 'Q'){//询问两点之间最大值 
177             int l, r;
178             scanf("%d%d", &l, &r);
179             printf("%d\n", query(l, r));
180         }else break;
181     }
182 }
183 //加边 
184 void addEdge(int u, int v, int c){
185      to[M] = v;
186      w[M] = c;
187      next[M] = head[u];
188      head[u] = M++;
189 }
190 void init(){
191      memset(head, -1, sizeof(head));//邻接表初始化
192      memset(dep, 0, sizeof(dep));
193      M = Time = 0;//总边数和时间 
194      fa[1] = size[0] = 0;
195      //加边 
196      scanf("%d", &n);
197      for (int i = 1; i < n; i++){
198          scanf("%d%d%d", &edges[i].u, &edges[i].v, &edges[i].w);
199          addEdge(edges[i].u, edges[i].v, edges[i].w);
200          addEdge(edges[i].v, edges[i].u, edges[i].w);
201      }
202      dfs_1(1);
203      dfs_2(1, 1);
204      build(1, 1, Time);
205      for (int i = 1; i < n; i++){
206          int x = edges[i].u, y = edges[i].v;
207          //判断父亲 
208          if (dep[x] > dep[y]) swap(edges[i].u, edges[i].v);
209          //u一定是父亲 
210          change2(1, pos[edges[i].v], pos[edges[i].v], edges[i].w);
211     }
212 }
213 
214 int main(){
215     int T;
216     
217     scanf("%d", &T);
218     while (T--){
219           init();
220           work();
221     }
222     //printf("%d\n", INF); 
223     return 0;
224 }
View Code

 

转载于:https://www.cnblogs.com/hoskey/p/4341075.html

WPS JS宏智能识别代码段并设置样式(完整可用版) 之前,我们已经经历了多次迭代,解决了许多问题,比如识别代码块、处理多行导入、调整样式等。现在他们需要一份全面的文档来解释整个代码的结构和工作原理。(5)智能行分析(含URL和注解检测优化)function analyzeLineEnhanced(rawText,trimmedText,codeSymbols,codePatterns, singleLinePatterns)该解决方案在保持高性能的同时,提供了良好的可扩展性,能够适应不同组织的代码规范需求,是WPS生态中专业文档处理的创新实践。 阅读详情

相关推荐

DolphinScheduler工作流中ChunJun任务保存失败的深度解析与实战修复

本文深度解析了在DolphinScheduler工作流中创建ChunJun任务时遭遇“parameter invalid”保存失败的普遍问题。其根源在于前端表单的`customConfig`参数默认值与后端校验逻辑不匹配。文章提供了两种实战修复方案:一是修改前端源码并重新编译,二是热更新已部署的JS文件,并对比了其适用场景与风险,帮助用户彻底解决此集成障碍。

weixin_29010003的博客 395

poj 3237 Tree(树链剖分)

题目链接:poj 3237 Tree 题目大意:给定一棵树,三种操作: CHANGE i v:将i节点权值变为vNEGATE a b:将ab路径上所有节点的权值变为相反数QUERY a b:查询ab路径上节点权值的最大值。 解题思路:树链剖分,然后用线段树维护节点权值,成端更新查询。 #include #include #include using namespace

不慌不忙、不急不躁 1434

手把手教你设计2bit反射型超表面:从单patch扫参到pin管配置全流程

本文提供了一份2bit反射型超表面设计的完整工程实践指南。从单贴片谐振器的参数化扫描与“270度法则”应用,到PIN二极管等效电路模型的获取与集成,再到利用参数化扫描高效仿真四种工作状态,手把手指导读者完成从单元设计到阵列布局、偏置线集成及加工考量的全流程,旨在帮助射频工程师将概念转化为可加工测试的实体模型。

java5的博客 1019

【POJ3237】Tree 树链剖分

题意: change,把第i条边权值改成v negate,把a到b路径上所有权值取相反数(*(-1)) query,询问a到b路径上所有权值的最大值 树链剖分。 以前一直不会,但是我恶补LCT了,所以先学一下。 对于现在的水平来说,树剖太水了,自己翻资料吧,我只提供一个还算不错的代码。 扒代码的时候可以用我的这个。 附rand和pai。 代码: #inc

辗转山河弋流歌 1186

基于MATLAB Simulink的电动汽车整车控制仿真

在本文中,我们选择了power_ElectricVehicle示例模型,该模型已经包含了电动汽车的基本组成部分,包括电机、变速器、驱动轮、电池等。例如,使用PID控制器来控制电机的转速,使用ABS控制器来控制车轮的制动力,使用转向控制器来控制车辆的转向角度,使用悬挂控制器来控制车轮的姿态等。通过建立模型和实现控制器,我们可以比较直观地了解电动汽车的工作原理和性能特点,并验证设计的控制系统在不同工况下的效果。而在电动汽车的开发中,整车控制系统是至关重要的一个组成部分,直接影响着电动汽车的性能和性价比。

qq_39605374的博客 1800

YOLOv11改进有效涨点专栏目录 | 含卷积、主干、注意力机制、Neck、检测头、损失函数、二次创新C2PSA/C3k2等各种网络结构改进

Hello,各位读者们好.本文为最新YOLOv11有效涨点专栏目录,YOLOv11以及发布了一个月左右,这个过程中我也是给大家整理了许多的机制,其中包含了C3k2、主干(均支持根据yolov11训练的版本进行二次缩放,全系列都能轻量化)、检测头、注意力机制、Neck多种结构上创新,也有损失函数和一些细节点上的创新。

Snu77的博客 8万+

POJ3237 Tree 树链剖分 边权

POJ3237 Tree 树链剖分 边权 传送门:http://poj.org/problem?id=3237 题意: n个点的,n-1条边 修改单边边权 将a->b的边权取反 查询a->b边权最大值 题解: 修改边权就查询点的深度大的点,用大的点去存这条边的边权,其余的就和点权的是一样的了 取反操作用线段树维护,区间最大值取反就是区间最小值,区间最小值取反就是区间最大值 所以维护两颗...

weixin_30570101的博客 184

ESP32-CAM 赋能 AI 视觉巡检小车:自主避障与目标追踪实现全解析

本文基于 ESP32-CAM 实现了低成本 AI 视觉巡检小车的核心功能,硬件成本<100 元,兼顾自主避障与目标追踪。算法升级:移植 YOLOv5nano 量化模型(INT8),提升目标检测精度(如识别巡检场景中的 “异常物体”“人员”);无线拓展:通过 MQTT 协议将巡检图像、距离数据上传到阿里云 / 腾讯云,实现远程监控;多传感器融合:增加温湿度(DHT11)、红外测温(MLX90614)模块,扩展巡检维度;路径规划:结合 SLAM 算法,实现自主建图与路径巡检。

weixin_42300449的博客 367

poj 3237 Tree 树链剖分

// poj 3237 Tree 树链剖分 // // 解题思路: // // 树链剖分,维护一个最大值和一个最小值, // 区间更新,laz标记.单点更新,去掉叶子节点的laz // 标记.边权改为离根节点较远的点的点权.求lca // 的方式进行区间更新.注意线段树的操作以及push_up() // push_down()的操作.写了很久,感悟颇多,继续加油吧~~~ #include

TIMELIMITE的专栏 541

【Bug已解决】claude: command not found 解决方案

方案适用场景推荐指数添加 PATH全局 bin 目录确实存在但未加入 PATH⭐⭐⭐⭐⭐nvm 重新安装多 Node 版本切换导致失效⭐⭐⭐⭐⭐Windows 环境变量检查Windows 平台专用⭐⭐⭐⭐原生安装脚本想彻底避开 npm PATH 问题⭐⭐⭐⭐清理多重 Node 安装系统里有多套 Node 管理方式冲突⭐⭐⭐报错的核心是npm 全局安装的可执行文件路径没有正确出现在系统的 PATH 环境变量里,而不是安装本身失败了。

一键难忘的博客 1万+

高通平台N4单路输入的720P相机预览

N4的一路720P Camera作为MIPI摄像头使用

llw21680的专栏 165

poj3237 Tree 树链剖分

http://poj.org/problem?id=3237

438

【100分】【等和子数组最小和】

逆序排序,这样能够使得在分组时优先选取较大的元素,以便将元素分配到较小的子集中,从而使得每个子集的和相对均衡。给定一个数组nums,将元素分为若干个组,使得每组和相等,求出满足条件的所有分组中,组内元素和的最小值。分成若干个组,使得每组的和相等,并求出满足条件的所有分组中,组内元素和的最小值。在递归的过程中,我们需要注意一个优化点,即避免将相同和的桶重复计算。4 个子集(5),(1,4),(2,3),(2,3)2 个子集(5, 1, 4),(2,3, 2,3)个子集,则返回子集和的最小值,如果不能,则将。

weixin_54707168的博客 1167

Tree POJ - 3237 (树链剖分)

题目 https://cn.vjudge.net/problem/POJ-3237 难点是线段树 #include &lt;iostream&gt; #include &lt;algorithm&gt; #include &lt;cstdio&gt; #include &lt;cstdlib&gt; #include &lt;cstring&gt; using namespace std;...

七九河开的博客 230

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

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

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

POJ 3237 Tree 树链剖分

树链剖分基础题 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 10010; struct edge { int v, next; }e[maxn*2]; int first[maxn], cn...

diandingyin9417的博客 87

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

poj 3237 Tree 题解(树链剖分,线段树)

原题链接: poj 题意简述 多组数据。给定一个树,带边权,要支持三种操作,分别是: 两个节点之间的路径的边权全部×−1\times -1×−1,即取相反数 单边修改边权值 求两个节点之间路径上的最长边 数据 输入 第一行一个ttt,表示有ttt组数据。对于每一个数据,先有一个nnn,表示点数。然后n−1n-1n−1行,每行两个数a,b,ca,b,ca,b,c表示a,ba,ba,b之间有一个边...

LightningUZ的博客 287

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

POJ 3237 Tree (树链剖分)

题目地址:POJ 3237 这题用了一下午。。本来一直认为max和min两个数组是不用改的,只需要改lazy数组,然后在查询的时候利用lazy标记来返回max或-min,后来发现错的很严重。。 这题要在pushdown中修改max和min数组,从而实现最大值取反。 代码如下:#include <iostream> #include <string.h>

scf0920 1153

「POJ3237」Tree【树链剖分+线段树】

题目链接:http://poj.org/problem?id=3237 Tree Time Limit: 5000MS Memory Limit: 131072K Description You are given a tree with NNN nodes. The tree’s nodes are numbered 111 through NNN and its edges are numbe...

wzw 234

POJ 3237 Tree (树链剖分)

树链剖分

Muti-Agent 2594

树链剖分+线段树 poj3237 Tree

传送门:点击打开链接 题意:3种操作,1单点更新,2路径正负反转,3路径查询最大值 思路:线段树维护最大值和最小值和一个懒惰标记,然后在线段树的基础上用树链剖分维护 #include #include #include #include #include #include #include #include #include #include #include #include #inclu

qwb的博客 856

SPOJ 375 QTREE POJ 3237 TREE 树链剖分

http://wenku.baidu.com/view/8861df38376baf1ffc4fada8 先上一往篇论文,我总觉得论文说的不够详细,但是可以理解好多东西。 首先,树链剖分就是把树拆成一系列链,然后用数据结构对链进行维护。 通常的剖分方法是轻重链剖分,所谓轻重链就是对于节点u的所有子结点v,size[v]最大的v与u的边是重边,其它边是轻边,其中size[v]是以v为根的子树的

Senbonzakura 1371

【POJ】3237 Tree 树链剖分

传送门:【POJ】3237 Tree

poursoul 764

【POJ3237】Tree(树链剖分)

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

zyf2000 580
上一篇: 【转】对无旋转操作的平衡树的一些探究
下一篇: 【BZOJ1036】【树链剖分】树的统计Count
Gregory99174
博客等级 码龄10年 2粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值