codeforces712

聚类教程:cisTopic——来自单细胞表观基因组学数据的顺式调控主题的概率建模 之前运行这步的时候报错了如下: 后来发现原因是Ubuntu自动把R包更新到4.2版本,但是Rstudio版本没有更新,更新Rstudio即可,更新Rstudio的教程看此教程:。 阅读详情

There are n integers b1, b2, …, bn written in a row. For all i from 1 to n, values ai are defined by the crows performing the following procedure:

The crow sets ai initially 0.
The crow then adds bi to ai, subtracts bi + 1, adds the bi + 2 number, and so on until the n’th number. Thus, ai = bi - bi + 1 + bi + 2 - bi + 3….
Memory gives you the values a1, a2, …, an, and he now wants you to find the initial numbers b1, b2, …, bn written in the row? Can you do it?

Input
The first line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of integers written in the row.

The next line contains n, the i’th of which is ai ( - 109 ≤ ai ≤ 109) — the value of the i’th number.

Output
Print n integers corresponding to the sequence b1, b2, …, bn. It’s guaranteed that the answer is unique and fits in 32-bit integer type.

Example
Input
5
6 -4 8 -2 3
Output
2 4 6 1 3
Input
5
3 -2 -1 5 6
Output
1 -3 4 11 6
Note
In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and  - 4 = 4 - 6 + 1 - 3.

In the second sample test, the sequence 1,  - 3, 4, 11, 6 satisfies the reports. For example, 5 = 11 - 6 and 6 = 6.

本题水题,直接推一发。

#include<bits/stdc++.h>
using namespace std;
#define N 1000001
int a[N];
int n;
int b[N];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    b[n]=a[n];
    for(int i=n-1;i>=1;i--)
    {
        b[i]=a[i]+a[i+1];
    }
    for(int i=1;i<=n;i++) cout<<b[i]<<" ";
}

Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string s with his directions for motion:

An ‘L’ indicates he should move one unit left.
An ‘R’ indicates he should move one unit right.
A ‘U’ indicates he should move one unit up.
A ‘D’ indicates he should move one unit down.
But now Memory wants to end at the origin. To do this, he has a special trident. This trident can replace any character in s with any of ‘L’, ‘R’, ‘U’, or ‘D’. However, because he doesn’t want to wear out the trident, he wants to make the minimum number of edits possible. Please tell Memory what is the minimum number of changes he needs to make to produce a string that, when walked, will end at the origin, or if there is no such string.

Input
The first and only line contains the string s (1 ≤ |s| ≤ 100 000) — the instructions Memory is given.

Output
If there is a string satisfying the conditions, output a single integer — the minimum number of edits required. In case it’s not possible to change the sequence in such a way that it will bring Memory to to the origin, output -1.

Example
Input
RRU
Output
-1
Input
UDUR
Output
1
Input
RUUR
Output
2
Note
In the first sample test, Memory is told to walk right, then right, then up. It is easy to see that it is impossible to edit these instructions to form a valid walk.

In the second sample test, Memory is told to walk up, then down, then up, then right. One possible solution is to change s to “LDUR”. This string uses 1 edit, which is the minimum possible. It also ends at the origin.

B题就是记录对立方向的差的和,为奇数不可能,为偶数除以2输出,即可。

using namespace std;
#include<bits/stdc++.h>
#define N 1000001
char it[N];
int n,m;
int dir[128];
int main()
{
    scanf("%s",it+1);
    int len=strlen(it+1);
    if(len%2==1){puts("-1");return 0;}
    for(int i=1;i<=len;i++) dir[it[i]]++;
    int l=dir['L'],r=dir['R'],u=dir['U'],d=dir['D'];
    int k=abs(l-r)+abs(u-d);
    cout<<k/2<<endl;
}

Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.

In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.

What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?

Input
The first and only line contains two integers x and y (3 ≤ y < x ≤ 100 000) — the starting and ending equilateral triangle side lengths respectively.

Output
Print a single integer — the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.

Example
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do .

