PAT 1074. Reversing Linked List

FPGA高速通信双核解析:CMAC与Interlaken硬核的实战对比 本文深入对比了FPGA中两大高速通信硬核CMAC与Interlaken的核心差异与应用场景。CMAC作为标准以太网接入方案,适用于网卡、交换机等需对外互联的场景;而Interlaken则以极低延迟和高效通道化能力,专为芯片间、板间裸数据高速传输设计。文章通过实战案例与性能指标分析,为FPGA高速通信方案选型提供清晰指南。 阅读详情

题目:http://pat.zju.edu.cn/contests/pat-a-practise/1074

题解:

给一个n长度的链表存储的字符串,以k长度为单位置逆子串,输出置逆后的整个子串。

写的时候死活最后一个case通不过。

看了别人的题解才知道输入的竟然可能不是一个串。

例如:

00100 6 3
00000 4 99999
00100 1 12309
68237 6 -1
33218 3 00000
99999 5 68237
12309 2 -1

代码:

#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
struct point
{
    int date;
    char add[10];
    char cnext[10];
    int idx;
} num[100010];
map<string,int> mapx;
int len=0;
bool cmp(const struct point &a,const struct point &b)
{
    return a.idx<b.idx;
}
int main()
{
    char a[10],b[10],st[10];
    int n,k,i;
    scanf("%s%d%d",st,&n,&k);
    for(i=0; i<n; ++i)
    {
        scanf("%s%d%s",num[i].add,&num[i].date,num[i].cnext);
        mapx.insert(make_pair(string(num[i].add),i));
        num[i].idx=999999;
    }
    int x=mapx.find(string(st))->second;
    for(i=0; i<n;)//整理串
    {
        num[x].idx=i;
        ++i;
        if(strcmp(num[x].cnext,"-1")==0)//处理不止一个串的情况
            break;
        x=mapx.find(string(num[x].cnext))->second;
    }
    sort(num,num+n,cmp);
    n=i;
    int high=n/k*k;
    for(i=0; i+k<=high; i+=k)
    {
        for(int j=k-1; j>0; --j)
        {
            printf("%s %d %s\n",num[i+j].add,num[i+j].date,num[i+j-1].add);
        }
        printf("%s %d ",num[i].add,num[i].date);
        if(i+k==n)//字符串刚好是k的倍数
        {
            printf("-1\n");
        }
        else if(i+2*k>high)//字符串不是k的倍数且多出小于k的长度
            printf("%s\n",num[i+k].add);
        else if(i+2*k-1<n)
            printf("%s\n",num[i+2*k-1].add);
        else
            printf("-1\n");
    }
    for(; i<n; ++i)
        printf("%s %d %s\n",num[i].add,num[i].date,num[i].cnext);
    return 0;
}

来源: http://blog.youkuaiyun.com/acm_ted/article/details/20406485

树莓派4B+红外传感器:手把手教你DIY一个能走黑线的智能小车(Python代码全解析) 本文详细介绍了如何使用树莓派4B和红外传感器DIY一个智能循迹小车,包括硬件配置、GPIO连接、Python代码实现及优化算法。通过动态PWM调速、状态机设计和赛道记忆算法,提升小车的循迹性能和稳定性。适合初学者和电子爱好者动手实践。 阅读详情

相关推荐

Flink CDC 3.0 详解

Flink CDC 是基于数据库日志 CDC(Change Data Capture)技术的实时数据集成框架,支持全增量一体化、无锁读取、并行读取、表结构变更自动同步、分布式架构等高级特性。配合Flink 优秀的管道能力和丰富的上下游生态,Flink CDC 可以高效实现海量数据的实时集成。Flink CDC 于2023年12月7日重磅推出其全新的 3.0 版本,3.0版本的发布对 Flink CDC 而言具有里程碑的意义,自此 Flink CDC 从捕获数据变更的Flink 数据源正式迈向为以 Flink

奔跑的蜗牛的博客 2639

Linux设备驱动模型核心原理与实战

Linux设备驱动模型是内核实现硬件抽象与用户空间交互的基础架构,其本质是基于kobject对象系统的面向对象设计,通过总线、设备、驱动、类四层抽象统一管理硬件生命周期。该模型支撑sysfs动态拓扑构建、udev热插拔响应及device tree匹配机制,是嵌入式内核开发与驱动移植的关键能力。掌握platform驱动从DTS解析、probe绑定到sysfs属性导出的完整链路,不仅能解决LED/UART等字符设备开发问题,更是深入PCIe、USB等复杂总线驱动的前提。本文围绕kobject引用计数、sysfs

