首页 > 其他分享 >牛客网刷题4

牛客网刷题4

时间:2023-06-25 23:22:52浏览次数:48  
标签:begin 1ns clk 牛客 网刷题 rst input reg

25-28

25题

输入序列连续的序列检测_牛客题霸_牛客网 (nowcoder.com)

image-20230625172233799

`timescale 1ns/1ns
module sequence_detect(
	input clk,
	input rst_n,
	input a,
	output reg match
	);

reg [8:0] tmp;
//存储
always @(posedge clk or negedge rst_n) begin
    if (!rst_n) begin
        tmp <= 0;
    end
    else  begin
        tmp <= {tmp[7:0],a};
    end
end


always @(posedge clk or negedge rst_n) begin
    if (!rst_n) begin
        match <= 0;
    end 
    else if (tmp == 9'b01110001) begin
        match <= 1;
    end
    else begin
        match <= 0;
    end
end
  
endmodule

26题

含有无关项的序列检测_牛客题霸_牛客网 (nowcoder.com)

image-20230625172757679

`timescale 1ns/1ns
module sequence_detect(
	input clk,
	input rst_n,
	input a,
	output reg match
	);

  reg [8:0] tmp;
//存储
always @(posedge clk or negedge rst_n) begin
    if (!rst_n) begin
        tmp <= 0;
    end
    else  begin
        tmp <= {tmp[7:0],a};
    end
end

wire flag;
always @(posedge clk or negedge rst_n) begin
    if (!rst_n) begin
        match <= 0;
    end 
    else if (flag) begin
        match <= 1;
    end
    else begin
        match <= 0;
    end
end

assign flag = tmp[8:6] == 3'b011 && tmp[2:0] == 3'b110;
endmodule

27题

不重叠序列检测_牛客题霸_牛客网 (nowcoder.com)

image-20230625173525768