In the second sample test, Memory can do .

In the third sample test, Memory can do:

.

三角形的贪心,使每次最大的边最大,只要有一条到了目标,其他两条两次就能到

using namespace std;
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
int x[4];
int y[4];
int st,en;
int step;
int MAX(int xx,int yy,int zz)
{
    return max(max(xx,yy),zz);
}
int main()
{
    cin>>st>>en;
    if(st<en) swap(st,en);
    if(st==en){puts("0");return 0;}
    if(st<en*2) {puts("3");return 0;}
    x[1]=en;x[2]=en;x[3]=en;
    while(MAX(x[1],x[2],x[3])<st)
    {
        step++;
        int t1=x[1],no=1;
        for(int i=2;i<=3;i++)
        {
            if(x[i]<t1)
            {
                t1=x[i];no=i;
            }
        }
        x[no]=x[1]+x[2]+x[3]-x[no]-1;
    }
    cout<<step+2<<endl;
}

Memory and his friend Lexa are competing to get higher score in one popular computer game. Memory starts with score a and Lexa starts with score b. In a single turn, both Memory and Lexa get some integer in the range [ - k;k] (i.e. one integer among  - k,  - k + 1,  - k + 2, …,  - 2,  - 1, 0, 1, 2, …, k - 1, k) and add them to their current scores. The game has exactly t turns. Memory and Lexa, however, are not good at this game, so they both always get a random integer at their turn.

Memory wonders how many possible games exist such that he ends with a strictly higher score than Lexa. Two games are considered to be different if in at least one turn at least one player gets different score. There are (2k + 1)2t games in total. Since the answer can be very large, you should print it modulo 109 + 7. Please solve this problem for Memory.

Input
The first and only line of input contains the four integers a, b, k, and t (1 ≤ a, b ≤ 100, 1 ≤ k ≤ 1000, 1 ≤ t ≤ 100) — the amount Memory and Lexa start with, the number k, and the number of turns respectively.

Output
Print the number of possible games satisfying the conditions modulo 1 000 000 007 (109 + 7) in one line.

Example
Input
1 2 2 1
Output
6
Input
1 1 1 2
Output
31
Input
2 12 3 1
Output
0
Note
In the first sample test, Memory starts with 1 and Lexa starts with 2. If Lexa picks  - 2, Memory can pick 0, 1, or 2 to win. If Lexa picks  - 1, Memory can pick 1 or 2 to win. If Lexa picks 0, Memory can pick 2 to win. If Lexa picks 1 or 2, Memory cannot win. Thus, there are 3 + 2 + 1 = 6 possible games in which Memory wins.

前缀和优化DP,下次遇到一段连一起的,一定要考虑这种算法!
dp用k次取x的方案数

using namespace std;
#include<bits/stdc++.h>
#define LL long long
#define N 200666
LL dance[101][N+5];
LL res;
LL S[N+5];
LL a,b,k,t;
const LL mod=1e9+7;
#define F(i,a,b) for(int i=a;i<=b;i++)
int fire;
int main()
{
    cin>>a>>b>>k>>t;
    dance[0][0]=1;
    fire=0;
    F(i,1,t)
    {
        fire^=1;
        S[0]=dance[fire^1][0]%mod+mod;
        S[0]%=mod;
        F(j,1,N)
        {
            S[j]=S[j-1]+dance[fire^1][j]+mod;
            S[j]=S[j]%mod;
        }
        dance[fire][0]=dance[fire^1][0]+mod;
        dance[fire][0]%=mod;
        F(j,1,N)
        {
            int kk=j-2*k-1;
            LL it=0;
            if(kk<0) it=0;else it=S[kk];
            dance[fire][j]=S[j]-it+mod;
            dance[fire][j]=dance[fire][j]%mod;
        }
    }
//  for(int i=1;i<=t;i++){cout<<endl;for(int j=1;j<=20;j++)cout<<dance[i][j]<<endl;}
    S[0]=dance[fire][0]+mod;S[0]%=mod;
    F(i,1,N)
    {
        S[i]=S[i-1]+dance[fire][i]+mod;
        S[i]%=mod;
    }
    LL hh=b-a;
    F(i,0,N)
    {
        LL fi=i-hh-1;LL it;
        LL dd=1;
        if(fi<0) it=0;else it=S[fi]%mod;
        res+=dd*it*dance[fire][i];
        res=res%mod;
    }
    cout<<res;
}

