PAT 甲级 1056 Mice and Rice

PAT甲级 1056 Mice and Rice 【代码】PAT 1056 Mice and Rice。 阅读详情

1056 Mice and Rice

题目大意:给出老鼠的数量和每组的人数,将老鼠分成若干组(多下来不够每组人数的算作一组),第二行给出每只老鼠最终的重量,第三行给出分组顺序

思路:记录每轮获胜的选手,淘汰掉的人的排名就是当前所在的层数,将获胜的选手继续下一轮排名。注意这里分组需要考虑总人数不满一组的情况!

n,m=map(int,input().split())
weight=list(map(int,input().split()))   #每只老鼠的重量
order=list(map(int,input().split()))    #按照order顺序分组
new_weight=[]
for i in range(n):
    new_weight.append(weight[order[i]])
win=order  #存放每轮获胜选手的下标
group=int(n/m)+1 if n%m!=0 else int(n/m)
trank=group+1  #每组老鼠的排名
rank=[trank]*n
index=0
while len(win)!=1:
    group=int(len(win)/m)+1 if len(win)%m!=0 else int(len(win)/m)   #这里取整要注意不满一组的情况
    trank=group+1
    for i in win:
        rank[i]=trank
    win=[]
    index=0
    for i in range(group):
        max_weight=max(new_weight[index:index+m])
        win_index=weight.index(max_weight)
        win.append(win_index)
        index+=m
    new_weight=[]
    for i in win:
        new_weight.append(weight[i])
rank[win[0]]=1
print(*rank)

基于Android平台下的健康管理APP/基于android的健康管理系统 随着网络科技的发展,移动智能终端逐渐走进人们的视线,相关应用越来越广泛,并在人们的日常生活中扮演着越来越重要的角色。因此,关键应用程序的开发成为影响移动智能终端普及的重要因素,设计并开发实用、方便的应用程序具有重要的意义和良好的市场前景。Android技术作为当前最流行的操作平台,自然也存在着大量的应用服务需求。 本课题研究的是基于Android技术平台的健康管理APP,开发这款健康管理APP主要是为了帮助用户可以不用约束时间与地点进行所需信息。本文详细讲述了健康管理APP的界面设计及使用,主要包括界面的 阅读详情

相关推荐

Windows平台高效BLE调试工具开发指南

本文为开发者提供了一份在Windows平台上开发高效BLE调试工具的详细指南。文章深入探讨了使用32feet.NET库进行蓝牙低功耗设备扫描、连接、数据通信及进阶功能开发的实战经验,旨在帮助开发者打造功能自定义、性能优化的专属调试利器,显著提升物联网和嵌入式设备的调试效率。

weixin_29201933的博客 255

Pat甲级1056 Mice and Rice

题解:有Np只老鼠,给出他们的重量,以Ng只为一组,找到该组最重的老鼠,该组其余老鼠淘汰,同批次被淘汰老鼠的等级相同。把每一组的最重老鼠集合再次分组。。。直到只有一只老鼠,该老鼠的等级为1。 当最后一组不足Ng只时,仍然分为一组。 输入的第二行即Np只老鼠的重量,该顺序也是老鼠的输出顺序。 老鼠0号重量25,老鼠1号重量18,老鼠2号重量0。。。。 第三行为游戏顺序,即以老鼠6号、老鼠0号、老鼠8号。。。的顺序开始比较。 每组被淘汰的老鼠等级为group + 1;如: 该题中,第一次比较时有11只老鼠,3

weixin_45640957的博客 231

手把手教你用C++和NI-VISA写个简易仪器上位机(附QT工程配置)

本文详细介绍了如何使用C++和QT框架结合NI-VISA驱动开发跨平台仪器控制上位机软件。从Ubuntu环境配置、VISA通信核心架构设计到QT界面与业务逻辑解耦,提供了完整的实战指南和代码示例,帮助开发者快速构建专业级仪器控制程序。

weixin_42522374的博客 273

PAT甲级1056 Mice and Rice

原题链接PAT甲级1056 Mice and Rice 这道题,2020年7月份做的时候,做了好久才AC,今天又做了一次。使用了比较直观的思路,模拟了一遍题目。A掉了 题意 给了n只老鼠,以及每只老鼠的体重,注意题目告诉了,每只老鼠的体重满足== ​​ distinct non-negative numbers==,即不同的非负数,也就是说每只老鼠的体重不同,而且,并没有说是整数,所以对于每只老鼠的体重,最好是按照double型存放。做pat要对数据描述字眼敏感,没有说是整数,最好存储为double。.

