Codeforces Round 957 (Div. 3) A~G

Codeforces Round 957 (Div. 3) 阅读详情

A.Only Pluses (枚举)

题意:

给出三个整数 aaa 、 bbb 和 ccc 可以执行以下操作最多 555 次。

  • 挑选其中一个整数;
  • 将其增加 111 。

通过这些操作可以实现的 a×b×ca \times b \times ca×b×c 的最大值是多少?

分析:

枚举a,b,ca,b,ca,b,c三个数在操作之后的值即可。

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define endl '\n'
#define PII pair<LL, LL>
const int maxn = 805;
const int INF = 1e9;
const int mod = 998244353;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int T;
    cin >> T;
    while (T--)
    {
        int a, b, c;
        cin >> a >> b >> c;
        int ans = a * b * c;
        for (int i = a; i <= a + 5; i++)
        {
            for (int j = b; j <= b + 5; j++)
            {
                for (int k = c; k <= c + 5; k++)
                {
                    if (i + j + k - (a + b + c) <= 5)
                        ans = max(ans, i * j * k);
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

B.Angry Monk (模拟)

题意:

给出一个数组,每次操作可以将数组中的一个数xxx分成x−1x-1x−1和111,或者将一个数xxx和一个111合并,问最少多少次操作可以将数组中所有数合并成一个。

分析:

我们从小到大将除了最大值的每个数字xxx分成xxx个111,再将他们全都合并到最大的数字上,每个数字的贡献是2×x−12 \times x-12×x−1。

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define endl '\n'
#define PII pair<LL, LL>
const int maxn = 805;
const int INF = 1e9;
const int mod = 998244353;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int T;
    cin >> T;
    while (T--)
    {
        int n, k, mx = 0;
        cin >> n >> k;
        int ans = 0;
        for (int i = 1; i <= k; i++)
        {
            int tmp;
            cin >> tmp;
            mx = max(mx, tmp);
            ans += 2 * tmp - 1;
        }
        cout << ans - 2 * mx + 1 << endl;
    }
    return 0;
}

C. Gorilla and Permutation (贪心)

题意:

给出三个数字 nnn 、 mmm 和 kkk。他们决定构造一个长度为 nnn 的排列。

对于该排列, g(i)g(i)g(i) 是长度为 iii 的前缀上排列中所有不大于 mmm 的数字之和。其中 f(i)f(i)f(i) 是长度为 iii 的前缀上排列中所有不小于 kkk 的数字之和。长度为 iii 的前缀是由原始数组的前 iii 个元素组成的子数组。

例如,如果 n=5n = 5n=5 、 m=2m = 2m=2 、 k=5k = 5k=5 ,且排列为 [5,3,4,1,2][5, 3, 4, 1, 2][5,3,4,1,2] ,则:

  • f(1)=5f(1) = 5f(1)=5 ,因为 5≥55 \ge 55≥5 ; g(1)=0g(1) = 0g(1)=0 ,因为 5>25 > 25>2 ;
  • f(2)=5f(2) = 5f(2)=5 ,因为 3<53 < 53<5 ; g(2)=0g(2) = 0g(2)=0 ,因为 3>23 > 23>2 ;
  • f(3)=5f(3) = 5f(3)=5 ,因为 4<54 < 54<5 ; g(3)=0g(3) = 0g(3)=0 ,因为 4>24 > 24>2 ;
  • f(4)=5f(4) = 5f(4)=5 ,因为 1<51 < 51<5 ; g(4)=1g(4) = 1g(4)=1 ,因为 1≤21 \le 21≤2 ;
  • f(5)=5f(5) = 5f(5)=5 ,因为 2<52 < 52<5 ; g(5)=1+2=3g(5) = 1 + 2 = 3g(5)=1+2=3 ,因为 2≤22 \le 22≤2 。

帮助他们找到一个使 (∑i=1nf(i)−∑i=1ng(i))\left(\sum_{i=1}^n f(i) - \sum_{i=1}^n g(i)\right)(∑i=1n​f(i)−∑i=1n​g(i)) 的值最大化的排列。

分析:

我们贪心的考虑这个问题,最优解为:让不超过mmm的数尽量靠后,不小于kkk的数字尽量靠前进行构造即可。

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define endl '\n'
#define PII pair<LL, LL>
const int maxn = 3e5 + 5;
const int INF = 1e9;
const int mod = 998244353;
int a[maxn];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int T;
    cin >> T;
    while (T--)
    {
        int n, m, k;
        cin >> n >> m >> k;
        int l, r;
        int x = 1;
        for (int i = n - m + 1; i <= n; i++)
        {
            a[i] = x;
            x++;
        }
        x = n;
        for (int i = 1; i <= n - m; i++)
        {
            a[i] = x;
            x--;
        }
        for (int i = 1; i <= n; i++)
        {
            cout << a[i] << ' ';
        }
        cout << endl;
    }
    return 0;
}

D. Test of Love(dp)

题意:

ErnKorErnKorErnKor要过河,这条河有nnn个格子,LLL代表平台,可以跳往[L,L+m][L,L + m][L,L+m]的任意位置,WWW代表水,每经过一格水要消耗一个体力,最开始有kkk个体力,也就是最多经过kkk格水,CCC代表鳄鱼,不能待在CCC所在的格子。给定n,m,kn,m,kn,m,k和一个代表河流的字符串,问能否到达对岸。

分析:

dp[i]dp[i]dp[i]表示到达第iii个格子需要游多少米,如果当前是陆地,就枚举往后跳了jjj格,则有dp[i+j]=dp[j]dp[i+j]=dp[j]dp[i+j]=dp[j],如果当前是水域,有dp[i+1]=dp[i]+1dp[i+1]=dp[i]+1dp[i+1]=dp[i]+1。

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define endl '\n'
#define PII pair<LL, LL>
const int maxn = 3e5 + 5;
const int INF = 1e9;
const int mod = 998244353;
int a[maxn];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int T;
    cin >> T;
    while (T--)
    {

        int n, m, k;
        cin >> n >> m >> k;
        string s;
        cin >> s;
        s = "L" + s + "L";
        vector<int> dp(n + 2, 1e9);
        dp[0] = 0;
        for (int i = 0; i <= n; i++)
        {
            if (dp[i] > k or s[i] == 'C')
                continue;
            if (s[i] == 'L')
            {
                for (int j = 1; j <= m and i + j <= n + 1; j++)
                {
                    dp[i + j] = min(dp[i + j], dp[i]);
                }
            }
            else
            {
                dp[i + 1] = min(dp[i + 1], dp[i] + 1);
            }
        }
        if (dp[n + 1] <= k)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    return 0;
}

E. Novice’s Mistake (dp)

题意:

给一个数字nnn,求出100001000010000以内的所有对a,ba,ba,b,能够满足nnn复制aaa次构成的字符串去掉末尾的bbb个数字得到的结果和n×a−bn \times a-bn×a−b相等。

分析:

因为这个数字至多只有666位,我们可以枚举aaa,再从1~61~61~6枚举这个数字的位数,判断由字符串得到的数字是否满足条件。

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define endl '\n'
#define PII pair<LL, LL>
const int maxn = 3e5 + 5;
const int INF = 1e9;
const int mod = 998244353;
vector<PII> ans[110];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int T;
    cin >> T;
    while (T--)
    {
        int n;
        cin >> n;
        string s = to_string(n);
        int len = s.size();
        s += s, s += s, s += s, s += s;
        for (int a = 1; a <= 1e4; a++)
        {
            int num = 0;
            for (int j = 1; j <= 6; j++)
            {
                num *= 10;
                num += s[j - 1] - 48;
                int b = a * len - j;
                if (b <= 0 || b >= 1e4)
                    continue;
                if (n * a - b == num)
                {
                    PII p;
                    p.first = a, p.second = b;
                    ans[n].push_back(p);
                }
            }
        }
        cout << ans[n].size() << endl;
        for (int i = 0; i < ans[n].size(); i++)
        {
            cout << ans[n][i].first << ' ' << ans[n][i].second << endl;
        }
    }
    return 0;
}

F. Valuable Cards (贪心)

题意:

有nnn 张卡片,上面标有不同位置的价格,第 iii 张卡片上有一个整数 aia_iai​ ,这些价格中没有一个正整数 xxx 。

将这些卡片分成最少数量的坏段(以便每张卡片都只属于一个段)。如果无法选择乘积等于 xxx 的卡片子集,则该段被视为坏段。将卡片分成的所有段都必须是坏段。

正式来说,如果没有索引 i1<i2<…<iki_1 < i_2 < \ldots < i_ki1​<i2​<…<ik​ 满足 l≤i1,ik≤rl \le i_1, i_k \le rl≤i1​,ik​≤r 和 ai1⋅ai2…⋅aik=xa_{i_1} \cdot a_{i_2} \ldots \cdot a_{i_k} = xai1​​⋅ai2​​…⋅aik​​=x ,则段 (l,r)(l, r)(l,r) 为坏段。

请确定坏段的最小数量。

分析:

考虑到xxx的除数不超过100100100,因此考虑枚举。我们维护一个数组用于存放xxx的除数的数组。如果a[i]a[i]a[i]是xxx的除数,那么就与在该数组中的元素相乘(注意不要超过xxx,防止数据溢出),如果该数组中出现了xxx , 那么使答案加一并清空数组,然后把 a[i]a[i]a[i] 加入到这个数组中,重复以上操作即可。

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define endl '\n'
#define PII pair<LL, LL>
const int maxn = 3e5 + 5;
const int INF = 1e9;
const int mod = 998244353;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int T;
    cin >> T;
    while (T--)
    {
        int n, x;
        cin >> n >> x;
        int ans = 0;
        vector<int> a(n + 1, 0);
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        map<LL, LL> f;
        for (int i = 1; i <= n; i++)
        {
            if (x % a[i] == 0)
            {
                if (f.empty())
                {
                    f[a[i]]++;
                }
                else
                {
                    map<LL, LL> g;
                    for (auto y : f)
                    {
                        if (x % (y.first * a[i]) == 0)
                            g[y.first * a[i]]++;
                    }
                    for (auto y : g)
                    {
                        f[y.first] += y.second;
                    }
                    if (f.count(x))
                    {
                        ans++;
                        f.clear();
                    }
                    f[a[i]]++;
                }
            }
        }
        ans++;
        cout << ans << endl;
    }
    return 0;
}