There are n casinos lined in a row. If Memory plays at casino i, he has probability pi to win and move to the casino on the right (i + 1) or exit the row (if i = n), and a probability 1 - pi to lose and move to the casino on the left (i - 1) or also exit the row (if i = 1).

We say that Memory dominates on the interval i… j if he completes a walk such that,

He starts on casino i.
He never looses in casino i.
He finishes his walk by winning in casino j.
Note that Memory can still walk left of the 1-st casino and right of the casino n and that always finishes the process.

Now Memory has some requests, in one of the following forms:

1 i a b: Set .
2 l r: Print the probability that Memory will dominate on the interval l… r, i.e. compute the probability that Memory will first leave the segment l… r after winning at casino r, if she starts in casino l.
It is guaranteed that at any moment of time p is a non-decreasing sequence, i.e. pi ≤ pi + 1 for all i from 1 to n - 1.

Please help Memory by answering all his requests!

Input
The first line of the input contains two integers n and q(1 ≤ n, q ≤ 100 000), — number of casinos and number of requests respectively.

The next n lines each contain integers ai and bi (1 ≤ ai < bi ≤ 109) — is the probability pi of winning in casino i.

The next q lines each contain queries of one of the types specified above (1 ≤ a < b ≤ 109, 1 ≤ i ≤ n, 1 ≤ l ≤ r ≤ n).

It’s guaranteed that there will be at least one query of type 2, i.e. the output will be non-empty. Additionally, it is guaranteed that p forms a non-decreasing sequence at all times.

Output
Print a real number for every request of type 2 — the probability that boy will “dominate” on that interval. Your answer will be considered correct if its absolute error does not exceed 10 - 4.

Namely: let’s assume that one of your answers is a, and the corresponding answer of the jury is b. The checker program will consider your answer correct if |a - b| ≤ 10 - 4.

Example
Input
3 13
1 3
1 2
2 3
2 1 1
2 1 2
2 1 3
2 2 2
2 2 3
2 3 3
1 2 2 3
2 1 1
2 1 2
2 1 3
2 2 2
2 2 3
2 3 3
Output
0.3333333333
0.2000000000
0.1666666667
0.5000000000
0.4000000000
0.6666666667
0.3333333333
0.2500000000
0.2222222222
0.6666666667
0.5714285714
0.6666666667

一道期望的题,转化区间转化的很好,Annox给我的解很好,很易懂。
这里写图片描述

这里写图片描述
大致思路就是这样的

