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;}
}
【论文翻译】YOLO26: KEY ARCHITECTURAL ENHANCEMENTS AND PERFORMANCE BENCHMARKING FOR REAL-TIME OBJECT DETEC 本研究对Ultralytics YOLO26进行了全面分析,重点阐述了其在实时边缘目标检测领域的关键架构改进与性能基准测试结果。YOLO26于2025年9月发布,是YOLO系列中最新、最先进的模型,专为在边缘设备和低功耗设备上实现高效能、高精度和部署就绪性而设计。论文依次详细介绍了YOLO26的架构创新,包括移除分布焦点损失(DFL)、采用端到端无非极大值抑制(NMS)推理、集成渐进式损失(ProgLoss)和小目标感知标签分配(STAL),以及引入MuSGD优化器以实现稳定收敛。 阅读详情

相关推荐

用友YonSuite产品实操手把手教学(图文版)

用友YonSuite

ct341688的博客 8161

codeforces查看题解

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

m0_62024160的博客 2834

SLAM轨迹评估神器evo实战:从GPS到TUM格式的完整转换指南(附Python代码)

本文详细介绍了如何使用evo工具将GPS数据转换为TUM格式,以便进行SLAM轨迹评估。通过Python代码实现GPS到笛卡尔坐标的精确转换,并提供了完整的处理流程和实战案例,帮助开发者轻松完成从原始GPS数据到精确轨迹评估的全过程。特别适用于ORB-SLAM等视觉SLAM算法的性能验证。

weixin_29074295的博客 293

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

嵌入式环境下XML配置文件解析实践

在资源受限的嵌入式环境中,如何轻量级地解析XML配置文件成为关键。通过简化语法结构与优化内存使用,实现快速读取和解析配置文件,提升系统启动效率与稳定性。

weixin_31869917的博客 399

Java实战:绿盾加密文件批量解密工具Ldterm的实现与优化

本文详细介绍了基于Java开发的绿盾加密文件批量解密工具Ldterm的实现与优化过程。通过分析绿盾加密机制,结合Java流处理能力,实现了高效的文件解密方案,并分享了多线程处理、内存优化等性能提升技巧,适用于企业级数据迁移与备份场景。

weixin_29314405的博客 490

Codeforces 中文题解(持续更新)

Codeforces近期比赛中文题解

TGX的博客 3449

Lane、PHY和Preset Value Bit

每个Lane支持不同的传输速度和带宽,例如PCIe 3.0中,一个Lane的传输速度可以达到8 GT/s(Giga Transfers per second),也就是1 GB/s(GigaBytes per second)。Preset Value Bit(预置值位)是在PCIe 3.0的Lane上新引入的一种机制,用于优化信号传输质量。PCIe设备可以包含多个Lane,例如x1、x4、x8、x16等,表示该设备同时使用的Lane数目,比如x16表示该设备采用了16个Lane,具有更高的传输速度和带宽。

weixin_58083606的博客 1296

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

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

Lazy_ChessPlayer的博客 1592

innovus:如何在init design之后新增参考库(lib/lef)

如题,在PR过程中经常会遇到这种问题,时序无法收敛,需要新增一套lvt或者hpc的库,怎么办?

m0_61544122的博客 5007

[SaaS] 阿里妈妈-万相营造

有controlnet的介入,我们是默认controlnet会介入,在inapinting时会把带有商品的画布做一点扩充,然后走inapinting和controlnet,其实也做了一点outpainting的工作。基于阿里妈妈营销平台,提供从图文到视频再到落地页的素材级智能化创意支持,是您营销创意数字资产累积和升值的阵地,最大化提升营销的效率和效果。目前看来抠图基本都是sam了,现在weshop也是,都有一个预扣好的主体,但是一点进去也会重新sam。atomovideo->图生视频。

liguandong 524

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

14、改进的目标检测与图像去模糊算法研究

本文研究了改进的目标检测与图像去模糊算法。改进的YOLOv5s算法在目标检测中通过添加PSA模块和VoVGSCSP结构,在轻量化模型的同时提高了检测的准确性和速度,适用于电力操作安全穿戴设备检测等场景。XT-GAN结合Transformer和生成对抗网络,在图像去模糊任务中有效解决了传统方法的不足,具有更低的计算复杂度和良好的鲁棒性。两种算法为计算机视觉领域的相关任务提供了更高效、准确的解决方案。

c7d8e的博客 214

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

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

qq_53446104的博客 274

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

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

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

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

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

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

廖雪峰Python教程[完整版]

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

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、付费专栏及课程。

余额充值