Codeforces Round #677 (Div. 3)A-G题解

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 #677 (Div. 3)A-G题解
比赛链接:https://codeforces.ml/contest/1433/

A题
水,施行

题意为给定一个1到9999的每一位上数字相同的整数x,现在按照一定规则报数,问报到x的时候,总共报了多少位的数字。
报数规则为从1,11,111,1111到2,22,222,2222…到9,99,999,9999。

注意到我们需要关注的只是x是由哪个数字构成的,以及x有几位。
假设x是由若干个y构成的,对于任意的数字比如1,喊完1,11,111,1111总共要报10位数字。因此报到y之前总共要报10(y-1)位,之后再看当前的x要报几次,1,2,3,4依次加上去就是了。

#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 x;
        cin>>x;
        int ans=10*(x%10-1);
        int cas=0;
        while(x)
        {
            cas++;
            ans+=cas;
            x/=10;
        }
        printf("%d\n",ans);
    }
}

B题
贪心,思维

题意为给定一个01数列a[],每次操作我们可以选择一个连续的1区间,把他们整体左移或者整体右移一个位置,询问最少要多少次操作可以使得所有的1都在一个连续的区间。

注意到对于所有1的初始位置中,最左侧和最右侧的下标位置构成的区间,对于这区间内的0,我们每次操作最多并且必然可以(操作最左侧或者最右侧的连续1区间即可)使得它们减少1。执行此贪心过程的话我们的最少操作次数就是这段区间内0的个数了。
统计即可。

#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 flag[60];

int32_t main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int pre=-1,ans=0;//pre标记上一段连续1区间的右侧位置
        for(int i=1;i<=n;i++)
        {
            cin>>flag[i];
            if(flag[i]&&!flag[i-1]&&pre!=-1)//记录连续1区间之间的0的个数,pre=-1的时候代表是最左侧的0区间不需要计算进去
            {//flag[i]=1,flag[i-1]为0,正好是连续0区间到连续1区间的分界处
                ans+=i-pre;//两个位置下标相减,即为这一段连续0区间的长度
                pre=-1;
            }
            if(!flag[i]&&flag[i-1]) pre=i;
        }
        cout<<ans<<endl;
    }
}

C题
贪心,构造

题意为有n条鱼,排成一排,每条鱼有一个初始的力量值。我们需要选定一条鱼,他每次可以吃掉自己左边或者右边的一条鱼,并且每吃掉一条鱼后,自己的力量值+1。询问是否存在这样一条鱼,可以把所有的其他鱼吃掉,输出位置下标。

首先想一下不存在这样的鱼的情况。那就是所有鱼的初始力量都相同时,没有鱼可以吃掉其他鱼。
那么当不是所有鱼的初始力量值都相同的时候,我们必定可以找到一个初始的最大力量值,并且拥有这个最大力量值的所有鱼当中,必定存在一条鱼的周围有比他力量值小的鱼(否则就是所有鱼初始力量值都相等的情况了)。我们选定这样一条初始为最大力量值,周围有比他力量值小的鱼,吃掉旁边这条鱼后力量值+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 maxn=3e5+7;

int num[maxn];

int32_t main()
{
    IOS;
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int M=0;//所有初始值中的最大值
        for(int i=1;i<=n;i++)
        {
            cin>>num[i];
            M=max(M,num[i]);
        }
        int tar=-1;//寻找答案位置
        for(int i=1;i<=n;i++)
        {
            if(num[i]==M)//值要与初始最大值相同
            {
                if(i>1&&num[i-1]!=M) tar=i;//与左侧或者右侧的值不同的位置,均满足要求,输出任意一个
                if(i+1<=n&&num[i+1]!=M) tar=i;
            }
        }
        cout<<tar<<endl;
    }
}

D题
构造

题意为给定n个点,你需要构造n-1条边,把这n个点连接成一个连通图。但是每个点都有一个标记值,标记值相同的点不能用某条边直接连接,只能间接连通。询问是否有满足要求的构造方法。

思考过程如上题,首先无法构造的情况,所有点的标记值都相同,我们无法构造任何边,故此情况下不存在满足要求的构造方法。
那么当并不是所有点的标记值都相同的情况下,必然存在两个下标的点x和y,他们的标记值是不同的。那么我们把所有与x点标记值不同的点(包括y)都与x连接起来,那么就只剩下标记值与x相同的点没有连接进来了,我们将这些点与y点连接起来即可。便能构造出满足要求的连通图。

