【解题报告】Codeforces Round #401 (Div. 2)

deepfacelab下载安装及训练(小白篇),以及导出SAEHD为dfm文件,解决broken pipe问题 其中如果用的是RTX30系列显卡的话,需要把WIN10升级到20H4或更新版本,然后打开硬件加速,不然会出现训练时一直卡在第一个迭代不动了,我的服务器版本为22H2,符合。支持WIN10,win11,WIN7,LINUX,不支持mac(因为mac不支持NVIDIA显卡) 阅读详情

题目链接


A. Shell Game(Codeforces 777A)

思路

为了更好地找到解题关键,先将小球随杯子运动的轨迹画在纸上。具体地,假设初始状态球在杯子 1 中。在纸上画一个数组 d ,其中 d[i] 表示当杯子被移动 i 次时,小球的位置。不难发现, d[i] 随 i 的增大呈现出周期性,其周期为 6 。对任意初始状态都可以画出这种数组。
于是我们用二维数组 d[i][j] 表示初始状态下小球在杯子 i 中,当杯子被移动了 j 次时小球的位置。对任意输入 n ,枚举i使得 d[i][n]=x ,那么 i 就是答案。

代码

#include <bits/stdc++.h>
using namespace std;

int n, x;
int d[3][6] = { {0, 1, 2, 2, 1, 0},
        {1, 0, 0, 1, 2, 2},
        {2, 2, 1, 0, 0, 1} };

