HDU 6582 Path——————2019多校第一场,最短路+最大流

(一)利用Python实现数据集读取,Python基本文件操作介绍 机器学习是计算机对大量数据的分析过程,在机器学习的实际项目中,通常都需要准备数据集,数据集通常包含的数据数量是庞大的。例如,在处理计算机视觉领域的项目时,每一张图片都是一个单独的文件,为了提高模型训练的效果,图片数量通常会比较多,因此需要合理且高效的操作将所有的图片数据读取。本篇旨在介绍如何用Python对海量文件进行遍历,也是机器学习实践的第一步。......... 阅读详情

Path

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1831 Accepted Submission(s): 496

Problem Description
Years later, Jerry fell in love with a girl, and he often walks for a long time to pay visits to her. But, because he spends too much time with his girlfriend, Tom feels neglected and wants to prevent him from visiting her.
After doing some research on the neighbourhood, Tom found that the neighbourhood consists of exactly n houses, and some of them are connected with directed road. To visit his girlfriend, Jerry needs to start from his house indexed 1 and go along the shortest path to hers, indexed n.
Now Tom wants to block some of the roads so that Jerry has to walk longer to reach his girl’s home, and he found that the cost of blocking a road equals to its length. Now he wants to know the minimum total cost to make Jerry walk longer.
Note, if Jerry can’t reach his girl’s house in the very beginning, the answer is obviously zero. And you don’t need to guarantee that there still exists a way from Jerry’s house to his girl’s after blocking some edges.

Input
The input begins with a line containing one integer T(1≤T≤10), the number of test cases.
Each test case starts with a line containing two numbers n,m(1≤n,m≤10000), the number of houses and the number of one-way roads in the neighbourhood.
m lines follow, each of which consists of three integers x,y,c(1≤x,y≤n,1≤c≤109), denoting that there exists a one-way road from the house indexed x to y of length c.

Output
Print T lines, each line containing a integer, the answer.

Sample Input
1
3 4
1 2 1
2 3 1
1 3 2
1 3 3

Sample Output
3


两遍 d i j k s t r a dijkstra dijkstra算法建一个最短路的图,然后求一下最大流

链式前向星存图

//#include<bits/stdc++.h>
#include<cstdio>
#include<iostream>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<bitset>
#include<set>
#include<vector>


using namespace std;
typedef long long ll;
typedef pair<int ,int> P;

const int INF  = 0x3f3f3f3f;
const int MAXN = 2e4+7;
int t,n,m;

struct Edge{
        int nxt, to;
        ll w;
}e[10010], f[10010];
int cnt = 1, head[MAXN], fcnt = 1,fhead[MAXN];

void add(int u, int v, int w){//建立图和反向图
        e[cnt] = {head[u], v, w};
        head[u] = cnt++;
        f[fcnt] = {fhead[v], u,w};
        fhead[v] = fcnt++;
}

ll dis[MAXN], fdis[MAXN];
bool vis[MAXN];

struct DijkHeap{
        int u;
        ll d;
        bool operator < (const DijkHeap &a)const{
                return d > a.d;
        }
}dijktemp;

void dijkstra(){
        // cout<<"********"<<endl;
        priority_queue<DijkHeap> q;
        memset(dis, 0x7f, sizeof(ll)*(n+2));
        memset(vis, 0, sizeof(bool)*(n+2));
        dis[1] = 0;
        q.push({1,0});
        while(!q.empty()){
                dijktemp = q.top(); q.pop();
                int u = dijktemp.u;
                ll d  = dijktemp.d;
                vis[u] = 1;
                for(int i=head[u]; i; i=e[i].nxt){
                        int v = e[i].to;
                        if(vis[v])      continue;
                        if(dis[v]>d+e[i].w){
                                dis[v] = d+e[i].w;
                                q.push({v,dis[v]});
                        }
                }
        }
        // for(int i=1;i<=n;++i)
        // cout<<i<<":"<<dis[i]<<endl;
        // cout<<"***"<<n<<endl;
        memset(fdis, 0x7f, sizeof(fdis));
        memset(vis, 0, sizeof(vis));
        fdis[n] = 0;
        q.push({n, 0});
        while(!q.empty()){
                dijktemp = q.top(); q.pop();
                int u = dijktemp.u;
                ll  d = dijktemp.d;
                vis[u] = 1;
                for(int i = fhead[u]; i; i = f[i].nxt){
                        int v = f[i].to;
                        if(vis[v])      continue;
                        if(fdis[v] > f[i].w + d){
                                fdis[v] = f[i].w + d;
                                q.push({v, fdis[v]});
                         }
                }
        }
        // for(int i=1;i<=n;++i)
        //         cout<<i<<":"<<fdis[i]<<endl;
}