按照以上思路构造即可。

#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;
        cin>>n;
        vector<ll>num(n);
        for(auto &x:num) cin>>x;
        int tar=-1;
        for(int i=1;i<n;i++)
            if(num[i]!=num[i-1])//寻找是否有标记值不同的两个点
            {
                tar=i;
                break;
            }
        if(tar==-1) cout<<"NO"<<endl;//所有点标记值相同,无法构造任何边
        else
        {
            cout<<"YES"<<endl;
            for(int i=0;i<n;i++)
            {
                if(i!=tar-1)
                {
                    if(num[i]!=num[tar-1]) cout<<tar<<' '<<i+1<<endl;//如果标记值与tar-1下标点的值不同,则连接到tar-1点上
                    else cout<<tar+1<<' '<<i+1<<endl;//如果与tar-1点的标记值相同,则连接到tar点上,tar点与tar-1点标记值不同固必定符合要求
                }
            }
        }
    }
}

E题
组合数学

题意为给定n个人,标记为1-n,n为偶数。现在需要你将这n个人分为人数相同的两组,每组都给定一个排列顺序,询问总共有多少种不同的分法。其中排列[1,2,3,4]和[2,3,4,1]和[3,4,1,2]和[4,1,2,3]这样循环相同的排列被认为是相同的排列方式。

