Codeforces Round #678 (Div. 2)A-E题解

Codeforces 题解 (不断更新,一起上分) 目录 Educational Codeforces Round 45 (Rated for Div. 2) Educational Codeforces Round 45 (Rated for Div. 2) 题目:A. Commentary Boxes题解 题目:B Micro-World 题解 题目:C Bracket Sequences Concatenation Problem 题解 题目:D Graph And Its Complement 题解 题目:E Po... 阅读详情

Codeforces Round #678 (Div. 2)A-E题解
比赛链接:https://codeforces.com/contest/1436

A题
水题,简单规律总结

题意为,给定一个长度为n的数列a[]。然后对于x取1到n,对于所有的满足x<=y<=n的y,累加a[y]/y(不取整,取确切的实数值),问能否通过改变原数列中数字的排列顺序,使得上述累加和等于m。

结合样例,自己稿纸上写一下,会发现这是个很花哨的题。对于a[i]这个数来说,每次它被计算都是a[i]/i,而它会被计算i次。所以最后的和仍然是a[i],也就是说整个数列不论怎么排列,最后的结果都是数列中所有值的累加和。
因此直接判断下整个数列的和是否等于m即可。

#include<bits/stdc++.h>
#define ll long long
#define llINF 9223372036854775807
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int32_t main()
{
    IOS;
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        ll sum=0;
        for(int i=0;i<n;i++)
        {
            ll x;
            cin>>x;
            sum+=x;
        }
        if(sum==m) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }

B题
构造

题意为给定一个整数n,要求你输出一个n×\times×n的整数矩阵,满足每一行和每一列的数加起来,都是质数。

这里的想法,当然是怎么简单怎么来。最小的质数是2和3,而且2和3值刚好相邻。我们简化我们构造的矩阵,只考虑0和1的话,对于每一行或者每一列来说,它都会经过两条对角线。因此我们只需要在两条对角线上全部放置1,其余位置放置0,即可让每一行和每一列的和加起来都为2了。
但是当n为奇数的时候,中间一行和中间一列上,两条对角线相交了,导致只有一个1,如下:
1 0 0 0 1
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1
此时我们在左侧的中间和上侧的中间补上一个1,使得中间行和中间列也变为2,左侧行和上侧列此时相加为3,仍满足条件:
1 0 1 0 1
0 1 0 1 0
1 0 1 0 0
0 1 0 1 0
1 0 0 0 1

#include<bits/stdc++.h>
#define ll long long
#define llINF 9223372036854775807
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

bool field[107][107];

int32_t main()
{
    IOS;
    int t;
    cin>>t;
    while(t--)
    {
        memset(field,0,sizeof(field));
        int n;
        cin>>n;
        for(int i=1;i<=n;i++) field[i][i]=field[i][n-i+1]=1;//两条对角线上放置1
        if(n&1) field[n/2+1][1]=field[1][n/2+1]=1;//特判n为奇数的情况,此时中间排和中间列只有一个1,在左侧中间和上测中间各加一个1即可
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++) cout<<field[i][j]<<' ';
            cout<<endl;
        }
    }
}

C题
二分算法原理,组合数

题意为给定一个二分算法的函数,用途为在一个已经从小到大有序的数列中查找某个数是否存在。现在给定数列长度n,并且该数列为1-n的全排列,查找的数值x,以及x所在的位置pos。
现在询问该数列有多少种排列方式,可以使得该二分查找函数成功在pos位置上找到x。

首先要认识到,二分算法是有一个左右区间的标记,在不断的二分区域缩小范围后,最终确定位置。对于每次二分的过程,选择左侧还是右侧,我们必然是要和正常排列时候的选择相同,才能找到目标位置。也就是说我们模拟一遍二分的过程,如果mid位置在pos左侧的话,该位置的值要比x小(注意这里要特判下mid刚好为pos的情况),如果mid位置在pos右侧的话,该位置的值要比x大。
我们记录下有low个位置必须放置比x值小的数,有high个位置必须放置比x值大的个数。
之后先特判下,比x值小的个数和比x值大的个数,是否足够满足low和high的需求。
如果能满足,再计算组合数:
比x小的数有x-1个,从中取low个,并且做一个low个位置的排列。
比x大的数由n-x个,从中取high个,并且做一个high个位置的排列。
剩余的数字有n-low-high-1个,做一个n-low-high-1个位置的排列。
上述三个乘起来,即为答案。