weixin_33816300的博客 331

Gazebo仿真平台模型搭建与修改

ROS里踩过的坑(一)Gazebo仿真平台模型搭建与修改文件讲解Models 文件World文件Launch文件模型编辑可视化编辑配置文件编辑模型展示如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出...

Redglass的博客 1万+

PAT甲级——1074 Reversing Linked List

Given a constantKand a singly linked listL, you are supposed to reverse the links of everyKelements onL. For example, givenLbeing 1→2→3→4→5→6, ifK=3, then you must output 3→2→1→6→5→4; ifK=4,...

Xiao2018428的博客 306

全国职业院校技能大赛-大数据应用赛项-数据挖掘-01

-----------------------推荐Top5结果如下--------------------------------------------第一条数据前10列结果展示为:----------------------------------------相同种类前10的id结果展示为:--------------------相似度top5(商品id:14,平均相似度:0.522356)相似度top1(商品id:1,平均相似度:0.983456)若属于该spu_id,则内容为1否则为0。

Eternity_04的博客 1954

集成电路模拟版图入门-版图基础学习笔记(一)

集成电路设计模拟版图入门笔记,了解版图的定义、意义、工具、设计流程。认识版图及版图组成的两大部件,版图编辑器有哪些,电路图编辑器,了解工艺厂商等。

weixin_52955333的博客 2万+

1074 Reversing Linked List | PAT

今天发现自己有点疑似颈椎病症状,555芳年二十就这样了,不引起重视老了还了得? 不知道要家里呆到啥时候 还是看题目 题目要求输入一个静态链表,再根据给出的跨度ng,每个跨度ng内都倒置,最后多余的不用倒置,并且只要输出就行。 思路是这样: 定义结构体。内有地址adress,数据data,下一个的地址next,在链表中的次序order,初始化为maxn。这个结构体数组的下标可以作为地址,为什么还...

vavakavak的博客 186

YOLOv8轻量化模型瘦身术:深度解析与实战LAMP剪枝 YOLOv8(2021)

YOLOv8模型LAMP剪枝技术解析与实战 本文深入探讨了LAMP剪枝技术在YOLOv8目标检测模型中的应用。针对深度学习模型部署面临的资源限制问题,LAMP剪枝通过最小化L2失真和层自适应稀疏度分配,实现了高效模型压缩。相比传统幅度剪枝的"一刀切"方法,LAMP创新性地将剪枝建模为优化问题,定义LAMP分数来衡量权重重要性,自动确定各层最佳剪枝率。文章从理论基础出发,详细解析了LAMP的核心数学公式和算法流程,并提供了完整的YOLOv8移植实战指南,包括代码结构、剪枝步骤和微调策略。通

FJN110的博客 2422

1074 Reversing Linked List (25 分)

1074 Reversing Linked List (25 分) 题意 给出n个节点,每个节点包括地址,数据,和下一节点地址。给出首地址和节点个数以及k , 每k个节点进行一次反转,不足k个不反转。比如原link为 1 2 3 4 5 6 7 ,k 为 2 则反转之后为 2 1 4 3 6 5 7 按顺序输出反转之后的节点。 思路 因为给出的是一系列无序节点,先排好序,用静态链表的方式组成一个有序地序列。可以用结构体存储每个节点,结构体包括 地址 数据 下一个节点地址 以及一个真实的序号orde

weixin_43735634的博客 307

商用车重型多挡位机械式变速器(AMT)结构设计与仿真分析

本文针对商用车重型AMT变速器开展结构设计与仿真分析。设计采用12挡双中间轴结构,匹配400kW柴油发动机,最大扭矩2000Nm。通过等比级数分配传动比(头挡14.5,最高挡0.78),采用主副箱组合实现多挡位。双中间轴结构可抵消径向力,提升承载能力。关键设计包括:235mm中心距、4.5-5.0mm齿轮模数、锁环式同步器和复合润滑系统。通过Python参数化建模进行强度校核,计算显示中间轴在2000Nm工况下等效应力满足安全系数要求(屈服强度850MPa,安全系数≥2)。该设计解决了传统MT变速器操作强度

AI的内部世界的博客 113