//把l当成1号节点的方法实在是太妙了 
using namespace std;
#include<cstdio>
#include<iostream>
#include<cstring>
#define N 400001
#define lc no<<1
#define rc no<<1|1
#define fire_dancer
#define getmid int mid=(L[no]+R[no])>>1
double fire[N],dance[N];
int L[N],R[N],n,q;
double p[N];
int x,y,u,ty;
double despacito,Timsei;
#define eps 1e-8
void pushup(int no)
{
    fire[no]=fire[lc]*fire[rc]+eps;
    dance[no]=dance[lc]+fire[lc]*dance[rc]+eps;
}
void build(int no,int l,int r)
{
    L[no]=l;R[no]=r;getmid;
    if(l==r)
    {
        scanf("%d%d",&x,&y);
        p[mid]=(double)x/double(y)+eps;
        fire[no]=(1-p[mid])/p[mid]+eps;
        dance[no]=fire[no]+eps;
        return;
    }
    build(lc,l,mid);build(rc,mid+1,r);
    pushup(no);
}
void change(int no,int num)
{
//  cout<<L[no]<<" "<<R[no]<<endl;
    if(L[no]==R[no])
    {
        double pp=double(x)/double(y)+eps;
        fire[no]=(1-pp)/pp+eps;
        dance[no]=fire[no]+eps;
        return;
    }
    getmid;
    if(num>mid) change(rc,num);
    else change(lc,num);
    pushup(no);
}
void query(int no,int l,int r)
{
    if(L[no]==l&&R[no]==r)
    {
        Timsei+=dance[no]*despacito+eps;
        despacito*=fire[no]+eps;
        return;
    }
    getmid;
    if(l>mid) query(rc,l,r);
    else if(r<=mid) query(lc,l,r);
    else
    {
        query(lc,l,mid);query(rc,mid+1,r);return ;
    }
}
int main()
{
    cin>>n>>q;
    build(1,1,n);
    while(q--)
    {
        scanf("%d",&ty);
        if(ty==1)
        {
            scanf("%d%d%d",&u,&x,&y);
            change(1,u);
        }
        else
        {
            scanf("%d%d",&x,&y);
            despacito=1;Timsei=0;
            query(1,x,y);
            if(Timsei>1e15){puts("0.000000000");continue;}
            else 
            {
                double ans=1.0/(1+Timsei)+eps;
                printf("%.10lf\n",(ans));
            }
        }
    }
}
华为OD机试真题 新系统【Skill执行链完整性检测】 华为OD机试 新系统真题【Skill执行链完整性检测】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试真题【Skill执行链完整性检测】 阅读详情

相关推荐

FPGA:将FIFO封装成AXI接口的IP

封装AXI_stream的接口IP核

m0_46830519的博客 4216

CodeForces Round #370 (div.2) 即 Codeforces 712

CodeForces Round #370 (div.2) DescreptionA设A[i] = B[i] - B[i + 1] + B[i + 2] - B[i + 3]… 现在给出A序列,求B序列。B给出一个有上下左右四个方向的移动序列。你能任意改变这个序列,问能否用最少的修改次数使得最后回到起点。C给出一个边长为X的正三角形,每次操作可以修改一条边的长度,要求是边保持整数且始终能构成三角形

毒液哥的专栏 824

Dify DSL文件分享 Dify讨论群 大模型token资源等(持续收集更新)

基于LLMOps平台-Dify的一站式学习平台。包含不限于:Dify案例、DSL文件分享、模型接入、Dify交流讨论等各类资源分享。

同名公众号:dify实验室 3714

贪心算法(各种贪心题目)

感觉很多贪心的题目只要想到怎么贪心就很快能解决,但是没有想到的话代码量就会很大,而且很容易出错,所有贪心还是要多做题目,掌握各种贪心的题目 题目链接:https://vjudge.net/contest/231313#problem/D A factory produces products packed in square packets of the same height ...

409

eDP、DP与HDMI——现代显示接口的核心解析

eDP、DP和HDMI各有千秋:eDP以嵌入式设备的低功耗见长,DP凭借开放生态和高带宽成为专业领域首选,而HDMI则依靠庞大的消费电子生态稳居家庭市场。未来,随着Type-C接口的普及和超高清内容的爆发,三者的技术边界可能进一步融合,但各自的核心优势仍将长期共存。对于用户而言,选择接口需基于设备需求——游戏玩家青睐HDMI的VRR,设计师依赖DP的多屏扩展,而轻薄本则离不开eDP的紧凑设计。

麟的博客 8411

Vivado报错-4 [Routed 35-3424] SLL Assignment failed ILP VU19P

Vivado报错[Routed 35-3424] SLL Assignment failed ILP VU19P

weixin_39896700的博客 1408

Codeforces Problem 712C Memory and De-Evolution(贪心,逆推)

Codeforces Problem 712C Memory and De-Evolution(贪心,逆推)

queuelovestack的专栏 1540

【Bug已解决】openclaw command not found / openclaw not installed — OpenClaw CLI 安装失败解决方案