weixin_44321570的博客 344

基于Cesium移动的天空云

天空中的云朵也算是一种天气气候的效果,它能更加逼真的反映当前的天气状况,可以是白云朵朵,也可以是乌云密布,结合其他天气效果,可以组合形成较为真实的三维可视化场景。

星云数海的博客,一个专注GIS十多年的GISer人。 446

从零开始学习PX4源码0(固件下载及编译)

本节主要记录从零开始学习PX4源码1(固件下载)的过程,欢迎批评指正!!!下载固件主要分为两个版本,之前稳定版本和最新官网发布版本,为什么要下载两个版本,主要是说明两个版本有一定的差异(开发环境及源码文件格式等),我们是从之前版本开始学习,为什么不从最新的?因为之前版本代码文件格式还是固定的,最新的变化很大,不利于初学者学习,apm和px4不好的地方就是之前版本v1.7.2和最新版本v1.14.0有些文件总是在变化,这样很不好。

陌城烟雨 4616

PAT甲级:1056 Mice and Rice

老鼠和大米是一个编程竞赛的主题,程序员们需要编写代码控制老鼠在给定的地图上移动,每只老鼠的目标都是吃掉尽可能多的大米,从而变成肥老鼠。第三行包含一个 0∼NP−1的排列,表示老鼠的具体参赛顺序,以样例为例,6 号老鼠排在第一个,0 号老鼠排在第二个,以此类推。输出一行 NP 个整数,其中第 i 个整数表示编号为 i 的老鼠的最终排名。为了简单起见,当程序员们提交了代码后,他们的老鼠的最终重量就已经确定了。给定所有老鼠的重量和程序员们的参赛顺序,请你为程序员们排名。所有 NP 只老鼠的编号为 0∼NP−1。.

KS的博客 267

代码的自由之旅:用AI写出无版权烦恼的Verilog

他们还基于这个数据集,训练了一个名叫“FreeV”的AI模型,不仅能写出好用的Verilog代码,还把版权侵权的风险降到了仅3%。为了让AI安全地写Verilog,研究团队提出了三个“法宝”:一个检测AI是否会生成侵权代码的测试方法、一个干净的Verilog数据集FreeSet,还有一个基于FreeSet训练的AI模型FreeV。AI的记忆力超强,能记住训练时见过的代码。测试发现,一些用Verilog数据训练过的AI,比如VeriGen,生成侵权代码的概率从9%涨到了15%,说明它们可能学了不该学的代码。

步子哥的博客 1809

【PAT甲级】1056 Mice and Rice (25分)

解题过程的小记录,如有错误欢迎指出。 难度:五星(题目读了好几遍也没读懂,不过看了解析后决定自己就算看懂题目可能也做不出来orz) 小导航~题目分析注意点我的解题过程思路bug代码dalao的代码借鉴点 题目分析 第一行给出的是总共的老鼠数和每一组老鼠的数量 第二行给出的是每只老鼠的数量 第三行给出的是每只老鼠的编号 按给出的顺序分组,选出每一组中体重最大的老鼠晋级下一轮,下一轮再次进行分组,一直进行循环,知道找到第一名(第一名一定是所有老鼠中最重的,但第二名不一定是所有老鼠中第二重的) 注意点 第三行给

SpicyChicken的自我修养 267

【论文复现】——基于NDT与ICP结合的点云配准算法(matlab版)

基于NDT与ICP结合的点云配准算法matlab版

点云侠的博客 490

计算机视觉教程2-3:图解双线性插值算法&最近邻插值算法

提出此算法的背景是基于图片的缩放,在图片缩放的过程中,实质上就是将原图像像素矩阵像素值,填到目标图像像素矩阵中,目标图像像素矩阵可能比原图像像素矩阵大(图片放大),也可能小(图片缩小)。我们假设图片的宽(WidthWidthWidth)和高(HeightHeightHeight)是按同比例缩放的,那么 srcXsrcWidth=dstXdstWidth\frac{srcX}{srcWidth}= \frac{dstX}{dstWidth}srcWidthsrcX​=dstWidthdstX​ ...

FRIGIDWINTER的博客 7282

PAT甲级1056,1057解题报告