首先很容易想到的,分为两组必定要计算组合数C(n/2,n),然后A,B和B,A两种方式重复,再除以2。接着需要考虑的就是两个分组各自有多少种不同的排列了。不考虑循环相同的情况下,n/2长度的排列数为(n/2)!,而考虑循环相同,每n/2种排列构成相同的一种排列方式,因此总方案数应该是(n/2-1)!。两个分组的排列情况相乘,因此最后的总排列数应该为C(n/2,n)/2×\times×(n/2-1)!×\times×(n/2-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;

int32_t main()
{
    IOS;
    int n;
    cin>>n;
    ll ans=1;
    for(int i=1;i<=n/2;i++) ans=ans*(n-i+1)/i;//计算C(n/2,n),划分成两组
    for(int i=2;i<n/2;i++) ans*=i*i;//乘上两边n!,并且除掉两个n,化简后便是该循环。此处为两组当中排列方式不同的情况,除掉n是因为循环相同的排列也属于排列方式相同
    cout<<ans/2<<endl;//A,B和B,A的分法重复,除以2
}

F题
dp

题意为给定一个n×\times×m的矩阵,每行最多取m/2个数字,要找到一个最大的总和值,满足能被k整除。

注意到数据范围都很小,都只有70。
对于每行来说,我们可以按照取了几个数字,对k取模等于多少,分为70/2 ×\times× 70种状态。使用dp去计算每行取不超过m/2个数的情况下,对k取模为j时,能得到的最大总和值,再将它用同样的dp方式,计算到最终答案上即可。
具体实现和转移方程见代码。

#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;

int n,m,k;

int dp[50][100],ans[2][100];//dp[i][j]讨论的是某一行,代表选择了i个数的情况下,得到的sum对k取模等于j的情况下,sum的最大值
//ans数组则用滚动数组来记录最终答案,ans[i][j],代表当前已经dp计算得的所有行累加情况下,得到的sum对k取模等于j的情况下,sum的最大值

int32_t main()
{
    IOS
    bool flag=0;
    cin>>n>>m>>k;
    int lim=m/2;//每行最多取lim个数
    for(int i=0;i<n;i++)
    {
        memset(dp,0,sizeof(dp));
        for(int j=0;j<m;j++)
        {
            int x;cin>>x;
            for(int q=lim-1;q>=0;q--)//注意这里循环是从大到小
            {
                for(int p=0;p<k;p++)
                {
                    int temp=dp[q][p]+x;
                    if(temp>dp[q+1][temp%k]) dp[q+1][temp%k]=temp;
                }
            }
        }
        for(int q=0;q<k;q++)
        {
            for(int p=0;p<k;p++)
            {
                int temp=ans[flag][p]+dp[lim][q];
                if(ans[!flag][temp%k]<temp) ans[!flag][temp%k]=temp;
            }
        }
        //for(int i=0;i<k;i++) cout<<ans[!flag][i]<<endl;
        flag=!flag;//滚动数组翻滚
    }
    cout<<ans[flag][0]<<endl;
}

G题
最短路,暴力,复杂度分析

题意为给定一个n个点,m条双向边的连通图,给定k条路径的起终点。询问在将最多一条边的权值修改为0的情况下,这k条路径的消耗总和的最小值。

注意到数据范围都很小,最大1000。因此可以采取暴力一些的做法。
如果我们暴力枚举删除每条边,每次删除后暴力去跑k次Dijskra的话,总复杂度mk(n+m)logn,1e9带常数的级别,必定会tle。
这代表我们的方法过分暴力了,注意到上述表述中有两个暴力过程,我们尝试思考是否可以把其中的某一部分暴力过程优化。
对于我们把i点到j点的路径置为0,对于从q点到p点的最短路径来说,存在两种大的情况。
1.i到j点路径置为0后,q点到p点的最短路径选择未受影响
2.i到j点路径置为0后,q点到p点的最短路径选择受到影响,并且i点到j点的路径必定在新的最短路径上。

对于第二种情况,可以是q->i->j->p也可以是q->j->i->p,这两种路径长度分别为q到i的最小距离加上j到p的最小距离,和q到j的最小距离加上i到p的最小距离。这两种方案与原本不把路径置零的情况下q到p的最小距离取最小值,即为把i到j点路径置为0后,q到p的最短距离了。

有了上述结论后,我们注意到,上面需要的三个距离,我们只需对k次询问的所有起终点,都跑一次Dijskra即可。总复杂度2k(n+m)logn。
离线计算k次询问的所有起终点,到其他所有点的最短距离,之后跑一次km复杂度的计算即可。

#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 int maxn=1e3+7;

int n,m,k,tot;

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

int head[maxn];

void init()
{
    for(int i=1;i<=n;i++) head[i]=-1;
    tot=0;
}

void add(int u,int v,int w)
{
    edge[tot].dis=w;
    edge[tot].to=v;
    edge[tot].next=head[u];
    head[u]=tot++;
}

ll dis[maxn][maxn];//dis[i][j]记录i点到j点的最短距离

struct Node
{
    int pos;ll val;
    Node(int pos,ll val):pos(pos),val(val){}
    friend bool operator < (Node a,Node b)
    {
        return a.val>b.val;
    }
};

void Dijskra(int st)
{
    for(int i=1;i<=n;i++) dis[st][i]=llINF;
    dis[st][st]=0;
    priority_queue<Node>Q;Q.push(Node(st,0));
    while(Q.size())
    {
        Node now=Q.top();
        Q.pop();
        if(now.val>dis[st][now.pos]) continue;
        for(int i=head[now.pos];i!=-1;i=edge[i].next)
        {
            int to=edge[i].to;
            if(dis[st][to]>edge[i].dis+now.val)
            {
                dis[st][to]=edge[i].dis+now.val;
                Q.push(Node(to,dis[st][to]));
            }
        }
    }
}

int u[maxn],v[maxn],w[maxn],st[maxn],ed[maxn];

int32_t main()
{
    IOS
    cin>>n>>m>>k;
    init();
    for(int i=0;i<m;i++)
    {
        cin>>u[i]>>v[i]>>w[i];
        add(u[i],v[i],w[i]);add(v[i],u[i],w[i]);
    }
    for(int i=0;i<k;i++)
    {
        cin>>st[i]>>ed[i];
        Dijskra(st[i]);Dijskra(ed[i]);//预处理出所有询问的起终点,到其他所有点的距离
        //单次Dijskra复杂度为(n+m)logn,要跑2k次,总复杂度2k(n+m)logn
    }
    ll ans=llINF;
    for(int i=0;i<m;i++)//此处O(1)计算,总复杂度mk
    {
        ll temp=0;
        for(int j=0;j<k;j++) temp+=min(dis[st[j]][ed[j]],min(dis[st[j]][u[i]]+dis[ed[j]][v[i]],dis[st[j]][v[i]]+dis[ed[j]][u[i]]));
        ans=min(ans,temp);
    }
    cout<<ans<<endl;
}
Codeforces Round #786 (Div.3) 题解 (CF786) [A-G] Codeforces Round #786 (Div.3) 题解 [A-G] 阅读详情

相关推荐

Codeforces Round #787 (Div. 3)个人题解

Codeforces Round #787 (Div. 3)个人题解 Codeforces Round #787 (Div. 3) A. Food for Animals B. Make It Increasing C. Detective Task D. Vertical Paths E. Replace With the Previous, Minimize F. Vlad and Unfinished Business G. Sorting Pancakes

weixin_51767904的博客 1383

Codeforces Round #677(Div.3)

Codeforces Round #677 (Div. 3) 目录Codeforces Round #677 (Div. 3)A. Boring ApartmentsB. Yet Another BookshelfC. Dominant PiranhaD. Districts Connection A. Boring Apartments 题意: 有一栋公寓有编号为1~10000的房间,从1开始拨打电话到n为止,求拨号到所有每位数字相同(例如“11”“9999”)的房间按下的次数和。例如,如果n==22

dyChao_19的博客 2068

手把手教你安装 Vivado2022.2(附安装包)

Vivado 2022.2版本与之前的版本相比,具有以下几个显著的优势:电源设计管理器(PDM):Vivado 2022.2引入了全新的电源设计管理器(PDM),这是一个下一代功耗评估平台,为Versal® 和 Kria™ SOM提供了准确一致的功耗估计能力。PDM是Versal产品家族的首选功耗评估工具,为Versal ACAP硬IP块提供增强向导,简化从XPE向PDM的迁移,帮助用户获得准确的功耗评估。

dpwkj的博客 2万+

Codeforces Round #677 (Div. 3)

A. Boring Apartments 题意: 存在一个有规律的数列1,11,111,1111,2,22,222,2222...9,99,999,9999。 给定数列中的某个数x,询问该数(包括)前有几个数。 思路: 取出这个数的最后一位x,答案就是(x*4+当前数的位数) 时间复杂度: O(logn) AC代码: void solve() { int n; cin>>n; int k = n%10; int cnt = ...

qq_62213124的博客 669

XS5018A TX ISP芯片同轴高清模拟输出图像处理芯片用户指南

当看门狗开启且系统异常,看门狗模块得不到喂狗信号时,自动产生看门狗复位信号,复位​​​​​​​。分量上与人眼对光谱的响应通常是有偏差的,通常通过一个色彩校正矩阵校正光谱响应的交叉效。但实际上由于电路的作用,复位模块对整个芯片及各个功能模块的复位进行统一管理,负责产生各个模块的软复位信。每个区域前景色可以在 16 个色表中查找,单个区域的前景色统一,各个区域的前。较弱的坏点被放大成刺眼的白点和明显的黑点,强烈推荐开启动态坏点校正功能。四种制式,通过寄存器配置,可以很方便的实现四种制式的切换、且可以对截止。

2403_88922712的博客 1975

Appsflyer Web2App实战指南:OneLink与Web SDK深度对比

本文深入对比了Appsflyer实现Web2App的两大核心工具:OneLink智能链接与Web SDK。OneLink提供开箱即用的智能跳转,部署快捷,适合快速推广;Web SDK则支持高度自定义的用户行为追踪,适合深度分析与精细化运营。文章提供了详细的配置指南、场景化选型建议及实战避坑技巧,帮助营销与开发团队根据自身需求选择最佳方案,有效提升从网页到应用的转化率与归因精度。

weixin_29213655的博客 464

D. Districts Connection(思维)Codeforces Round #677 (Div. 3)

原题链接: https://codeforces.com/contest/1433/problem/D 测试样例 input 4 5 1 2 2 1 3 3 1 1 1 4 1 1000 101 1000 4 1 2 3 4 output YES 1 3 3 5 5 4 1 2 NO YES 1 2 2 3 3 4 YES 1 2 1 3 1 4 题意: 有nnn个区,每个区都属于一个帮,现在你需要用n−1n-1n−1条道路连连接这些区,要求所连的直接区不能属于一个帮,可以使用中间点来连接。 解题思路

pursuit的博客 915

Nacos2.3.0与vastBase数据库的集成实践指南

本文详细介绍了将Nacos 2.3.0的默认数据库从MySQL迁移至vastBase数据库的完整实践指南。内容涵盖前期环境准备、源码改造、依赖配置、SQL适配、数据库初始化以及最终的编译打包与部署验证,旨在帮助开发者在国产化或特定技术栈场景下,实现微服务配置中心与vastBase数据库的自主可控集成。

plant的博客 281

B. Yet Another Bookshelf(思维)Codeforces Round #677 (Div. 3)

原题链接: https://codeforces.com/contest/1433/problem/B 测试样例 input 5 7 0 0 1 0 1 0 1 3 1 0 0 5 1 1 0 0 1 6 1 0 0 0 0 1 5 1 1 0 1 1 output 2 0 2 4 1 Note In the first test case of the example, you can shift the segment [3;3] to the right and the segment [4;

pursuit的博客 783

【AI气象6】Skilful nowcasting of extreme precipitation with NowcastNet

极端降水是气象灾害的重要因素,因此迫切需要通过高分辨率、长时间预报和局部细节的精准短期预报来减轻其社会经济影响。当前的方法存在模糊、衰减、强度或位置误差,基于物理的数值方法在捕捉关键的混沌动态(如对流起始)时面临挑战,而数据驱动的学习方法则未能遵循内在的物理法则(如平流守恒)。我们提出了 NowcastNet,这是一种针对极端降水的非线性短期预报模型,将物理演变方案与条件学习方法统一到一个端到端的神经网络框架中,通过优化预测误差进行训练。基于来自美国和中国的雷达观测数据,我们的模型能够生成物理上合理的降水短

weixin_51473374的博客 2332

18.EC实战 新建项目工程并配置各个引脚的工作方式(持续更新)

本博文介绍了从零开始新建EC工程及对各个引脚进行了工作模式的初始化配置

qq_30135687的博客 1737

Codeforces Round #677 (Div. 3) A-G

比赛链接 A.把数存下来然后算一下 #pragma GCC optimize(2) #pragma GCC optimize(3) #include <bits/stdc++.h> using namespace std; typedef long long LL; const int N = 2e5 + 10; #define fi first #define se second #define pb push_back #define wzh(x) cerr<<#x<&lt

pubgoso的博客 546

mabl:AI原生测试自动化平台的基础使用

mabl是一个基于人工智能和机器学习的云原生测试自动化平台。它通过使用先进的技术,如机器学习,自动创建和执行测试,自动分析测试结果,并根据需求的变化自动适配和维护测试。这样的自动化过程极大地提高了软件测试的效率和准确性。mabl的口号是 “You write code, mabl tests”,意味着开发者只需关注编写代码,而测试工作则可以交给mabl来完成。mabl的平台支持多种测试类型,包括 Web、App、Api、可访问性和性能测试,使得团队能够更快速、更有信心地发布软件。

blues_C的博客 3670

Codeforces Round #677 (Div. 3)[A-G]题解

A. Boring Apartments(思维) B. Yet Another Bookshelf(思维) C. Dominant Piranha(思维) D. Districts Connection(思维+构造) E. Two Round Dances(思维+圆排列组合数学) F. Zero Remainder Sum(思维+四维dp) G. Reducing Delivery Cost(思维+最短路) ...

代码笔记本 369

从传统业务到 AI Skill:产品经理也能看懂的能力改造指南(含完整案例)

从传统业务到 AI Skill:产品经理也能看懂的能力改造指南(含完整案例)

专注于编程、AI、人工智能等多个领域内容研究和分析 667

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

Codeforces Round #760 (Div. 3)题解(A-G)

Codeforces Round #760题解

qq_45758578的博客 2404

深度学习工具包 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 #786 (Div. 3) A ~ G 全题解

Codeforces Round #786 (Div. 3) A ~ G 全题解 A. Number Transformation 题意 给你两个整数x,y,你需要选择两个正整数a,b使得x乘a次b后等于y,输出a和b 若无解输出0 0 思路 判断是否有解,只需要看y是不是x的倍数,如果不是则无论怎么乘都不能把x变成y 如果有解,我们选一个特殊解 令a为1,b为y/x即可 AC代码 #include<bits/stdc++.h> using namespace std; const int N

csxylrf的博客 1324

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

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

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

【Codeforces 1475】Codeforces Round #697 (Div. 3) | 全题解

:比赛连接 emm,消极了,消极了。这场可以akakak的,看到unrunrunr不想打了,奇怪了,本身我也不加分的呀。 赛后333分钟过GGG,101010分钟过FFF,不该消极的。 不传播负能量了,开始题解了。 A.Odd Divisor 题目大意: 判断一个整数nnn,是否具有为奇数的因子 题目思路: 水题了吧. 只需要判断是否是2的幂即可,不是2的幂必定有奇数因子呀。 Code: /*** keep hungry and calm CoolGuang! ***/ #pragma GCC optim

一只酷酷光儿的博客 3277

【算法题解】Codeforces Round #817 (Div. 4)题解

只要我们有改变--就会有获得感--就回增加自信--就会有助于坚持--就可以帮助你改掉拖延的顽疾!

小新的博客 1581

Codeforces Round #744 (Div. 3)题解A-G

Codeforces Round #744 (Div. 3) A. Casimir’s String Solitaire 分析:不难发现,当且仅当B的个数等于A和C的个数的和时,可行。 代码: #include <algorithm> #include <iostream> using namespace std; const int N = 500; char s[N]; void solve() { scanf("%s",s); int a, b; a = b

Arctic_Clam的博客 710

Codeforces Round #697 (Div. 3 A-G)题解(新鲜)

记录一下div3第一次akakak,虽然是因为这次很简单的原因…不过还是很开心hhh A,BA,BA,B太简单了就不写了,然后下面每一题都写了比较详细的题解^_^. 1475C. Ball in Berland(容斥原理) 1475D. Cleaning the Phone(二分+前缀和) 1475E.Advertising Agency(排序) 1475F. Unusual Matrix(构造,模拟) 1475G. Strange Beauty(dp+优化) ...

jziwjxjd的博客 1726

Codeforces Round #677 (Div. 3)A-G

Codeforces Round #677 (Div. 3) A. Boring Apartments 题意: 一个无聊的人喜欢 给楼层居民打电话 如果他要给某户人打电话它会吧之前的每户都打一遍 问他在打给某房间号 按了多少个数字 其中 房间号 定义类似如下 第一层【1,11,111,1111】 第二层 【2,22,222,2222】 问题分析: 每层全拍 就是10个数字=1+2+3+4 最后一层 没户按键数量就是他目前的长度 看码,看码。 AC代码: #include<iostream> #

MaxVen 193

Codeforces Round #702 (Div. 3)A-G题解

Codeforces Round #702 (Div. 3)A-G题解 比赛链接:https://codeforces.ml/contest/1490 这场F读错题意白给一发,G二分的if(dp[mid]<x)居然写成了if(dp[l]<x),做梦都没想到自己二分有写错的一天,疯狂白给5发。 Div3相对以前变简单了,罚时手速场。 A题 暴力 题意: 1000组数据 给定一个只包含正整数的长度为n的数组(n最大50),每个数字均在1到50之间。 你可以在任意位置插入任意的整数(这里其实有bug,

StandNotAlone的博客 3170

Codeforces Round #481 (Div. 3)(A-G)题解

Codeforces Round #481 (Div. 3)(A-G)题解 传送门 A. Remove Duplicates 思路:先用一个vis[]vis[]vis[]记录那些数出现过,储存他们最后一次出现位置,然后排个序输出即可。 时间复杂度:O(n)O(n)O(n) 实际上不用排序,直接顺序遍历对应匹配输出即可。 #include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=50+5,M=1e6

Harris-H的博客 722

Codeforces Round #677 (Div. 3) A - G

Codeforces Round #677 (Div. 3) A. Boring Apartments 思路 设相同的数的数为n位数为k,可以很明显看到答案为 (n - 1) * 10 + (1 + 2 + 3 ···+ k ) 代码 #include<iostream> using namespace std; int main(){ int T; cin >> T; while(T--){ int n; scan

qq_45074215的博客 259
上一篇: 2020CCPC绵阳站后记
下一篇: 2020CCPC长春站后记
StandNotAlone
博客等级 码龄7年 338粉丝 47原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值