#include<bits/stdc++.h>
#define ll long long
#define llINF 9223372036854775807
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const ll mod=1e9+7;

ll cas[1007];//cas[i]储存i的阶乘
int n,x,pos;

void init()
{
    cas[0]=cas[1]=1;
    for(ll i=2;i<=1000;i++) cas[i]=cas[i-1]*i%mod;
}

ll qpow(ll x,ll p)//快速幂算乘法逆元
{
    ll ret=1;
    while(p)
    {
        if(p&1) ret=ret*x%mod;
        x=x*x%mod;
        p>>=1;
    }
    return ret;
}

int32_t main()
{
    IOS;
    init();
    cin>>n>>x>>pos;
    int high=0,low=0;
    int l=0,r=n;
    while(l<r)
    {
        int mid=(l+r)>>1;
        if(mid<=pos)
        {
            l=mid+1;
            if(mid!=pos) low++;//注意特判位置刚好为目标位置的情况,这个位置我们已经固定为x
        }
        else
        {
            r=mid;
            high++;
        }
    }
    if(low>=x||x+high>n) cout<<0<<endl;
    else
    {
        ll ans=cas[x-1]*qpow(cas[low]*cas[x-1-low]%mod,mod-2)%mod;//乘法逆元计算C(low,x-1)
        ans=cas[n-x]*qpow(cas[high]*cas[n-x-high]%mod,mod-2)%mod*ans%mod;//乘法逆元计算C(high,n-x)
        ans=ans*cas[low]%mod*cas[high]%mod*cas[n-high-low-1]%mod;//乘上low,high,n-low-high-1的阶乘
        cout<<ans<<endl;
    }
}

D题
树上博弈

题意为在一棵n个结点并以结点1为根节点的树上,每个节点上一开始都有一个初始的人数,现在有一个怪物出现在了根节点1上,人类和怪物交替操作。
人类先移动,怪物后移动,都只能在树上朝着更深的地方去移动,直到到达某个叶子结点无路可走,此时怪物会抓住这个叶子结点上所有的人。
现在人类和怪物都用最优策略来决策,询问最后怪物抓住了多少人。

推得最基础的一个结论还是简单的,那就是不考虑父结点的情况下,当前结点和其子树上所有的人数加起来,作为人类会选择尽可能平均得分配到各个叶子结点方向上去。
困难之处在于当前结点的人数比较少,无法实现平均分配的情况该如何是好呢?
此时怪物必然是选择人多的那个方向去了,并且我们这时候不会将当前结点的人分配到这个人多的方向去,否则就是可以平均分配的情况了,也就是说当前位置的人数不会影响该方向子树的总人数(重要)。
此时我们计算人多的那个方向子树的平均分配方案,可以得到该方向上的最优结果。
这里运用了递归的思想,但是由于给定数据是排序后的特别数据,反向for循环即可实现。

#include<bits/stdc++.h>
#define ll long long
#define llINF 9223372036854775807
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const ll maxn=2e5+7;

int p[maxn];//由于题目说了p[i]的值必定小于i,图是经过排序后给定边的,因此直接用一个一维数组即可存图
ll a[maxn];
int son[maxn];//son[i]记录结点i的子树有多少叶子结点

int32_t main()
{
    IOS;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) son[i]=1;
    for(int i=2;i<=n;i++) {cin>>p[i];son[p[i]]=0;}
    for(int i=1;i<=n;i++) cin>>a[i];
    ll ans=0;
    for(int i=n;i;i--)//反向从叶子结点"递归"回来
    {
        ans=max(ans,a[i]/son[i]+(a[i]%son[i]?1:0));//当前位置以及其子树上所有的所有人,我们按照尽可能平均的原则分配到各个叶子结点的方向上去
        //如果某一个方向的人数特别多或者特别少,当前结点的位置人数较少,会无法在当前结点上实现平均分配到各个叶子结点方向上去
        //但是此时怪物必然是选择人多的那个方向去了,并且我们这时候不会将当前结点的人分配到这个人多的方向去,否则就是可以平均分配的情况了,也就是说当前位置的人数不会影响该方向子树的总人数(重要)
        //此时我们计算人多的那个方向子树的平均分配方案,可以得到该方向上的最优结果
        //这里运用了递归的思想,但是由于给定数据是排序后的特别数据,反向for循环即可实现
        a[p[i]]+=a[i];
        son[p[i]]+=son[i];
    }
    cout<<ans<<endl;
}