【CASS精品教程】035:南方CASS7.1台阶画法案例大全

摘要:本文详细介绍了南方CASS7.1软件中5种台阶工具的使用方法,包括普通台阶、有边台阶、L型台阶、U型台阶和不规则台阶。重点说明各类台阶的绘制步骤和注意事项,如绘制方向(从右下角逆时针连接4个点)、台阶方向标识(白色边为下边)、台阶数自动生成不可更改等特性。同时指出高版本CASS可能存在操作差异,并配以多张示意图直观展示各类台阶的绘制过程和效果,为使用CASS7.1绘制建筑台阶提供了实用指导。(148字)

智慧空间实验室 2921

1120 Friend Numbers (20 分)

Two integers are called “friend numbers” if they share the same sum of their digits, and the sum is their “friend ID”. For example, 123 and 51 are friend numbers since 1+2+3 = 5+1 = 6, and 6 is their friend ID. Given some numbers, you are supposed to count

weixin_45962741的博客 210

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

PAT 1074 Reversing Linked List

PAT 1074 Reversing Linked List 链表

2301_80219163的博客 429

深度学习工具包 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")

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

【PAT】1074. Reversing Linked List(又是迷惑的一题)

【PAT】1074. Reversing Linked List(又是迷惑的一题) 题目: 1074 Reversing Linked List (25 分) Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For example, given L being 1→2→3→4→5→6, if K=3, then you must o

weixin_43827530的博客 664

OV9734 DATASHEET,完整规格书

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

PAT 1074 Reversing Linked List——双端队列解法

题目地址 原始想法 既然给定的序列是乱序的; 但是输出要求顺序,再按块反转输出 那么我为何不直接在读入的时候调整为顺序呢! 具体思路 读入1个结点后,剩下的结点,仅存在3种情况 插在他前面,插在他后面,直接空置(放到另一个容器a里) 由于存在空置,因此当输入最后一个时,对容器a进行遍历,再次插入,知道符合题意的首尾 通过reverse进行块反转 输出时第一个是特殊的,中间是有一定规律的,最后补上-1 代码 #include<bits/stdc++.h> using namespace st

net961231的博客 1661

【PAT】A1074 Reversing Linked List【链表】

Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For example, given L being 1→2→3→4→5→6, if K=3, then you must output 3→2→1→6→5→4; if K=4,...

elegant coder 928

PAT_1074. Reversing Linked List

// // main.cpp // PAT_1074. Reversing Linked List // // Created by wjq on 17/8/19. // Copyright © 2017年 wjq. All rights reserved. // #include using namespace std; int start,N,K; int linklist[10

kukubao207的博客 271

PAT 1074 Reversing Linked List

1074Reversing Linked List(25分) Given a constantKand a singly linked listL, you are supposed to reverse the links of everyKele...

Do Better 207

PAT 甲级 1074  Reversing Linked List

1074 Reversing Linked List (25 point(s)) Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For example, given L being 1→2→3→4→5→6, if K=3,...

漫浸天空的雨色的备忘录~ 762

[PAT B1025/A1074]Reversing Linked List

[PAT B1025/A1074]Reversing Linked List 本题是PAT乙级1025题和甲级1074题,这里先放英文原题,想要做乙级题的同学可以直接看后面的中文原题 题目描述 Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elem...

欢迎来到我的编程小屋 590

PAT1 1074 Reversing Linked List

题目链接 我的github 题目大意 给一个链表,要求将链表中的节点每KKK个相反排列一次,并输出最后的链表 输入 每组包含一个测试用例 第一行,有链表的首地址, 一个正数N≤105N\le10^5N≤105表示节点的数量,一个正数K≤NK\le NK≤N表示每KKK个相反排序一次。 之后有NNN行,每一行都表示一个节点的信息,格式为Address Data Next,表示节点的地址,节点的值(...

LSC_333的博客 279

PAT 1074 Reversing Linked List 链表

Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For example, given L being 1→2→3→4→5→6, if K=3, then you must output 3→2→1→6→5→4; if K=4,...

weixin_39666736的博客 192

【PAT A1074】Reversing Linked List

Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For example, given L being 1→2→3→4→5→6, if K=3, then you must output 3→2→1→6→5→4; if K=4,...

lvmy3的博客 302
上一篇: PAT 1024. 科学计数法
下一篇: PAT 1014. Waiting in Line
ACM_Ted
博客等级 码龄15年 122粉丝 208原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值