struct WEdge{
        int nxt, to;
        ll flow;
}we[2*MAXN];

int whead[MAXN] = {0}, wcnt = 2;

void wadd(int u, int v, long long f){
        we[wcnt] = {whead[u], v, f};
        whead[u] = wcnt++;
        we[wcnt] = {whead[v], u, 0};
        whead[v] = wcnt++;
}

int dep[MAXN] = {0};

bool bfs(){
        memset(dep, 0, sizeof(int)*(n+2));
        queue<int>q;
        dep[1] = 1;
        q.push(1);
        while(!q.empty()){
                int u = q.front(); q.pop();
                for(int i = whead[u]; i; i = we[i].nxt){
                        ll v = we[i].to;
                        if(!dep[v] && we[i].flow){
                                dep[v] = dep[u] + 1;//分层图
                                q.push(v);
                        }
                }

        }
        return dep[n] != 0;
}

long long dfs(int u, ll fflow){
        if(u == n || fflow == 0ll)       return fflow;
        ll sum = 0;
        for(int i = whead[u]; i; i = we[i].nxt){
                int v = we[i].to;
                if(dep[v] == dep[u] + 1 && we[i].flow){
                        ll delta = dfs(v, min(fflow - sum, we[i].flow));
                        sum += delta;
                        we[i].flow -= delta;
                        we[i^1].flow += delta;
                        if(fflow<=sum)  break;
                }
        }
        if(!sum)        dep[u] = -1;
        return sum;
}

long long dinic(){
        ll ans = 0;
        while(bfs()){
                while(ll temp = dfs(1, 0x3f3f3f3f3f3f3f3f))
                        ans += temp;
        }
        return ans;
}

void init(){
        cnt = fcnt = 1;
        wcnt = 2;
        memset(head, 0, sizeof(int)*(n+2));
        memset(fhead, 0, sizeof(int)*(n+2));
        memset(whead, 0, sizeof(int)*(n+2));
}


int main(){
        // freopen("../in.txt","r",stdin);
        // freopen("../out.txt","w",stdout);
        scanf("%d",&t);
        while(t--){
                init();
                scanf("%d %d",&n,&m);

                for(int i=0;i<m;++i){
                        int x,y,z;
                        scanf("%d %d %d",&x,&y,&z);
                        add(x,y,(ll)z);
                }
                dijkstra();
                for(int u=1;u<=n;++u){
                        for(int i=head[u]; i; i=e[i].nxt){
                                int v = e[i].to;
                                if(dis[u] + e[i].w + fdis[v]==dis[n]){
                                        wadd(u, v, e[i].w);
                                        // printf("***%d   %d   %lld\n", u, v, e[i].w);
                                }
                        }
                }
                printf("%lld\n",dinic());
        }


        return 0;
}

然后,我自个又用vector存的图,根据原来的思路又写了一边
G是原图
rG是原图的反图
wG是最短路构成的图

//#include<bits/stdc++.h>
#include<cstdio>
#include<iostream>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<bitset>
#include<set>
#include<vector>


using namespace std;
typedef long long ll;
typedef pair<ll ,ll> P;

const ll INF  = 0x3f3f3f3f3f3f3f3f;
const ll MAXN = 2e5+7;

ll n,m,t;
struct edge{
        ll to,cost;
};
ll dis[MAXN], rdis[MAXN];
vector<edge>  G[MAXN];
vector<edge> rG[MAXN];

ll Min(ll x, ll y)
{
        return x>y?y:x;
}