E题
结论,线段树维护

题意为定义一个针对数列的MEX计算,其值为该数列中未出现的最小的整数值。现在给定一个数列a[],对于其每一个练习子序列,求取他们的MEX值,这些MEX值写在一起构成一个新的数列,询问该数列的MEX值为多少。

这里先推个前置结论,对于每一个具体的值x,我们的目标是在原数列中找到能构造MEX值为x的部分,对于这个数列中每一个x出现的位置作为隔板,隔开若干个区域,根据贪心的原则对于每一个区域我们都是选择整段。对于这一整段,我们计算其MEX值是否等于x,检测每一个区域能否出现一个可以构造MEX等于x的区域即为我们能否利用该数列构造出MEX值为x。
按照这个结论直接暴力去写的话是会tle的,在最劣情况下复杂度为n2。
这里我们需要用线段树来维护L-R这个范围的值,在当前数列中出现的最右侧下标的最小值。
我们记录每个数字出现的上一个位置pre[x],我们在线段树中,找寻区间最小值不小于pre[x]+1的区间最右侧下标,该区间的所有值,出现位置都在pre[x]后,在当前for循环位置前,也就是我们当前的这个检测区域。该区间的所有下标对应的值,都在该区域有出现,其最右侧即为该区域对应的MEX值。

#include<bits/stdc++.h>
#define ll long long
#define llINF 9223372036854775807
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const ll maxn=1e5+7;

int a[maxn];

struct Node
{
    int l,r,data;//线段树维护的是,l-r区间的值,各自在数列中出现的最右侧位置下标的最小值是多少
}node[maxn<<2];

void build(int now,int l,int r)
{
    node[now].l=l;node[now].r=r;node[now].data=0;
    if(l==r) return;
    int mid=(l+r)>>1;
    build(now<<1,l,mid);
    build(now<<1|1,mid+1,r);
}

void change(int now,int tar,int x)//更改值为tar的数字的最右侧位置下标为x
{
    if(node[now].l==node[now].r)
    {
        node[now].data=x;
        return;
    }
    int mid=(node[now].l+node[now].r)>>1;
    if(mid>=tar) change(now<<1,tar,x);
    else change(now<<1|1,tar,x);
    node[now].data=min(node[now<<1].data,node[now<<1|1].data);
}

int ask(int now,int tar)//询问下标从1开始的区间中,其维护的最右侧下标最小值不超过tar的最右侧下标为多少,实际上就是在求针对tar到主函数for循环参数i这个区间的数列,其对应的MEX值
{
    if(node[now].l==node[now].r) return node[now].l;
    if(node[now<<1].data<tar) return ask(now<<1,tar);
    else return ask(now<<1|1,tar);
}

bool flag[maxn];//记录数列a各个子序列能得到那些MEX值
int pre[maxn];//pre[i]记录数值i上次出现的下标位置,用于ask函数的区间范围确定