安装 OpenClaw 后命令未找到或运行失败,本质是 PATH 未配置或 Python 版本不兼容。文中给出修复 PATH、使用虚拟环境、检查 Python 版本、pipx 安装等完整方案。

一键难忘的博客 8065

Codeforces 712A. Memory and Crow

题目链接:http://codeforces.com/problemset/problem/712/A 题意:   有两个序列 ai 和 bi, 长度都为 n, 对于序列 ai 满足 ai = bi - bi + 1 + bi + 2 - bi + 3 ...(i < n).现给你 ai, 让你求出 bi. 思路:   ai = bi - bi + 1 + bi + 2 -...

dimaishu7553的博客 189

9、傅里叶变换:连续时间与离散时间信号分析的核心工具

本文深入探讨了傅里叶变换在连续时间和离散时间信号分析中的核心作用,详细介绍了连续时间傅里叶变换(CTFT)和离散时间傅里叶变换(DTFT)的定义、性质及其应用。文章涵盖了傅里叶级数到傅里叶变换的推导过程、常见变换对、系统分析中的关键性质,并讨论了采样后频谱的周期延拓与混叠问题。此外,还展示了傅里叶变换在滤波器设计、通信系统调制解调等实际场景中的应用,最后展望了其在图像处理、生物医学等领域的广阔前景。

jump7的博客 67

全网首发--Unet3+改进16:在不同位置添加RepLKBlock超大卷积核

本文提出了一种基于大核卷积的神经网络架构RepLKNet,旨在缩小CNN与ViTs之间的性能差距。通过重新审视CNN中的大核设计,研究证明使用少量大卷积核替代多个小核能获得更强大的性能。提出的RepLKNet采用31×31大卷积核,在ImageNet和下游任务上取得了与SwinTransformer相当或更好的结果,同时具有更低延迟。文章详细介绍了实现步骤:(1)创建RepLKBlock模块文件;(2)在模型层中添加注意力机制;(3)在UNet模型中集成RepLKBlock;(4)完成训练流程。该方法展现了

AIcurator的博客 618

Codeforces_712_A

http://codeforces.com/contest/712/problem/A 水题,写出来就看到规律了。 #include<iostream> #include<cstring> using namespace std; long long a[100005]; int main() { long long...

diaotan0836的博客 199

电源完整性分析:PDN阻抗与去耦电容设计——目标阻抗计算与电容选型深度实战

摘要:随着嵌入式处理器主频突破 GHz、多核架构普及,电源完整性(Power Integrity, PI)已成为高速 PCB 设计中不可忽视的关键环节。本文从 PDN(电源分配网络)阻抗模型出发,系统讲解目标阻抗计算方法、去耦电容选型策略、反谐振抑制技术,并结合 STM32F4 核心板的完整设计实例,提供一套可落地的电源完整性工程实践方案。电源完整性设计是一项系统工程,需要从目标阻抗计算电容选型反谐振抑制PCB 布局目标阻抗是设计的起点,由电源电压、纹波要求和瞬态电流决定去耦电容。

从事移动开发八年,csdn博客专家,阿里云特邀专家,华为云云享专家,高级网络信息安全工程师,大数据工程师(高级),python技术开发(高级),HarmonyOS 应用开发者高级认证,现在某学校任教。 1万+

Codeforces_712_B

http://codeforces.com/problemset/problem/712/B 水,判断奇偶即可。 #include<iostream> #include<string> using namespace std; int main() { string s; int a = 0,b = 0; ...

diaotan0836的博客 150

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

Codeforces Problem 712A Memory and Crow(公式推导)

Codeforces Problem 712A Memory and Crow(公式推导)

queuelovestack的专栏 1084

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

Codeforces 712B. Memory and Trident

题目链接:http://codeforces.com/problemset/problem/712/B 题意:   一个人站在坐标原点处,他可以往上(U), 下(D), 左(L), 右(R), 四个方向移动,现给你一个移动序列,为了使他最后仍然能回到原点,你需要对这个序列做一些改变,每次可以改变其中一个字母,问最少的改变次数. 思路:   如果这个序列的长度是奇数,那么肯定不可能...