void dijkstra(){
        priority_queue<P, vector<P>, greater<P> > que;
        que.push(P(0,1));
        memset(dis,0x3f,sizeof(ll)*(n+2));
        dis[1] = 0LL;
        // cout<<dis[1]<<" ";

        while(!que.empty()){
                P p = que.top(); que.pop();
                ll v = p.second;
                if(dis[v] < p.first)    continue;
                for(ll i = 0; i < (ll)G[v].size(); ++i){
                        edge e = G[v][i];
                        if(dis[e.to] > dis[v] + e.cost){
                                dis[e.to] = dis[v] + e.cost;
                                que.push(P(dis[e.to], e.to));

                        }
                }

        }
        // cout<<dis[1]<<" ";
        // cout<<dis[n]<<endl;
        que.push(P(0,n));
        memset(rdis,0x3f,sizeof(ll)*(n+2));
        rdis[n] = 0LL;

        while(!que.empty()){
                P p = que.top(); que.pop();
                ll v = p.second;
                if(rdis[v] < p.first)    continue;
                for(ll i = 0; i < (ll)rG[v].size(); ++i){
                        edge e = rG[v][i];
                        if(rdis[e.to] > rdis[v] + e.cost){
                                rdis[e.to] = rdis[v] + e.cost;
                                que.push(P(rdis[e.to], e.to));
                                // cout<<e.to<<" "<<dis[e.to]<<endl;
                        }
                }
        }
        // cout<<rdis[n]<<endl;
}

struct wedge{ll to, cap, rev;};

vector<wedge> wG[MAXN];
ll level[MAXN];
ll  iter[MAXN];

void add_edge(ll from, ll to, ll cap){
        wG[from].push_back((wedge){to, cap, (ll) wG[to].size()});
        wG[to].push_back((wedge){from, 0, (ll) wG[from].size()-1});
        /*这里我之前把wG写成rG了,一直Wa,找了两天没找到原因,感谢尚位大佬帮我*/
}

void bfs(ll s) {
        memset(level, -1, sizeof(ll)*(n+2));
        queue<ll> que;
        level[s] = 0;
        que.push(s);
        while(!que.empty()) {
                ll v = que.front(); que.pop();
                for(ll i = 0; i < (ll)wG[v].size(); ++i) {
                        wedge &e = wG[v][i];
                        if(e.cap>0 && level[e.to]<0){
                                level[e.to] = level[v] + 1;
                                que.push(e.to);
                         }
                }
        }
}
ll dfs(ll v, ll t, ll f) {
        if(v == t)      return f;
        for(ll &i = iter[v]; i < (ll)wG[v].size(); i++) {
                wedge &e = wG[v][i];
                if(e.cap > 0 && level[v] < level[e.to]) {
                        ll d = dfs(e.to, t, Min(f, e.cap));
                        if(d > 0){
                                e.cap -= d;
                                wG[e.to][e.rev].cap += d;
                                return d;
                        }
                }

        }
        return 0;
}

ll max_flow(ll s,ll t) {
        ll flow = 0;
        for(;;){
                bfs(s);
                if(level[t] < 0)        return flow;
                memset(iter, 0, sizeof(ll)*(n+1));
                ll f;
                while((f = dfs(s, t, 0x3f3f3f3f3f3f3f3f)) > 0)
                        flow += f;
        }
}

int main(){
        // freopen("../in.txt","r",stdin);
        // freopen("../out.txt","w",stdout);
        scanf("%lld",&t);
        while(t--){
                scanf("%lld %lld",&n,&m);
                for(ll i=0;i<=n;++i)
                {
                        G[i].clear();
                        rG[i].clear();
                        wG[i].clear();
                }
                for(ll i=0, x, y, z;i<m;++i){
                        scanf("%lld %lld %lld",&x,&y,&z);
                        G[x].push_back((edge){y,z});
                        rG[y].push_back((edge){x,z});
                }
                dijkstra();
                // cout<<"n:"<<n<<" dis[n]:"<<dis[n]<<endl;
                for(ll u = 1; u <= n; ++u){
                        for(ll i = 0; i < (ll)G[u].size();++i){
                                edge e = G[u][i];
                                if(dis[u] + e.cost + rdis[e.to]==dis[n]){
                                        add_edge(u, e.to, e.cost);
                                        // printf("%lld %lld %lld\n",u,e.to, e.cost);
                                }
                        }
                }
                cout<<max_flow(1,n)<<endl;
        }


        return 0;
}
安卓15_ROM修改定制化_____修改rom的前提条件 去除各种验证 安卓设备通用 通过博文了解💝💝💝 1-------💝💝💝了解安卓设备的启动流程与核心验证机制 2-------💝💝💝了解安卓设备修改rom中的各种验证机制以及对应的去除方法 3-------💝💝💝了解avb验证与dm验证的本质区别与对应的操作方式 4-------💝💝💝修改rom前的循序步骤 避免验证机制导致的不开机 阅读详情