int32_t main()
{
    IOS;
    int n;
    cin>>n;
    build(1,1,maxn);
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++)
    {
        if(pre[a[i]]+1<i) flag[ask(1,pre[a[i]]+1)]=1;//注意这里和下一个for循环的特判区间是否为空,如果不特判的话会导致算出一个MEX值1,使得结果出错
        pre[a[i]]=i;
        change(1,a[i],i);
    }
    for(int i=1;i<maxn;i++) if(pre[i]&&pre[i]<n) flag[ask(1,pre[i]+1)]=1;//对于每个数字,其最后一次出现到数列末尾的这个区间未在上述for循环中询问
    flag[ask(1,1)]=1;//注意上述情况是不包括询问整个数列的
    for(int i=1;;i++) if(!flag[i]) {cout<<i<<endl;break;}
}
【机器人路径规划】基于改进型A*算法的机器人路径规划(Python代码实现) 本文针对传统A算法在机器人路径规划中存在的搜索效率低、路径不平滑等问题,提出了一种改进型A算法。该算法通过引入跳点搜索(JPS)技术优化子节点扩展方式,结合贝塞尔曲线或B样条曲线进行路径平滑处理,并采用动态启发式函数和自适应邻域搜索策略,显著提升了路径规划的效率和路径质量。实验结果表明,改进型A*算法在复杂环境下能有效减少搜索节点数量,缩短路径长度,提高路径平滑性,且具备动态避障能力。 阅读详情

相关推荐

基于java实现的弹幕视频网站

开发语言:Java框架:ssm技术:JSPJDK版本:JDK1.8服务器:tomcat7数据库:mysql 5.7(一定要5.7版本)数据库工具:Navicat11开发软件:eclipse/myeclipse/ideaMaven包:Maven3.3.9系统展示弹幕视频网站,在弹幕视频网站可以查看首页、视频信息、商品信息、论坛信息、我的、跳转到后台、购物车、客服等内容前台首页界面图登录,通过登录填写账号、密码等信息进行登录操作登录界面图视频信息界面图。

DC5621的博客 1333

codeforces查看题解

文章目录1. 步骤一:右键单击箭头指向位置,根据提示打开链接2. 步骤二:左键单击箭头指向位置3. 结果:红线上方是参考代码,下方是测试样例4. 补充:① 右边这个方框可以筛选想要查看代码的状态(Accepted、Wrong answer等)以及提交的语言② 下方这一栏可以按运行时间(或者内存损耗等)对代码进行排序 1. 步骤一:右键单击箭头指向位置,根据提示打开链接 2. 步骤二:左键单击箭头指向位置 3. 结果:红线上方是参考代码,下方是测试样例 4. 补充: ① 右边这个方框可以筛选想要查看代码

m0_62024160的博客 2834

Ubuntu 22.04 实战:为WIFI6网卡Realtek RTL8852BE手动编译驱动指南

本文详细介绍了在Ubuntu 22.04系统上为Realtek RTL8852BE WIFI6网卡手动编译驱动的完整指南。从问题诊断、环境准备到源码获取、编译安装,逐步解决驱动缺失问题,并提供常见问题排查和性能优化建议,帮助用户充分发挥WIFI6网卡性能。

weixin_30808693的博客 478

codeforces题解(800)

目录A. Optimal PathA. The Third Three Number ProblemA. XOR Mixuptime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a table aa of size n×mn×m. We will consider the table rows numbered from top t

qq_56853912的博客 1283

Android 以太网802.1x 配置

802.1X认证网络配置摘要:本文介绍了通过wpa_supplicant.conf文件配置802.1X企业网络认证的两种方法:PEAP-MSCHAPv2方式和TLS方式。PEAP方式需设置SSID、用户名、密码,可选择是否验证CA证书;TLS方式则需要配置客户端证书、私钥及CA证书路径。文件配置完成后需设置权限并重启设备。最后提出如何验证802.1X配置是否生效的问题,但未给出具体验证方法。该配置适用于需要802.1X认证的企业网络环境。

zhaoyufei133的博客 458

手把手教你学Simulink--人形机器人控制场景实例:基于Simulink的多连杆人形机器人拉格朗日动力学建模仿真

matlab编辑% 连杆长度 (m)% 躯干(髋到CoM)% 大腿% 小腿% 质量 (kg)% 转动惯量(绕质心,简化为杆)matlab编辑% 躯干CoM(假设在髋上方L_body/2处)% 左大腿CoM% 左小腿CoM% (右腿类似,略)本文完成了基于Simulink的多连杆人形机器人拉格朗日动力学建模仿真,实现了:✅ 定义7-DOF平面人形结构✅ 使用Symbolic Math Toolbox自动推导动力学方程✅ 生成。

MHD0815的博客 145

Codeforces 中文题解(持续更新)

Codeforces近期比赛中文题解