G. Ultra-Meow (组合数)

题意:

给出一个长度为 nnn 的数组 aaa ,由数字 1,2,…,n1, 2, \ldots, n1,2,…,n 组成。

让 MEX(S,k)\text{MEX}(S, k)MEX(S,k) 为升序排列的第 kkk 个正(严格大于零)整数,该整数不存在于集合 SSS 中。将 MEOW(a)\text{MEOW}(a)MEOW(a) 表示为数组 aaa 的所有不同 子集 bbb 的 MEX(b,∣b∣+1)\text{MEX}(b, |b| + 1)MEX(b,∣b∣+1) 的总和。

集合的 MEX(S,k)\text{MEX}(S, k)MEX(S,k) 值示例:

  • MEX({3,2},1)=1\text{MEX}(\{3,2\}, 1) = 1MEX({3,2},1)=1 ,因为 111 是集合中不存在的第一个正整数;
  • MEX({4,2,1},2)=5\text{MEX}(\{4,2,1\}, 2) = 5MEX({4,2,1},2)=5 ,因为集合中不存在的前两个正整数是 333 和 555 ;
  • MEX({},4)=4\text{MEX}(\{\}, 4) = 4MEX({},4)=4 ,因为空集中没有数字,所以其中不存在的前 444 个正整数是 1,2,3,41, 2, 3, 41,2,3,4 。