`timescale 1ns/1ns
module sequence_detect(
	input clk,
	input rst_n,
	input data,
	output reg match,
	output reg not_match
	);


    //计数器
    reg [2:0] cnt;
    always @(posedge clk or negedge rst_n) begin
       if (!rst_n) begin
            cnt <= 0;
       end 
       else begin
            if (cnt == 5) begin
                cnt <= 0;
            end
            else begin
                cnt <= cnt + 1;
            end
       end
    end

    reg [5:0] tmp;
    always @(posedge clk or negedge rst_n) begin
        if (!rst_n) begin
            tmp <= 0;    
        end
        else begin
            tmp[5-cnt] <= data;
        end
    end

     always @(posedge clk or negedge rst_n) begin
        if (!rst_n) begin
            match <= 0;    
            not_match <= 0;
        end
        else if(tmp == 6'b011100 && cnt == 5) begin
            match <= 1;
            not_match <= 0;
        end
        else if(tmp != 6'b011100 && cnt == 5) begin
            match <= 0;
            not_match <= 1;
        end
        else begin
            match <= 0;    
            not_match <= 0;
        end
    end

endmodule

28题

输入序列不连续的序列检测_牛客题霸_牛客网 (nowcoder.com)

image-20230625220744537

`timescale 1ns/1ns
module sequence_detect(
	input clk,
	input rst_n,
	input data,
	input data_valid,
	output reg match
	);

    reg [3:0] tmp;

  always  @(posedge clk or negedge rst_n)begin
    if(rst_n==1'b0)begin
        tmp <= 0;
    end
    else if(data_valid) begin
        tmp <= {tmp[2:0],data};
    end
  end


  always  @(posedge clk or negedge rst_n)begin
    if(rst_n==1'b0)begin
        match <= 0;
    end
    else if(tmp[2:0] == 3'b011 && data_valid && data == 0) begin
        match <= 1;
    end
    else begin
        match <= 0;
    end
        
  end
endmodule

标签:begin,1ns,clk,牛客,网刷题,rst,input,reg
From: https://www.cnblogs.com/doincli/p/17504241.html

相关文章

  • 牛客网刷题二
    牛客网FPGA题库刷题之快速入门题库(一)9~13题14-20没啥用就是看图写,不需要做了第九题题目链接使用子模块实现三输入数的大小比较代码`timescale1ns/1nsmodulemain_mod(inputclk,inputrst_n,input[7:0]a,input[7:0]b,input[7:0]c,output[7:0]d);......
  • 牛客题解-mixup2混乱的奶牛(状压dp)
    题解-mixup2混乱的奶牛[原题连接](1026-mixup2混乱的奶牛_2021秋季算法入门班第八章习题:动态规划2(nowcoder.com))题目描述混乱的奶牛[DonPiele,2007]FarmerJohn的N(4<=N<=16)头奶牛中的每一头都有一个唯一的编号S_i(1<=S_i<=25,000).奶牛为她们的编号感到骄傲......
  • 牛客竞赛刷题模板
    牛客竞赛自用,便于复制for(letT=parseInt(readline());T>0;T--){const[n,m]=readline().split('',2).map(v=>parseInt(v));constnums=readline().split('',n).map(v=>parseInt(v));letsum=0;constsub......
  • transform (牛客多校) (双指针+二分+ 中位数妙用+前缀和相减维护)
    题目大意:n个商店在一条直线上, 有一个xi然后有ai个商品你可以把商店的物品移动到另一个商店,代价为:abs(xi-xj)在代价不超过T的情况下你可以选择一个商店来让其他商店的物品都移到这个商店,问最多移动多少个物品  思路:双指针维护一个最大的区间,因......
  • farm (牛客多校) (二维树状+数学式子优化+rand()去除特殊情况)
    题目大意:给出一个n*m的田地矩阵,每个格子上种着一种植物。给格子施肥t次,每一次给出五个数字,x1,y1,x2,y2,k,要施肥的区域坐标和要施的肥料种类。如果植物和施肥种类不匹配,植物会死亡。问最终会死多少个植物。 思路:判断一个植物死不死, 判断植物种类*施肥次数==施肥种类总和某......
  • car (牛客多校) (情景找规律,抠细节)
    题目大意:给一个正方形棋盘,你现在可以在棋盘的边缘防止车,然后车只能向正对的方向走,(角落可以往2边走)2个车相遇会G给m个破环的方块,车经过就G问最多可以放多少个车] 思路:注意奇偶分规律,偶数2*n,奇数2*n-1注意放置破环的方块,在奇数最中间的时候,......
  • Longest Path (牛客多校) (换根DP+斜率优化)
    换根dp:第一次dfs处理儿子点的权值第二次dfs处理父亲点,和兄弟节点的权值处理兄弟节点的时候,利用父亲节点统一处理,利用stl存储斜率优化:为什么会用到斜率优化:在遇到转移式子是fixfj的时候,不是分开的,(分开的,直接用单调队列处理)(通常会遇到平方式子)把......
  • 牛客网刷题一
    牛客网FPGA题库刷题之快速入门题库(一)1~8题第一题题目链接:四选一多路器代码:`timescale1ns/1nsmodulemux4_1(input[1:0]d1,d2,d3,d0,input[1:0]sel,output[1:0]mux_out);//*************code***********//reg[1:0]mux_out_tmp;always@(*)begin......
  • 牛客小白月赛73
    A最小的数字#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongint32_tmain(){ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);intn;cin>>n;cout<<((n+2ll)/3ll)*3ll<<"\n";......
  • 牛客想开了大赛2 题解
    题目链接:https://ac.nowcoder.com/acm/contest/907#question A.【六】平面公式:(n*n+n)/2+1,n为直线数目B.【一】n的约数枚举质因子和每个质因子的个数,显然个数肯定从多到少。#include<bits/stdc++.h>typedeflonglongll;usingnamespacestd;constintmx=1e4+10;in......