TGX的博客 3449

【华为OD技术面试手撕真题】1、长度最小的子数组 | 手撕真题+思路参考+代码解析(C & C++ & Java & Python & JS)(三种解法)

【华为OD面试手撕真题】长度最小的子数组,本专栏更新每年华为OD机试的高频手撕代码题,每个题目都会使用五种语言进行解答(C & C++& Java & Python & JS),思路分析都非常详细, 实现最低的时间复杂度和高通过率,每个解题思路超过百字,内含各个编程语言的八股文面试题,欢迎大家订阅学习, 代码可以直接运行使用,全网限时最低价,持续更新

KJ.JK 1万+

codeforces Hello 2024个人题解(A~C)

1秒256兆标准输入标准输出ab爱丽丝和鲍勃很无聊,于是他们决定用自己的钱包玩一个游戏。爱丽丝的钱包里有a枚硬币,而鲍勃的钱包里有b枚硬币。双方轮流玩,由爱丽丝先走棋。10无法在自己的回合中做出有效举动的玩家输。如果爱丽丝和鲍勃都以最佳方式下棋,则决定谁将赢得游戏。

Lazy_ChessPlayer的博客 1592

基于Spring Boot 3 + Vue 3 + Vite的现代化社区订餐系统设计与实现

本文将详细阐述系统的整体架构、数据库设计、核心功能模块(用户管理、餐厅管理、菜品浏览、购物车、订单管理)的实现细节,并提供关键代码示例。<el-input v-model="loginForm.password" type="password" placeholder="密码" prefix-icon="Lock" show-password />.requestMatchers("/api/auth/**", "/api/dishes/public/**").permitAll() // 公开接口。

2201_76125393的博客 468

基于STM32设计的智能水母投喂器(华为云IOT)_170

本项目利用STM32单片机控制各种传感器和水泵等设备,能够自动检测和调整水温和水质等参数,自动换水,自动供氧等等,充分满足了水母的养殖要求和需要。同时,根据水母喜欢的光环境,添加了RGB氛围灯,以及可以手动控制的喂食器等功能,提升了水母养殖的便利性和趣味性。

8806

Codeforces Round #678 (Div. 2)

文章目录Codeforces Round #678 (Div. 2)A. ReorderB. Prime SquareC.Binary SearchD. Bandit in a CityE. Complicated Computations Codeforces Round #678 (Div. 2) A. Reorder 题意: 给定n和m,问∑i=1n∑j=inajj\sum_{i=1}^{n}{\sum_{j=i}^{n}{\frac{a_j}{j}}}∑i=1n​∑j=in​jaj​​是否为m 题解

m0_49959202的博客 164

Unity 面试篇|(四)Unity性能优化篇 【全面总结 | 持续更新】

Unity中,CPU准备好需要绘制的元素,对底层图形程序接口进行调用的过程,每次引擎准备数据并通知GPU的过程称为一次Draw Call。DrawCall越高对显卡的消耗就越大。降低DrawCall的方法:动态合批静态合批降低shader的等级特性场景优化策略——遮挡技术。rectMask2D替代Mask。

游戏开发小Y的博客 13万+

Codeforces Round #678 (Div. 2) A~F个人题解

Codeforces Round #678 (Div. 2) A~F个人题解

qq_53446104的博客 274

深度学习工具包 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&#39;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(&#39;DeepLearnToolbox&#39;));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(&#39;state&#39;,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&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,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 = &#39;sigm&#39;;%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, &#39;Too big error&#39;);```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(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;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)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;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, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% 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&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 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, &#39;Too big error&#39;);```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(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % 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, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);%% 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(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

Codeforces Round #678 (Div. 2) 题解

文章目录前言A. ReorderB. Prime SquareC. Binary Search总结 前言 蒟蒻又来发题解了,今天感觉没有水题 又是哭哭唧唧写题的一天啊QAQ A. Reorder A题原题戳这里 题目的大致意思:给定数组a的数,求a[i]/i*i的和,若等于给定的值m就输出Yes,否则输出No(水题~) 题解: #include<iostream> using namespace std; double a[110]; int main() { int t;

lfy0的博客 213

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