1056 Mice and Rice (25 point(s)) Mice and Rice is the name of a programming contest in which each programmer must write a piece of code to control the movements of a mouse in a given map. The goal of...

TateBrwonJava的博客 437

【高级】系统架构师 | 2026年上半年案例分析真题

标准答案:系统因缺乏足够历史数据(用户行为、物品信息或评分等),难以做出准确推荐的问题。另外两种:物品冷启动(新课程 / 新知识点缺少互动数据)系统冷启动(平台上线初期整体数据稀缺)类型典型表现常见缓解用户冷启动新注册学员无历史问卷/前测、热门兜底、人口统计学特征、知识图谱前置测评物品冷启动新课无人学无人评内容特征推荐、专家标注、探索流量系统冷启动新平台双边都稀缺规则引擎、运营冷启、知识图谱强约束路径本题已点明「用户冷启动」,另外两种按推荐系统经典三分法作答即可。

大胆尝试,小心实践 358

PAT 甲级 1056  Mice and Rice

1056 Mice and Rice (25 point(s)) Mice and Rice is the name of a programming contest in which each programmer must write a piece of code to control the movements of a mouse in a given map. The goal of...

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

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

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

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

【PAT甲级 - C++题解】1056 Mice and Rice

给定参赛的老鼠数量 ,比赛分组每组 只老鼠。第二行给定 个老鼠的重量,第三行给定老鼠出场的顺序,拿题目样例举例,第一只出场的老鼠编号为 ,第二只出场的老鼠编号为 。现在要将 只老鼠进行分组比赛,每组 只,如果不满 则同样被分为一组,每组中重量最大老鼠晋级下一轮。被淘汰的老鼠排名都相同,按照上述规则继续分组比赛,直至找到第一名,最后输出每只老鼠的最终排名。具体思路如下:

Newin2020的博客 688

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

PAT甲级 1056 Mice and Rice(25)

PAT甲级真题1056 Mice and Rice详解和AC代码

2301_79601095的博客 1283

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

1056. Mice and Rice (25)-PAT甲级真题

当时没想到可以用队列来做,就傻傻的模拟了,用cur存当前轮的id,这个id对应的是order的下标,这里有个求rank的技巧就是当前轮没有晋级的rank为(当前轮的组数+1)

m0_61868996的博客 441

PAT A 甲级 1056 Mice and Rice (25分)

1056 Mice and Rice (25分) 题意 重点就是第三行。以示例为例,第三行的内容分析一下是“ID6号、0号、8号分别在第1、2、3位,他们三位在第一局中互相对决”。 思路 用了两个保存指针的vetor,方便一边削减vector内容(也就是模拟淘汰)一边记录名次。 然后就是模拟淘汰赛——每只鼠和当前同组最重鼠比较,留下胜者并给败者赋rank、erase败者,重复这个操作到只剩一只鼠。...

虚境的博客 249

PAT甲级 1056 Mice and Rice (25分)

1056 Mice and Rice (25分) 题目链接:PAT A 1056 题目大意:输入第一行给出两个数np和ng,分别代表老鼠总数和每组老鼠的个数,第二行给出每只老鼠(索引从0到np-1)的重量,第三行给出初始时老鼠的分组序号。规则是从每组中选出最重的一只老鼠晋级比赛,这样有几组,就会有几只老鼠晋级,其余老鼠的排名就是组数加一,要求输出最后每只老鼠的排名。如果像样例那样,有11只老鼠,...

weixin_43684054的博客 282

PAT 甲级 1056 Mice and Rice 思路以及解题代码

记录一下自己刷PAT A1056题的思路及代码。

weixin_40007143的博客 251

1056 Mice and Rice -PAT甲级

题目描述 Mice and Rice is the name of a programming contest in which each programmer must write a piece of code to control the movements of a mouse in a given map. The goal of each mouse is to eat as m...

amf12345的博客 179

PAT甲级题目1056 Mice and Rice

代码: #include<cstdio> #include<vector> #define maxn 1010 using namespace std; struct mouse { int weight; int rank; }mice[maxn]; int main() { int NP,NG; int Rat,Group; int i,j,k,front,current,u,max; vector<int> Seq

weixin_43801993的博客 176
上一篇: PAT 甲级 1052 Linked List Sorting
下一篇: PAT 甲级 1059 Prime Factors
zerohawk
博客等级 码龄8年 3粉丝 78原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值