分析:

我们考虑枚举集合的大小iii和最后的结果jjj,需要满足以下条件:

  • 集合中不能含有jjj

  • [1,j−1][1,j-1][1,j−1]区间内的数字需要取(j−i−1)(j-i-1)(j−i−1)个。

  • 如果集合大小还没满iii,就在[j+1,n][j+1,n][j+1,n]区间内取剩下的数字。

我们首先预处理出组合数,就可以进行计算。

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define endl '\n'
#define PII pair<LL, LL>
const int INF = 1e9;
const int mod = 1e9 + 7;
template <const int T>
struct ModInt
{
    const static int mod = T;
    int x;
    ModInt(int x = 0) : x(x % mod) {}
    ModInt(long long x) : x(int(x % mod)) {}
    int val() { return x; }
    ModInt operator+(const ModInt &a) const
    {
        int x0 = x + a.x;
        return ModInt(x0 < mod ? x0 : x0 - mod);
    }
    ModInt operator-(const ModInt &a) const
    {
        int x0 = x - a.x;
        return ModInt(x0 < 0 ? x0 + mod : x0);
    }
    ModInt operator*(const ModInt &a) const { return ModInt(1LL * x * a.x % mod); }
    ModInt operator/(const ModInt &a) const { return *this * a.inv(); }
    bool operator==(const ModInt &a) const { return x == a.x; };
    bool operator!=(const ModInt &a) const { return x != a.x; };
    void operator+=(const ModInt &a)
    {
        x += a.x;
        if (x >= mod)
            x -= mod;
    }
    void operator-=(const ModInt &a)
    {
        x -= a.x;
        if (x < 0)
            x += mod;
    }
    void operator*=(const ModInt &a) { x = 1LL * x * a.x % mod; }
    void operator/=(const ModInt &a) { *this = *this / a; }
    friend ModInt operator+(int y, const ModInt &a)
    {
        int x0 = y + a.x;
        return ModInt(x0 < mod ? x0 : x0 - mod);
    }
    friend ModInt operator-(int y, const ModInt &a)
    {
        int x0 = y - a.x;
        return ModInt(x0 < 0 ? x0 + mod : x0);
    }
    friend ModInt operator*(int y, const ModInt &a) { return ModInt(1LL * y * a.x % mod); }
    friend ModInt operator/(int y, const ModInt &a) { return ModInt(y) / a; }
    friend ostream &operator<<(ostream &os, const ModInt &a) { return os << a.x; }
    friend istream &operator>>(istream &is, ModInt &t) { return is >> t.x; }