相关推荐

Ubuntu20.04运行Vins-fusion

因已安装ROS noetic,eigen,opencv及ceres等库,这部分环境配置就不细讲,直接下载VINS-FUSION的代码库 下载编译 cd ~/vins-fusion/src git clone https://github.com/HKUST-Aerial-Robotics/VINS-Fusion.git cd ../ catkin_make source ~/catkin_ws/devel/setup.bash 编译时会发现一堆错误,别急,无非就是环境冲突问题,一个个解决 1)首先,ROS

xiaojinger_123的博客 1万+

芯片DFT设计全解析:从扫描链到ATPG的工程实践地图

集成电路制造完成后,数以百万计的晶体管与逻辑门电路需要经受严格测试才能以合格良率进入市场。如何让难以直接观测的芯片内部节点变得可控、可观?可测试性设计(DFT)由此应运而生,它通过在芯片设计阶段嵌入扫描链、BIST、边界扫描等测试结构,配合ATPG自动测试向量生成,将内部逻辑故障映射为可判别的测试响应,从而实现高覆盖率的测试筛选。这一设计方法在提升测试效率、压缩测试时间、降低ATE存储需求方面价值显著,也是低功耗SoC与先进工艺节点下保证产品可靠性的关键环节。文章基于芯片设计工程师视角,深入解析了扫描链原理

weixin_30399155的博客 404

杭电2019多校第一场 HDU——6582 Path(最短路最大流(最短路最小割))

时间限制: 1 Sec内存限制: 128 MB 题目描述 Years later, Jerry fell in love with a girl, and he often walks for a long time to pay visits to her. But, because he spends too much time with his girlfriend, Tom ...

lgz0921的博客 854

Win11 24H2家庭版共享打印机失败?别慌,一个批处理脚本搞定所有设置

本文提供了Win11 24H2家庭版共享打印机失败的解决方案,通过一个批处理脚本自动修复所有设置问题。脚本包含安装组策略组件、修改关键注册表项等操作,帮助用户快速恢复打印机共享功能,适用于普通家庭用户。

weixin_30632089的博客 419

2025年12月11日 Coherent收发器下沉到数据中心:调研

技术可行性已基本具备。随着3nm DSP技术的成熟和Coherent-Lite等低功耗方案的推出,Coherent技术与IMDD的功耗差距在800G及以上速率节点快速缩小。特别是在1.6T及更高速率,两种技术的功耗开始趋于收敛。同时,通过系统级优化,如将DSP功能从可插拔模块转移到ASIC芯片,可实现30%以上的功耗降低。在成本方面,硅光技术的进步使得单通道硅光引擎BOM成本降至18美元,较2020年下降62%,逼近InP方案的经济临界点。光学系统机会丰富多样。

weixin_51184047的博客 1167

【最短路建边+最小割最大流】 HDU 6582 2019杭电多校第一场1005 Path

http://acm.hdu.edu.cn/showproblem.php?pid=6582 Path Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 685Accepted Submission(s): 189 Pro...

qq_41037114的博客 260

ECC椭圆曲线加解密原理详解(配图)

椭圆曲线加解密原理详解 本文主要参照:ECC椭圆曲线详解(有具体实例)[1] 前言: 椭圆曲线(ECC)加密原理跟RSA加解密原理比起来,可真是晦涩难懂。拜读了大神Kalafinaian文章“ECC椭圆曲线详解(有具体实例)”,终于看到了参透的曙光。 由于原文中有微小的瑕疵,也为了便于阅读起来更加流畅,我重新整理了一下这篇文章。 为什么使用椭圆曲线加密算法? RSA的解决分解整数问题需要亚指数...