dimaishu7553的博客 156

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

Codeforces Problem 712B Memory and Trident(implementation)

Codeforces Problem 712B Memory and Trident(implementation)

queuelovestack的专栏 1050

简单思维题CodeForces - 712B

传送门:https://codeforces.com/problemset/problem/712/B 题意:L,R,U,D,分别向左边,向右边,向上边,向下走。你可以替换字符串,从而让他走到原点。 问,给你字符串,最少需要替换几个。无解输出-1. 很明显,字符串长度为奇数,怎么替换也不能走到原点,输出-1; 字符串为偶数,要考虑什么呢? L,R是一对,U,D是一对。 也就是说L,R个数要相对,U...

i_like1ac的博客 168

Codeforces 712C. Memory and De-Evolution

题目链接:http://codeforces.com/problemset/problem/712/C 题意:   给你两个值 a 和 b (a > b), 代表这里有两个等边三角形, 边长分别为 a 和 b, 你可以对边长为 a 的三角形进行变换, 每次变化你可以选择一条边, 并为其重新指定一个长度, 当然变换完成后还能组成一个三角形.问最少经过多少次变换可以把等边三角形的三...

dimaishu7553的博客 164

Codeforces 712B Memory and Trident

B. Memory and Trident time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Memory is performing a walk on the two-...

weixin_30594001的博客 114

codeforces 712E Memory and Casinos

codeforces 712E 题目大意 有\(n\)个赌场,在赌场\(i\)有\(p_i\)的几率获胜并走到第\(i+1\)个赌场,有\(1-p_i\)的几率失败并走到第\(i-1\)个赌场。有两种操作: 修改\(p_i\) 给定区间\([l,r]\),求从\(l\)开始并在\(r\)获胜的概率。 思路 考虑每一个查询操作,对于区间\([l,r]\),\(l\)到达不了\(r\)当且仅当经过...

weixin_30929295的博客 119

codeforces 712A. Memory and Crow

题目链接:http://codeforces.com/problemset/problem/712/A 题目大意:   给你一个数字系列,求其满足条件的一个序列。   条件为:     ai = bi - bi + 1 + bi + 2 - bi + 3.... 解题思路:     可先从后向前推,b[n]=a[n](1-n个数);     b[i]=a[i]+b[i+1]-b[i+...

weixin_30711917的博客 72

[Codeforces 712E Memory and Casinos]概率+线段树区间合并

[Codeforces 712E Memory and Casinos]概率+线段树区间合并分类:math probabilities data structures1. 题目链接[Codeforces 712E Memory and Casinos]2. 题意描述现在n个赌场排成一行。 在第i个赌场,有p[i]的概率获胜,如果此时i=n则结束,否则到达第i+1个点;有(1-p[i])概率失败,

Fighting! 897

[Codeforces712D] Memory and Scores(DP+前缀和优化)(不用单调队列)

[Codeforces712D] Memory and Scores(DP+前缀和优化)(不用单调队列) 题面 两个人玩游戏,共进行t轮,每人每轮从[-k,k]中选出一个数字,将其加到自己的总分中。已知两人的初始得分分别为a和b,求第一个人最后获胜的方案数。两种方案被认为是不同的,当且仅当存在其中一轮,其中一人选到的数字不同。a, b, t≤100,k≤1000 分析 两个人的操作是独立...

weixin_30551963的博客 170

codeforces 712B. Memory and Trident

题目链接:http://codeforces.com/problemset/problem/712/B 题目大意:   给出一个字符串(由'U''D''L''R'),分别是向上、向下、向左、向右一个单位,问修改若干字符,可以回到原点。回不到原点输出 -1,可以则输出最少修改的步数。 解题思路:   如果是奇数步,则不可以回到原点 直接输出-1;   否则:分别统计出向各个方向的步数,求出...

weixin_30484247的博客 125
上一篇: codeforces160A
下一篇: codeforces544
Timsei
博客等级 码龄10年 344粉丝 159原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值