Codeforces Round #678 (Div. 2) C. Binary Search

Codeforces Round #678 (Div. 2) C. Binary Search(组合数学) 思路:二分的操作可以转换找smallsmallsmall次小等于goalgoalgoal的数和找bigbigbig次比goalgoalgoal大的数。可以先对递增序列进行一次操作求出找到位置ppp的数对于的smallsmallsmall和goalgoalgoal,然后就是简单的组合数学。 #include<bits/stdc++.h> using namespace std; typed

Harris-H的博客 659

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

Codeforces Round #678 (Div. 2) C. Binary Search组合数+快速幂逆元

Codeforces Round #678 (Div. 2)C 组合数+快速幂逆元 题意:给你一个二分的模板,然后就是给你一个序列长度为N,固定序列中一个位置pos,该处的值为 x,问 我有多少种序列可以在无序的时候依旧可以使用二分找到这个x。序列是从0—N-1的。 题解:首先我们要知道,mid=L+R>>1;每次查询的这个(mid-1位置上的数)值要是在pos左边那必须是小于x,在右边一定是大于的,所以我们可以先二分pos的左右两边,找到小于等于x的个数a,大于x的个数b。注意,二分条件里面.

weixin_45187630的博客 256

Codeforces Round #678 (Div. 2) Oct/24/2020 22:05UTC+8

Codeforces Round #678 Div. 2 Oct/24/2020 22:05UTC+8C. Binary SearchD. Bandit in a CityE. Complicated Computations 比赛链接:https://codeforces.com/contest/1436 比赛记录:https://blog.csdn.net/cheng__yu_/article/details/105395197 C. Binary Search 题意:给定一个二分查找算法,问有多少个

qq_17080419的博客 379

Codeforces Round #678 (Div. 2) A,B,C,D,E

文章目录A. ReorderB. Prime SquareC. Binary SearchD. Bandit in a CityE. Complicated Computations A. Reorder 判断一下所有元素加和是否等于m即可。 #include <bits/stdc++.h> using namespace std; int T; int n,m; int sum; int main() { scanf("%d",&T); while(T--) {

hhhcbw的博客,欢迎各位来访 1135

codeforces Round #678 (Div. 2) 1436

A. Reorder 题解 就是求数组a里面元素的和 判断是否与 k 相等 #include<iostream> #include<algorithm> using namespace std; const int N = 1e6 + 10; int t, n, k, a; int main () { cin >> t; while(t -- ) { int res = 0; cin >> n >> k; for(int

qq_45697243的博客 235

Codeforces Round #672 (Div. 2) 1420A 【思维】 题解

目录1.A题1.1题意1.2思路1.3代码 1.A题 CodeForces - 1420A For god’s sake, you’re boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for? Oh, that’s funny, is it? Oh it’s funny? Because we’ve bee

林深不见鹿 的博客 400

Codeforces Round #678 (Div. 2)补题

B. Prime Square 传送门 题目大意:输出一个方阵,使方阵每行每列的和都是素数,同时方阵的组成不能是素数 解法: 我原来的思路是素数筛,然后发现太麻烦,方阵中允许重复数字出现,我无法用代码实现 正确思路:方阵行列最小为2,找到两个数字a,b,是的a+b=素数,吧这两个数字放进数组中,然后对这个数组全排列输出。对此可以建立一个方阵,行列相同 1 2 3 4 2 3 4 1 3 4 1 2 4 3 2 1 代码如下: import java.util.*; publ

ba7bc的博客 456

Codeforces Round #678 (Div. 2) C

题目链接 思路 按照题目所给程序,将a[mid]<=x等价转化为mid<=pos,即可求出需要小于和大于x的数量。则答案转化为在x-1个数中任意选取small个小于x的数×在n-x个数中任意选取big个大于x的数×剩余的(n-big-small-1)个数任意组合。 代码 #include<map> #include<stack> #include<queue> #include<string> #include<math.h> #i

WTMDNM_的博客 277
上一篇: Codeforces Round #676 (Div. 2)A-D题解
下一篇: 2020CCPC绵阳站后记
StandNotAlone
博客等级 码龄7年 338粉丝 47原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值