Mark的博客 7万+

hdu 6582 19 航电多校第一场1005题 path 【最短路+最小割】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6582 /* 思路:最短路径构成的图的最小割(即最大流) 最短路径图:spaf得到 1 到所有点的单源最短路(dis),再求出 n 到所有点的单源最短路(dis1) 遍历每条路,设当前边起点为 u ,终点为 v ,圈主为 w , 如果 dis[u]+dis1[v]+w==1到n的最短路径 那么...

几许情愁的博客 227

OLED的字模提取(保姆级)---基于PCtoLCD2013

做为一个刚刚开始接触编程不久的白菜,这个OLED想做一个信息显示,可是商家给我的例程里就是88,816两种字体的格式,我的屏幕是0.91寸的8*16的字体显示上感觉特别丢丢儿小,我就想整个大的,哎,只怪直接学习习惯不好,总是学一半,绕了好大一圈,才搞好,想写一篇博客,时刻提醒踏实学习,第一次写博客,小白一枚,勿喷。。 OLED屏幕驱动程序功能 我们对Markdown编辑器进行了一些功能拓展与语法支...

qq_44886611的博客 7781

2026 AI Agent Harness Engineering 生态报告:开源工具链的现状与未来趋势

IEEE P2863-2025《通用人工智能自主代理技术架构与评估规范》于2025年11月正式发布,将AI Agent(通用人工智能自主代理)定义为:一种具备感知(Perception)、记忆(Memory)、推理(Reasoning)、规划(Planning)、行动(Action)五大核心能力闭环,能够在无显式指令覆盖全部环节的前提下,自主完成特定领域或开放领域复杂任务的智能实体。

AI 算法实战派 497

hdu-6582 Path(最短路+dinic)

链接;http://acm.hdu.edu.cn/showproblem.php?pid=6582 题意:给你一个图,要求你减去一些边使得1至n的最短路径变长。并且使得花费最小,删边花费为其长度。 思路:先求出最短路,将所有的最短路的边新建一个图,跑一个最大流就可以了。 #include <cstdio> #include <queue> #include <...

Kuguotao的博客 411

【四足机器人项目实战】四足机器人运动学、动力学模型

系列文章目录 提示:这里可以添加系列文章的所有文章的目录,目录需要自己手动添加 TODO:写完再整理 文章目录系列文章目录前言一、四足机器人实际模型的物理难点二、四足机器人运动学模型1.方法一:DH法建立运动学模型(1)运动学建模构型方法(2)运动学模型描述方法1、基于DH法四足机器人单腿运动学模型公式推导(0)DH法科普1)原理2)实现过程3)评价(1)四足机器人的建模规则、坐标系定义及实物参数确定1)标准Denavit-Hartenberg法建模规则2)单腿运动学模型坐标系定义示意图及简化模型3)

qq_35635374的博客 1万+

2019年杭电多校第一场 Path HDU - 6582 (SPFA+最小割)

题目链接:https://cn.vjudge.net/problem/HDU-6582. 题意,给你一个有向图,一个人要从1到n走一条最短的路,可是Tom想让他走的更长一点,所以需要阻断一些路 问 用最少的cost使得这个人走的更长,输出这个cost 思路:就是找到所有的最短路,然后用这个最短路建图,从1到n跑最大流(即最小割)输出结果即可 注意:数据需要long long 这题和HD...

zx93的博客 219

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

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

2019杭电暑期多校第一场E-Path/HDU 6582(最短路+最小割)

题意:给你m个边构成有向无环图(DAG),从1~n找出一条最短路,让你最少割几条边让1~n的最短路边长(此最短路非彼最短路了) 题解:可以发现该最短路是最短路图,然后在这个图上跑最小割就行了,所以就是最短路+最小割板子了 满足dis[v]==dis[u]+w就可以确定最短路了 #include <bits/stdc++.h> using namespace std; cons...

gml1999的博客 219

蓝牙模块HM-10手册

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

19杭电多校一 hdu 6582 Path 最短路建图+最大流/最小割

Path 首先用Dijsktra跑一遍,根据最短路建图,再跑一遍Dinic或者最小割 #include<bits/stdc++.h> using namespace std; #define mk make_pair typedef long long ll; const ll INF = 1e17; const int N = 2e4+100; int t; int n, m;...

Pikachu的博客 223

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

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

HDU6582 Path 最短路+最小割

网址:https://vjudge.net/problem/HDU-6582 题意: 给出一个有向无环有重边图,删除一条边的代价就是边的长度,求使得点$1$和点$n$的最短路变长或者不存在最短路的最小代价。 题解: 对于一个图两点的最短路中构成的边构成的子图,如果在这个子图中两点不连通,则在实际的图中,最短路一定变长或甚至不存在最短路。故求一次点$1$到其他点的最短路,记录所有最...

FairyTail0423的专栏 177

【2019多校第一场补题 / HDU6582】2019多校第一场E题1005Path——最短路径+网络流

题目链接 题意: T组数据,n个点和m条边组成一个有向图,边是单向边,每条边都有权值,需要你删去一些边使得1到n的最短路严格变长,删掉边的费用为边的长度,求最小花费。 思路:先跑一遍最短路求出1到其他点的最短距离,然后 倒着dfs 求出最短路的DAG的所有边,重新建图,跑最小割就行了。//套板子 #include<bits/stdc++.h> #define ll long long ...

代不在‘的博客 311

HDU - 6582 Path(最短路+最大流)

题目链接:点击查看 题目大意:给出一张 n 个点和 m 条边组成的有向图,现在问让最短路变长的最小花费是多少 题目分析:增加最短路的最小花费,我们可以将最短路上的边单独拿出来,再求一下最小割就好了,用了封装后的算法看起来非常舒服,但时间复杂度有点高。。看别人都是100ms左右跑完,我的代码是950ms划过 代码: #include<iostream> #include<cstdio> #include<string> #include<ctime&gt.

Falcon的博客 515

[HDU 6582] Path

题目描述: 给你一张图,你可以堵上一条边,代价就是这条边在长度,问你如何用最小的代价使得1->n不能走最短路! 题目分析: 首先我们正反跑两次SPFA,求出那条边在最短路上,然后把这些边扔进最大流里,跑个最小鸽就好了。 题目链接: HDU 6582 代码: #include <cstring> #include <algorithm> #include <ios...

HT008的Blog 276

2019多校第一场:Path(最小割)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6582 题意:现在有一个有向图,每个边有个边权,你需要拆除一些边使111到nnn的最短路变长并且拆除边的权值总和最小。 解题心得:首先将111到nnn的所有最短路上用到的边都找出来形成一个新的图,然后就是一个最小割。找出所有最短路径用到的边可以将111到所有点的最短路径答案找到,然后再从nnn点反过来找...

二营长的意大利炮友 266

Path HDU6582 (最短路+最小割)

题面: Years later, Jerry fell in love with a girl, and he often walks for a long time to pay visits to her. But, because he spends too much time with his girlfriend, Tom feels neglected and wants to pre...

mzip的博客 414

HDU - 6582 Path(spfa+最大流)

Years later, Jerry fell in love with a girl, and he often walks for a long time to pay visits to her. But, because he spends too much time with his girlfriend, Tom feels neglected and wants to prevent...

柳予欣的三味书屋~ 623

「hdu6582」Path【最短路+最大流】

Path Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 572 Accepted Submission(s): 130 Problem Description Years later, Jerry fell in love w...

wzw 309

[最短路,最大流最小割定理] 2019 Multi-University Training Contest 1 Path

题目:http://acm.hdu.edu.cn/showproblem.php?pid=6582 Path Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 3747Accepted Submission(s): ...

dixiangee374493的博客 432

HDU6582 Path【优先队列优化最短路 + dinic最大流 == 最小割】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6582 来源:2019 Multi-University Training Contest 1 题目大意: 给定一张有向图,可以阻碍若干条有向边,花费为边的权值,求使其最短路变得更长所需的最小花费。 解题思路: 1.因为最短路可能是多条,所以找出最短路网络,然后在最短路网络中跑最小割...

a6334167的博客 126
上一篇: HDU 6581 Vacation——————2019多校第一场,思维
下一篇: HDU 3949 XOR——————线性基
陶鸿杰
博客等级 码龄9年 93粉丝 298原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值