    ModInt pow(int64_t n) const
    {
        ModInt res(1), mul(x);
        while (n)
        {
            if (n & 1)
                res *= mul;
            mul *= mul;
            n >>= 1;
        }
        return res;
    }

    ModInt inv() const
    {
        int a = x, b = mod, u = 1, v = 0;
        while (b)
        {
            int t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        if (u < 0)
            u += mod;
        return u;
    }
};
using mint = ModInt<1000000007>;
const int maxn = 5005;
mint C[maxn][maxn];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin >> T;
    for (int i = 0; i <= 5000; i++)
    {
        for (int j = 0; j <= i; j++)
        {
            if (!j)
            {
                C[i][j] = 1;
            }
            else
            {
                C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
            }
        }
    }
    while (T--)
    {
        int n;
        cin >> n;
        mint ans = 1;
        for (int i = 1; i <= n; i++)
        {
            for (int j = i + 1; j <= 2 * i + 1; j++)
            {
                int cnt = j - i - 1;
                mint t = j * C[min(j - 1, n)][cnt];
                if (n - j < 0)
                {
                    if (cnt != i)
                    {
                        t = 0;
                    }
                }
                else
                {
                    assert(n - j >= 0 and i - cnt >= 0);
                    t *= C[n - j][i - cnt];
                }
                ans += t;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

赛后交流

在比赛结束后,会在交流群中给出比赛题解,同学们可以在赛后查看题解进行补题。

群号: 704572101,赛后大家可以一起交流做题思路,分享做题技巧,欢迎大家的加入。

Dify 本地部署教程 到这里,Dify 就安装完成了,更多操作设置可以参考官方文档,Dify 和 FastGPT 基本上差不多,也可以同时安装一下 FastGPT 进行体验~Docker Compose 部署 | Dify。 阅读详情

相关推荐

电机控制必看!SVPWM谐波优化:5段式与7段式全参数对比测试

本文通过实测数据,对比分析了电机控制中5段式与7段式SVPWM控制算法的谐波性能。实验表明,7段式SVPWM在电流波形质量(THD)和低速性能上更优,而5段式SVPWM则在开关损耗和效率方面表现突出。文章为工程师在不同应用场景(如对噪音、效率或动态响应的侧重)下的算法选型提供了清晰的依据和实用的工程指南。

weixin_28331555的博客 178

Codeforces Round 957 (Div.3)

CF957

djhws144的博客 1071

使用Android GPS api 实现一个轨迹记录的小功能

引入 市场上的跑步软件已经是非常多了,如咕咚和悦跑圈还有其他,很多大厂也在涉足这个方面。而最简单的运动跑步,最近几年也因简单,不限场地,运动效果出众备受大众喜欢。 我的这篇文章的内容很多也是从网上学习其他的博客内容,外加利用android自身的提供的api实现的,希望能对有这方面需求的朋友有所帮助。 介绍 先上两张图,界面比较丑,不过一些数据基本都有了,这个图片是临时要用截取的,所以轨迹线很短,之前

尝试着去了解代码 1万+

Codeforces Round 957 赛后总结

Codeforces R957 (Div3) 赛后总结,赛时通过 4 题,赛后通过 7 题。Rating 加了 534 分。重点/有价值的题目:E、F、G。

m0_66401342的博客 2311

从3D相机数据到三维模型:Halcon实战深度图、亮度图与点云转换全流程

本文详细解析了如何利用Halcon将3D相机采集的深度图、亮度图转换为三维点云模型的完整流程。通过实战案例分享,涵盖数据格式处理、点云生成方法(SDK接口与纯Halcon实现)、三维模型可视化优化等关键技术,帮助工程师解决工业检测中的实际难题,提升三维重建精度与效率。

weixin_42525005的博客 396

2024年全国大学生电子设计竞赛H题_自动行驶小车

自动行驶小车(H题)【本科组/高职高专组】

qq_74395263的博客 1万+

Codeforces Round 957 (Div. 3) A-D

Codeforces Round 957 (Div. 3) A-D题解

2301_81058663的博客 436

Android 跨进程通信-(一)Binder概念引入

前言 主要对Android中的跨进程通信进行总结下,这篇先梳理下里面的涉及的一些概念 一 多进程 1.进程与线程 进程:系统中正在运行的一个应用程序,某个程序一旦运行就是一个进程,是资源分配的最小单位; 线程:程序执行的最小单位,包含在进程中,一个进程可以包含多个线程。 2.Android应用中的多进程 (1)dalivk虚拟机 Android系统的底层任务管理以及驱动都是基于Linux系统。一个Android系统其实就是一个Linux系统,通过adb shell进入连接的手机,就可以看到Li

nihaomabmt的专栏 1103

Codeforces Round 957

Codeforces Round 957

青少年趣味编程 720

手把手教你用Simulink搭建交流异步电机矢量控制模型(附完整仿真文件)

本文提供了一份详细的Simulink仿真指南,手把手教你从零开始搭建交流异步电机矢量控制模型。内容涵盖主电路搭建、坐标变换实现、双闭环PI调节器设计、转子磁链观测器调试等核心步骤,并附有完整的仿真文件,帮助读者跨越理论到实践的鸿沟,掌握高性能电机控制系统的建模与仿真技能。

pz890123的博客 665

深入浅出之CSPBlock模块(YOLO)

YOLO CSPX模块是YOLO系列算法中的一个重要组成部分,它通过跨阶段部分连接的方式减少了计算量,同时保证了模型的准确率。在YOLOv4及后续版本中,CSPX模块被广泛应用于主干网络和Neck结构中,为模型提供了强大的特征提取和融合能力。

浩瀚之水的专栏 6753

【Codeforces Round 957 (Div. 3)】

Codeforces Round 957 (Div. 3)补题

L1314049的博客 1382

YoloV10改进策略:卷积篇|基于PConv的二次创新|附结构图|性能和精度得到大幅度提高(独家原创)

在PConv的基础上做了二次创新,创新后的模型不仅在精度和速度上有了质的提升,还可以支持Stride为2的降采样。改进方法简单高效,需要发论文的同学不要错过!

m0_47867638的博客 1094

Codeforces Round 957 (Div. 3) D. Test of Love

这道题,我们初步看有点像模拟,模拟跳跃的整个过程,但会发现整个过程下来是比较麻烦的,我们考虑动态规划,dp[i] 是到达位置 i所需的 最小游泳距离,最后看看dp[n+1] 和 k 之间的大小关系即可。站在木点 i 上,你可以跳到 min⁡(n+1,i+j(0≤j≤m))min(n+1,i+j(0≤j≤m)) 上,可以跳入水中或者另一个木头,但是不能跳到鳄鱼上。如果这两种运动方式都无法到达 n+1 号点,或是经过了超过 k 个水点,则失败,反之成功。在水 i 上,你能且仅能到达 i+1 号点。

2302_79545206的博客 1339

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

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

廖雪峰Python教程[完整版]

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

Codeforces Round 957 (Div. 3 ABCDEFG题) 视频讲解

Codeforces Round 957 (Div. 3)(A ~ G 题视频讲解)

Edward Shi的博客 1211

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

Codeforces Round 957 (Div. 3)A——E题解

Codeforces Round 957 (Div. 3)

qq_50196144的博客 680

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

这次比赛只能用抽象来形容,前五道题都没有什么算法,都是思维加模拟都能过,然后第四题卡住了,第五题不知道为什么做出来的人那么少,就是纯暴力就能过,但是没抓住上分的机会,有些可惜,但是还好打完比赛把第四个重新补出来了,感觉大模拟的题还是不太擅长,以后可以练习一下。如果是水,判断水和下一个木头的位置,如果中间存在鳄鱼,那么也是不可能的,如果没有鳄鱼,则需要判断如果游泳,会不会超过k,如果总游泳没有超过k,则可以,更新old的first和second即可。每次选取出来三个数里面最小的一个加上1就可以。

2301_80475191的博客 2350

Codeforces Round 957 (Div. 3) A - E

【代码】Codeforces Round 957 (Div. 3) A - E。

Xyrsis的博客 308
上一篇: AtCoder Beginner Contest 364 A~F
下一篇: Codeforces Round 958 (Div. 2) A~E
AC-Panda
博客等级 码龄5年 1736粉丝 191原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值