int main() {
//  freopen("data.txt", "r", stdin);
    cin >> n >> x;
    n = n % 6;
    for(int i = 0; i < 3; i++) {
        if(d[i][n] == x) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}

B. Game of Credit Cards(Codeforces 777B)

思路

首先这个数据规模暴力肯定是不行了。那么潜在的,可能有贪心策略也可能是动态规划。那么先考察有没有贪心策略。因为两个字符串的序对本题是没有影响的(因为M已经知道S的出牌顺序)。因此考虑对两个字符串进行排序。我们分两种策略来考虑:

  • 被 S 攻击的最少次数。假设我们是 M ,那么我们的目标是让对方的牌尽可能不发挥作用。我们从当前 S 的点数最大的 S[i] 这儿考虑。为了让 S[i] 哑火,我们可以拿出最大的 M[j] 来压制它。这样为什么是最好的呢?因为如果 M[j] 都压不住它,那么也没有牌能够压住它了。况且如果此时不用 M[j] ,有什么理由以后再用它呢?有人可能会反驳:能不能放弃压制 S[i] ,把 M[j] 留到后面用呢?假如这样做,那么最好的情况是结果不变,最差的情况是结果变大了(也就是次优解)。因此我们按照点数从大到小枚举 S[i] ,用当前最大的牌来压制对方即可。

    • 攻击 S 的最多次数。假设我们是 M ,那我们的目标是让我们的牌尽可能发挥作用。那么我们从 M 的点数最大的 M[j] 这儿考虑。为了让 M[j] 发挥最大效果,我们选择比 M[j] 小的(或相等的)最大的 S[i] 下手。因为对于任意满足 S[k]≤S[i] 的 k ,都存在 S[k]≤M[j] ,那么将 M[j] 用在 S[i] 上最利于我方的后来的牌的发挥。我们同样可以从大到小枚举 S[j] ,用当前最大的牌来压制对方。
    • 代码

      #include <bits/stdc++.h>
      using namespace std;
      
      const int maxn = 1010;
      char S[maxn], M[maxn];
      int n, Max, Min;
      
      int main() {
      //  freopen("data.txt", "r", stdin);
          scanf("%d%s%s", &n, S, M);
          sort(S, S + n);
          sort(M, M + n);
          int j = n - 1;
          for(int i = n - 1; i >= 0; i--) {
              if(S[i] > M[j]) {
                  Min++;
              }
              else {
                  j--;
              }
          }
          j = n - 1;
          for(int i = n - 1; i >= 0; i--) {
              if(S[i] < M[j]) {
                  Max++;
                  j--;
              }
          }
          printf("%d\n%d\n", Min, Max);
          return 0;
      }

      C. Alyona and Spreadsheet(Codeforces 777C)

      思路

      对于这题,不少人都能够立即想到暴力的解法:对于每列 j ,检查行区间 [l,r] 中的每行,看看这些行是不是在 j 列上单调不减。这是不错的想法,但是时间复杂度太大了,达到了 O(nm+n+m) 。
      事实上,这种要对矩阵进行某种统计,暴力解复杂度太大的题,多半是要维护某种神奇的量,使得我们只用枚举行或枚举列就能完成这种统计。话说 CF 出这种题已经不是一次两次了。
      那么这题怎么样呢?我们可以事先统计 d[j][i] ,表示以 i 行 j 列的元素 aij 为终点的最长上升子串(注意是子串而不是子序列)的长度为多少。此时原问题就转化成

      对于第 r 行,是否存在一个 j ,使得 r−d[j][r]+1≤l 。

      不等式左边的式子表示以 r 为区间右端点 d[j][r] 为区间长度的区间左端点的编号(也就是本题的行号)是多少。将式子变形后问题转化成

      是否存在一个 j ,使得 d[j][r]≥r−l+1 。

      显然这个问题就是在问

      max{d[j][r]}≥r−l+1 是否成立。

      那么对于每个 r ,维护 d[j][r] 的最大值即可。这既是我前面所说的神奇的量。

      最后,实现上需要注意一个细节。因为题目只说 n×m≤105 ,所以理论上说 n,m 都有可能达到 105 。在存矩阵的时候如果用二维数组的话会超内存限制。所以得采用类似图论中邻接表的数据结构才能存下。

      代码

      #include <bits/stdc++.h>
      using namespace std;
      
      const int maxn = 1e5 + 10;
      vector <int> a[maxn], d[maxn];
      int n, m, k, l, r, num, Max[maxn];
      
      int main() {
      //  freopen("data.txt", "r", stdin);
          scanf("%d%d", &n, &m);
          // 输入并存储矩阵
          for(int i = 1; i <= n; i++) {
              a[i].push_back(0);
              for(int j = 1; j <= m; j++) {
                  scanf("%d", &num);
                  a[i].push_back(num);
              }
          }
          for(int j = 1; j <= m; j++) {
              d[j].push_back(0);
              d[j].push_back(1);
          }
          // 对每列计算以某个元素结尾的最长不下降子串
          for(int j = 1; j <= m; j++) {
              for(int i = 2; i <= n; i++) {
                  if(a[i][j] >= a[i-1][j]) {
                      d[j].push_back(d[j][i-1] + 1);
                  }
                  else {
                      d[j].push_back(1);
                  }
              }
          }
          // 统计每行的列最长不下降子串的最大值
          for(int i = 1; i <= n; i++) {
              for(int j = 1; j <= m; j++) {
                  Max[i] = max(Max[i], d[j][i]);
              }
          }
          // 回答查询
          scanf("%d", &k);
          while(k--) {
              scanf("%d%d", &l, &r);
              puts(r - Max[r] + 1 <= l ? "Yes" : "No");
          }
          return 0;
      }

      D. Cloud of Hashtags(Codeforces 777D)

      思路

      这题从数据规模和“字典序”这个这么强的条件来看,可能存在贪心策略。首先从先往后考虑,结果是没什么结果。那么从后往前考虑呢?首先,对于一个字符串,我们删除它的后缀只会让它的字典序变小而不是变大。那么,对于倒数第一个串 s[n] 和倒数第二个串 s[n−1] ,如果字典序 s[n]<s[n−1] ,那么我们对 s[n] 做任何事情都于事无补,但可以删除 s[n−1] 的后缀。
      从这个灵感不难得出贪心算法:我们从第一位开始逐位比较两个字符串 s[i] 和 s[i−1] 。

      • 如果出现某位j使得 s[i][j]>s[i−1][j] ,那么一切顺利。
      • 如果出现某位j使得 s[i][j]<s[i−1][j] ,那么从 j 开始的 s[i−1] 的后缀要全部删除掉。
      • 如果一直是 s[i][j]==s[i−1][j] 直到某个串被遍历完,那么只需要 s[i] 的长度大于或等于 s[i−1] 的长度即可。

      代码

      #include <bits/stdc++.h>
      using namespace std;
      
      const int maxn = 5e5 + 10;
      string s[maxn];
      bool equ;
      int n, p1, p2;
      
      int main() {
      //  freopen("data.txt", "r", stdin);
          ios::sync_with_stdio(false);
          cin.tie(0);
          cin >> n;
          for(int i = 1; i <= n; i++) {
              cin >> s[i];
          }
          for(int i = n - 1; i >= 1; i--) {
              equ = true;
              p1 = p2 = 0;
              while(true) {
                  if(s[i+1][p1] < s[i][p2]) {
                      if(true == equ) {
                          s[i] = s[i].substr(0, p2);
                      }
                      break;
                  }
                  if(s[i+1][p1] > s[i][p2]) {
                      equ = false;
                  }
                  if(++p2 >= s[i].size()) {
                      break;
                  }
                  if(++p1 >= s[i+1].size()) {
                      if(true == equ) {
                          s[i] = s[i].substr(0, p2);
                      }
                      break;
                  }
              }
          }
          for(int i = 1; i <= n; i++) {
              cout << s[i] << endl;
          }
          return 0;
      }

      E. Hanoi Factory(Codeforces 777E)

      思路

      这题显然不是贪心能够解决的(很难找到某个顺序进行某种贪心策略)。考虑动态规划。我们需要有一个“序”来让动规满足“无后效性”。根据题目的特点先按照外径从大到小对 ring 排序,当外径相等时按照内径从大到小排序(相当于排在前面的一定放在下面)。这时候就可以设计动态规划算法了。
      令状态 i 表示当前考虑到 ringi 这个物品,且 ringi 是放在塔顶的物品, d[i] 表示状态 i 下的最优解。若某个状态 j 可以转移到状态 i ,那么物品 ringi 的外径一定要严格小于 ringj 的外径,且物品 ringi 的外径一定要严格大于 ringj 的内径,用方程来描述状态转移过程中最优解的变化有( a,b,h 数组分别存放内径,外径和高度)

      d[i]=max{d[j],j<i,b[i]>a[j]}

      这看上去会是一个 O(n2) 的算法。让我们来尝试优化它(所以一定要熟悉动态规划及其优化技巧,这样才能自信认为这样的优化会奏效)。根据 j<i 这个信息。我们可以开一个数组 data[] ,假设我们处理到状态 i 了, data[k] 表示在状态 i 之前出现过的内径为 k 的物品在塔的最顶端时的最优解。那么我们就可以通过区间最大值查询 RMQ(1,b[i]−1) ,来得知 max{d[j],j<i,b[i]>a[j]} (相当于不需要知道 j ,而直接知道了 d[j] ),从而更新 d[i] ,然后通过 d[i] 来更新 data[a[i]] 。那么这有什么用呢?将问题逐步变形至此有什么好处呢?答案是,动态的 RMQ 以及修改元素是可以用线段树在 O(logn) 的时间内完成的(需要对内径离散化)。只要将 data 数组用线段树维护起来就好了。这样,本题的复杂度达到了 O(nlogn) ,这是可以接受的。

      代码

      #include <bits/stdc++.h>
      using namespace std;
      
      #define lch (k << 1)
      #define rch (k << 1 | 1)
      #define mid ((l + r) >> 1)
      
      typedef long long ll;
      const int maxn = 2e5 + 10;
      map <int, int> mp;
      int n, a, b, h, m, foo[maxn], bar[maxn];
      ll d, tmp, ans;
      
      // 排序用的ring结构体
      struct ring {
          int a, b, h;
          ring() {}
          ring(int a, int b, int h):a(a), b(b), h(h) {}
          bool operator < (const ring& o) const {
              if(b == o.b) {
                  return a > o.a;
              }
              return b > o.b;
          }
      }rings[maxn];
      
      // 线段树
      template <class T>
      struct Tree {
          T data[maxn<<2];
          T operate(T x, T y) {
              return max(x, y);
          }
          void pushUp(int k) {
              data[k] = operate(data[lch], data[rch]);
          }
          // 建树
          void build(int k, int l, int r) {
              if(l == r) {
                  data[k] = 0;
                  return;
              }
              build(lch, l, mid);
              build(rch, mid + 1, r);
              pushUp(k);
          }
          // 修改
          void update(int a, T v, int k, int l, int r) {
              if(l == r) {
                  data[k] = v;
                  return;
              }
              if(a <= mid) {
                  update(a, v, lch, l, mid);
              }
              else {
                  update(a, v, rch, mid + 1, r);
              }
              pushUp(k);
          }
          // 查询
          T query(int a, int b, int k, int l, int r) {
              if(a <= l && r <= b) {
                  return data[k];
              }
              ll res = 0;
              if(a <= mid) {
                  res = operate(res, query(a, b, lch, l, mid));
              }
              if(b > mid) {
                  res = operate(res, query(a, b, rch, mid + 1, r));
              }
              return res;
          }
      };
      
      Tree <ll> o;
      
      // 离散化
      int dec(int a[], int b[], int n, map <int, int>& mp) {
          copy(a + 1, a + n + 1, b + 1);
          sort(b + 1, b + n + 1);
          int m = unique(b + 1, b + n + 1) - b - 1;
          for(int i = 1; i <= n; i++) {
              mp[a[i]] = lower_bound(b + 1, b + m + 1, a[i]) - b;
          }
          return m;
      }
      
      int main() {
      //  freopen("data.txt", "r", stdin);
          scanf("%d", &n);
          for(int i = 1; i <= n; i++) {
              scanf("%d%d%d", &a, &b, &h);
              rings[i] = ring(a, b, h);
              foo[i] = a;
              foo[n + i] = b;
          }
          // 离散化
          m = dec(foo, bar, 2 * n, mp);
          o.build(1, 1, m);
          sort(rings + 1, rings + n + 1);
          for(int i = 1; i <= n; i++) {
              a = rings[i].a;
              b = rings[i].b;
              h = rings[i].h;
              // 查询d[j]
              if(mp[b] >= 2) {
                  d = o.query(1, mp[b] - 1, 1, 1, m) + h;
              }
              else {
                  d = h;
              }
              // tmp相当于d[i]
              tmp = o.query(mp[a], mp[a], 1, 1, m);
              // 将d[i]插入线段树
              if(d > tmp) {
                  o.update(mp[a], d, 1, 1, m);
              }
              // 用d[i]更新答案
              ans = max(ans, d);
          }
          printf("%I64d\n", ans);
          return 0;
      }

vue2/3 - H5 移动端网页中调用手机摄像头扫描二维码 / 条形码功能,在h5手机网页里调起相机摄像头进行二维码或条形码扫描效果详细教程(详细示例组件源码,一键复制开箱即用!) vue扫描二维码条形码,vue网页调用摄像头扫二维码条形码,vue移动端如何实现调用相机扫描二维码,vue移动端扫一扫功能,vue怎么做移动端h5扫一扫功能,vue识别二维码和条形码,vue实现点击按钮调用摄像头扫码,vue调用本地摄像头实现拍照功能,Vue中如何进行二维码生成与扫描,如何实现vue在手机浏览器中调用摄像头实现扫描二维码功能,VUE项目移动端H5调用摄像头扫码,vue项目中实现H5调取摄像头,网页调用摄像头实现二维码扫描功能,vue调用手机摄像头,vue在调用摄像头扫码,vue自定义打开摄像 阅读详情

相关推荐

帆软 finereport FCRA 考试 题库+答案,共收录561题,大部分有答案

帆软 finereport FCRA 考试 题库+答案,共收录561题,大部分有答案 入门基础 11.多选题 以下方式中属于FineReport中预览模式的有( ) 分页预览、填报预览、新填报预览、数据分析、移动端预览 16.判断题 FineReport报表工具必须购买激活码后才能使用。 错误,可以免费获取激活码。 29.单选题 FineReport是一款利用( )语言开发的报表工具。java 41.多选题 访问帮助文档的方式有哪些?设计器中社区菜单下-帮助文档;直接访问http://help.finere

qq_37485720的博客 2万+

codeforces-401c

#include"iostream" #include"algorithm" #include"vector" #include"stack" #include"queue" #include"map" #include"cstring" #include"cstdio" using namespace std; int n[200005]; int

mengyinhu123的博客 254

单细胞分析实战:用R语言绘制带连线的堆叠柱状图(附完整代码)

本文详细介绍了如何使用R语言绘制带连线的堆叠柱状图进行单细胞转录组数据分析,特别适用于展示细胞比例变化趋势。通过完整代码示例和实战技巧,帮助研究者优化多组别比较的可视化效果,提升科研图表质量。

yhn4567890的博客 393

Codeforces 401C 题解

题意简述 构造一个01序列,使得这个序列中连续的0长度小于2,连续的1长度小于3,并且有n个0,m个1。(有SPJ,构造一个即可)。没有解输出-1。n,m&lt;=1000000n,m&lt;=1000000n,m<=1000000 数据 输入 1 2 输出 101 输入 4 8 输出 110110110101 输入 4 10 输出 11011011011011 输入 1 5...

LightningUZ的博客 381

ARM架构福音:在飞腾FT-2000/4开发板上,用Clonezilla Live 2.6.6-11给麒麟V10系统做个‘快照’

本文详细介绍了在飞腾FT-2000/4开发板上使用Clonezilla Live 2.6.6-11为麒麟V10系统创建备份的完整方案。针对ARM架构的特殊挑战,提供了从工具准备到备份执行的全流程指南,包括镜像获取、U盘制作、备份配置及性能优化技巧,帮助用户实现高效可靠的系统备份。

weixin_30889885的博客 611

TMS-EEG数据预处理:eeglab工具包TESA(一)

b. 自动选择:Tools -> Reject data epochs -> Reject by probability,然后进行Plot -> channel,进行删除。TMS-EEG(经颅磁刺激-脑电图)是一种结合了TMS和EEG记录的技术,这种技术允许研究者在非侵入的情况下探测大脑环路,评估大脑的兴奋性和连通性等皮层特性。对移除脉冲伪迹的数据进行插值:Tools ->TESA -> Interpolate removed data;插值后,画图查看:数据会有数值;

weixin_43604817的博客 1503

【Codeforces】401C Team (01010110...)

http://codeforces.com/contest/401/problem/C 题目中,n表示0的个数,m表示1的个数,要求两个0不能连续,三个1不能连续 还要判断能否输出满足要求的序列,不满足输出-1 满足条件以后徐瑶分情况讨论 当1比0多,且0的个数不为零; 当1的个数等于0的个数; 当1的个数小于0的个数,且1最多只能比0少一个,否则就无法输出。 #include &...

( :3 ) 293

合规批量下载美国上市公司年报数据的一些经验和总结

本文总结了使用Python脚本批量下载和处理美国上市公司SEC报告的技术经验。通过CIK代码查询SEC EDGAR系统,生成特定日期和报告类型的URL,并使用Selenium和Requests库下载报告内容。流程包括数据获取、文件下载、Excel处理和多线程优化,确保高效处理几百条数据。关键技术挑战包括SEC访问限制、动态网页内容和数据完整性,解决方案包括设置合规的User-Agent、使用Selenium模拟浏览器行为以及错误日志记录。最佳实践包括模块化设计、多线程优化和严格遵守SEC合规性。该自动化流程

jyfool的博客 1644

CodeForces 401C Team

Team Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u  Description Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming

yu_ming_cong的专栏 469

金融行业大数据可视化:实时监控与风险预警系统构建

随着金融业务数字化转型,日均产生的交易数据、市场数据、客户行为数据呈指数级增长(单家银行日交易数据量可达TB级)。数据实时性不足(分钟级延迟难以应对高频交易风险)风险特征挖掘浅层(仅基于规则引擎,漏报率高达30%+)可视化分析能力薄弱(静态报表无法支持动态决策)本文聚焦构建具备毫秒级数据响应智能风险建模交互式可视化决策能力的新一代系统,覆盖数据采集、实时处理、多维可视化、智能预警四大核心模块,适用于银行、证券、保险等金融细分领域。章节核心内容技术亮点核心概念可视化系统架构/数据流模型。

AI天才研究院 1529

部署模型:Libtorch使用笔记【Pytorch的C++版本】【把用Pytorch训练好的模型打包保存为.pt格式,使用Libtorch去加载.pt格式模型,在C++工程中去用就好了】

A : Libtorch是pytorch的C++版本,现在的很多大型项目都是用C++写的,想使用训练好的模型,需要通过caffe等方式去集成,比较麻烦。这里pytorch官方提出了Libtorch,我们就可以把pytorch训练好的模型,打包起来,直接在C++工程中去用就好了,相比较caffe等,非常方便!虽然对于许多需要动态性和易迭代性的场景来说,Python是一种合适且首选的语言,但在同样的情况下,Python的这些特性恰恰是不利的。生产环境是一个需要低延迟和有严格部署要求的领域,一般选择C++。

u013250861的博客 2952

Codeforces Round #401 (Div. 2) C Alyona and Spreadsheet —— 打表

题目链接:http://codeforces.com/contest/777/problem/C C. Alyona and Spreadsheet time limit per test 1 second memory limit per test 256 megabytes input standard input ...

alince20008的博客 164

PCB板设置20H 原则理解

20H原则是PCB设计中抑制EMI辐射的关键方法,要求电源层比相邻地层内缩20倍介质厚度(20H)。在四层板中实现20H原则需采用S-G-P-S层叠结构,确保GND与PWR紧邻。具体步骤包括:确定GND-PWR间介质厚度H,计算20H值(通常80-120mil),并在设计软件中将电源层四周内缩20H,同时保持地层完整不内缩。注意避免常见误区,如混淆介质厚度、地层内缩等。该原则能有效限制边缘场辐射,降低EMI干扰,是四层板EMC设计的重要规范。

qq_37999850的博客 707

Codeforces Round #401 (div. 2)解题报告

Problem A-Shell Game 找规律 6个一组 //Author: Lixiang #include struct Shell_Game{ int N,X; void init(){ scanf("%d%d",&N,&X); } int getans(){ switch(N%6){ case 0: if(X==0)return 0; if(X=

理想之国 518

visio安装包

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

深度学习工具包 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 #401 (Div. 2)解题报告

A - Shell Game 1 #include <iostream> 2 #include<bits/stdc++.h> 3 #include <stack> 4 #include <queue> 5 #include <map> 6 #include <set> 7 #include ...

weixin_30727835的博客 131

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

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

Codeforces Round #401 (Div. 2) 第一套。 刷100套cf,加油加油!!! ps:写题解时没看题,题意可能有错 A:Shell Game 题意:三个杯子,其中一个下面有东西,操作:先交换左和中间,再交换右和中间。给出n次操作后的状态,东西在x(0,1,或2)位置,让你求出初始东西在哪个位置。 0 1 2 1 0 2 1 2 0 2 1 ...

ailei7251的博客 231

老版QQ原生表情gif动态

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

Codeforces Round #713 (Div. 3)-C. A-B Palindrome-题解

目录Codeforces Round #713 (Div. 3)-C. A-B PalindromeProblem DescriptionInputOutputSample InputSample Onput题目大意解题思路AC代码 Codeforces Round #713 (Div. 3)-C. A-B Palindrome 传送门 Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description You are given a

<font color="Pink">Tisfy的博客</font> 1万+

Codeforces Round #401 (Div. 2)C. Alyona and Spreadsheet

Codeforces Round #401 (Div. 2)C. Alyona and Spreadsheet 看代码  一种新的思想 dp 以每行 #include using namespace std; const int MAXN=100010; int n,m,a[MAXN],last[MAXN],h[MAXN],k; int main() { scanf("%d%d"

liyanfeng1996的博客 342

Codeforces Round #401 (Div. 2)

Codeforces Round #401 (Div. 2)    很happy,现场榜很happy,完全将昨晚的不悦忘了。终判我校一片惨白,小董同学怒怼D\E,离AK就差一个C了,于是我AC了C题还剩35分钟立刻开D题,不料英文苦涩难懂,懂了题意之后发现也是个水题,从后往前遍历一遍即可。然而代码速度和思维都不算很好,还有半分钟在徘徊要不要测一下样例,但又怕OJ卡了,直接交第一组就跪了,然后发现

NYIST_TC_LYQ的博客 741

Codeforces Round #401 (Div. 2) A~E

http://codeforces.com/contest/777  (Codeforces Round #401 (Div. 2) ) 好的嘛,最简单的一次cf,也是做的最差的一次 abc大数据全挂。。。。。。。。。。。 A.是那个状态数组少写一个。。在纸上写对了 #include #include #include #include #include #include #i

jerans的博客 290

Codeforces Round #401 (Div. 2) 【结题报告】

总结下, 看题慢,读错题,代码能力渣,思维不敏捷,菜的一逼。Shell Game————————————————————————————————————————————傻逼题,, 明确题意 枚举下所有情况 就能AC了。。int main(){ int n,x; scanf("%d",&n); scanf("%d",&x); n%=6; if(x==0){

Tabris的博客 508

Codeforces Round #235 (Div. 2)

500pt: 题目链接:http://codeforces.com/problemset/problem/401/A A. Vanya and Cards time limit per test 1 second memory limit per test 256 megabytes input standard input output

wangyuquanliuli的专栏 1379

Codeforces Round #401 (div.2)

自己的号2000+了....临时找了一个1540的号,和一个大佬@ditoly一起打... 这是大佬↓ 迟到了一下,过了十分钟才报名..... A....... B.你有n个数,对面也有n个数,两两对决!!! 求最多大于对面的数多少场,大等于对面的数多少场。 直接贪心 #include<iostream> #include<cstdio> #...

weixin_30532987的博客 128

Codeforces Round #401 (Div. 2) 离翻身就差2分钟

Codeforces Round #401 (Div. 2) 很happy,现场榜很happy,完全将昨晚的不悦忘了。终判我校一片惨白,小董同学怒怼D\E,离AK就差一个C了,于是我AC了C题还剩35分钟立刻开D题,不料英文苦...

weixin_30869099的博客 131

Codeforces Round #235 (Div. 2) C Team 构造法

题目链接:http://codeforces.com/contest/401/problem/C 题目大意:输入两个整数n,m。n代表0的个数,m代表1的个数。要求输出一串数字(只包含0与1),且0不能相邻,三个1不能连续。如果无解则输出-1. 解题思路: 先判断无解的状态,当这串数字是这样的时候:11011011.....011  此时的0的个数是最少的,即2*n+2==m,化简得到:2*

Just do IT! 750
上一篇: 【解题报告】Codeforces Round #395 (Div. 2)
下一篇: 【解题报告】ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)
TRiddle
博客等级 码龄11年 14粉丝 71原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值