P1085简单解法

NOIP普及组经典题解析:不高兴的津津(附洛谷P1085题解与优化技巧) 本文以NOIP2004普及组经典题目“不高兴的津津”(洛谷P1085)为例,深入解析了信息学奥赛入门题的解题思路与算法思维构建。文章详细拆解了问题抽象、极值查找的核心算法实现(同步记录与索引记录两种方法),并提供了代码优化技巧与常见错误剖析,旨在帮助初学者夯实基础,掌握NOIP普及组的核心考点与高效备赛策略。 阅读详情

首先我们要知道题目的具体要求

知道题目及输出样例后,我们开始正式编写代码

如果想做题的话我先给答案

def happy (day):
    global donthnuber,donth
    a = input("").split()
    a = [int(x) for x in a]
    a = sum(a)
    if a>8 and donthnuber<a:
        donthnuber=a
        donth=day
donthnuber=0
donth=0
happy(1)
happy(2)
happy(3)
happy(4)
happy(5)
happy(6)
happy(7)
print(donth)

 接下来我们讲解一下它的过程

首先第一行

 这行是定义一个开不开心。

这段代码是def里面的,其主要检测今天开不开心,是不是最不开心的。

 

最后这段写了全局变量及运行定义

-----------------------------------------------------------------------------

但这样可能会比较麻烦,因为我们是一个一个的写出happy

我们其实可以用for循环,将happy(x) 中的x改为循环次数

def happy (day):
    global donthnuber,donth
    a = input("").split()
    a = [int(x) for x in a]
    a = sum(a)
    if a>8 and donthnuber<a:
        donthnuber=a
        donth=day
donthnuber=0
donth=0
for ha in range(7)
      happy(ha)
print(donth)

​

这样就是最终版了,我在强调一下

a = [int(x) for x in a]很多人都不知道其实这样可以将列表内的字符串转换为数字

byebye

【2026最新版】Open3D(C++)点云处理算法汇总(C++长期更新版) C++版本Open3D进行点云处理的一些算法使用案例。博客长期更新,最近一次更新时间为:2026年4月11日。 阅读详情

相关推荐

HFSS实战:手把手教你设计3.3-10.6GHz超宽带微带天线(附S11优化技巧)

本文提供了一份基于Ansys HFSS的超宽带微带天线实战设计指南,详细讲解了从3.3GHz到10.6GHz天线的建模、仿真与优化全流程。文章重点剖析了阻抗匹配的核心挑战,并分享了通过接地板开槽、参数化扫描及目标驱动优化等系统性技巧来优化S11曲线的实用方法,帮助射频工程师快速掌握超宽带天线设计的关键技能。

2y3u4i5o6p的博客 1081

P1085 不高兴的津津

...题目描述津津上初中了。妈妈认为津津应该更加用功学习,所以津津除了上学之外,还要参加妈妈为她报名的各科复习班。另外每周妈妈还会送她去学习朗诵、舞蹈和钢琴。但是津津如果一天上课超过八个小时就会不高兴,而且上得越久就会越不高兴。假设津津不会因为其它事不高兴,并且她的不高兴不会持续到第二天。请你帮忙检查一下津津下周的日程安排,看看下周她会不会不高兴;如果会的话,哪天最不高兴。输入输出格式输入格式:输...

独钓门前月 2040

人工智能-CS188 Project 2: Multi-agents

一、项目介绍 项目介绍网页 项目代码下载 本项目是采用Berkeley的CS188课程内容实习二的内容,在这个项目中,我们将为经典版本的Pacman 设计自动算法,包括幽灵。在此过程中,我们将实现 minimax 和 expectimax 搜索并尝试评估函数设计 完成作业只需要完成5个题目,按照项目介绍的步骤进行完成,主要是在multiAgents.py文件中进行补充代码 二、代码详情 1、Question1:Reflex Agent 略 2、Question2:Minimax 套用ppt上的minm

xiten的博客 8286

洛谷算法题 P1085 [NOIP2004 普及组] 不高兴的津津

我首先是想到用两个数组,第一个数组arr,来存储输入的14个数据(一天两条数据),接着用第二个数组arr1 把一天的数据加起来,得到一天一共的学习时间,然后再对数组arr1 中的7天的学习时间进行比大小,找出max。最后再用max,来判断一周的学习时间有没有超过8小时的,如果有,则用max找到对应的数组下标,下标+1 就是当天是星期几

2301_80147864的博客 1136

手把手教你用Ubuntu 22.04的附加驱动工具安装NVIDIA显卡驱动(含常见错误修复)

本文详细介绍了在Ubuntu 22.04系统上,如何通过图形化的“附加驱动”工具安全、便捷地安装NVIDIA显卡驱动。内容涵盖从准备工作、禁用默认的nouveau驱动、图形界面安装实操,到安装后的验证(如使用nvidia-smi命令),并提供了安装失败黑屏、亮度调节失效等常见问题的深度解决方案,帮助用户彻底搞定驱动安装难题。

weixin_29248653的博客 604

激光雷达接收芯片选型指南:APD、SiPM、SPAD阵列的优缺点对比

本文深入对比了激光雷达接收芯片APD、SiPM和SPAD阵列的核心技术原理与性能差异。APD作为线性模式工作的稳健选择,动态范围大;SiPM具备单光子探测和高增益优势;而SPAD阵列凭借像素级数字读出和集成TDC,在时间分辨率与系统集成度上领先。文章从灵敏度、时间精度、动态范围及系统成本等多维度剖析,为不同应用场景(如车载雷达、Flash LiDAR、消费电子)的芯片选型提供实战指南。

ik6789012的博客 660

不高兴的o( ̄ヘ ̄o#)JJ

题目描述 津津上初中了。妈妈认为津津应该更加用功学习,所以津津除了上学之外,还要参加妈妈为她报名的各科复习班。另外每周妈妈还会送她去学习朗诵、舞蹈和钢琴。但是津津如果一天上课超过八个小时就会不高兴,而且上得越久就会越不高兴。假设津津不会因为其它事不高兴,并且她的不高兴不会持续到第二天。请你帮忙检查一下津津下周的日程安排,看看下周她会不会不高兴;如果会的话,哪天最不高兴。 输入输出格式 输...

weixin_34005042的博客 177

CDO批量处理nc文件:5分钟搞定CMIP6数据双线性插值(附完整代码)

本文详细介绍了如何使用CDO工具链中的`remapbil`命令,快速实现CMIP6数据的批量双线性插值处理。通过环境配置、核心操作步骤、高级优化技巧及典型报错解决方案,帮助科研人员高效处理大规模nc文件,显著提升气象数据处理效率。

weixin_29267307的博客 296

【洛谷】P1085 [NOIP2004 普及组] 不高兴的津津

本题选自洛谷题库 原题传送门←戳一戳看原题 题意分析 这道题结合少许循环的内容,仍然以判断为主 题目大意为:津津七天上课,每天会有两个上课时间,两个上课时间的和即为当日上课总时间,总时间若大于8,则为不高兴。需要我们输出津津最不高兴的一天(有多日同样不高兴则输出靠前的一天) 理解:其实题目就是给出了十四个数据,两两一组,也就是七个综合数据(将每组数据相加)。七个综合数据比较大小,输出最大的那个数据的下标即可。当然不能忘记判断特殊的没有的情况。 一天一共就24小时,数据范围很小,直接int型就行了 代码实

Handsome_Dragon的博客 1275

告别配置迷茫:手把手教你用Vivado 2023.1配置Xilinx FPGA的DDR4 MIG IP核(含AXI接口详解)

本文详细介绍了如何在Vivado 2023.1中配置Xilinx FPGA的DDR4 MIG IP核,包括AXI接口的深度解析与优化。通过实战案例和调试技巧,帮助工程师快速掌握DDR4内存与FPGA的协同工作,提升系统性能。特别适合需要高性能计算和实时信号处理的开发者。

weixin_29231725的博客 440

Mamba-YOLOv8深度解析:基于状态空间模型的下一代目标检测架构(含完整代码与实战部署)文末含资料链接!

通过本文的完整指南,您将掌握从理论创新到工程落地的全流程技术细节。立即动手实践,开启目标检测的新纪元!

FJN110的博客 522

codeves天梯 不高兴的津津

津津上初中了。妈妈认为津津应该更加用功学习,所以津津除了上学之外,还要参加妈妈为她报名的各科复习班。另外每周妈妈还会送她去学习朗诵、舞蹈和钢琴。但是津津如果一天上课超过八个小时就会不高兴,而且上得越久就会越不高兴。假设津津不会因为其它事不高兴,并且她的不高兴不会持续到第二天。请你帮忙检查一下津津下周的日程安排,看看下周她会不会不高兴;如果会的话,哪天最不高兴。 分析:水== var

StrACPgirl的博客 690

【人工智能】OpenClaw网关API速率限制报错全解析 API rate limit reached. Please try again later.

对应HTTP标准状态码为429(请求过多)。该报错集中出现在OpenClaw GATEWAY DASHBOARD的聊天会话界面,核心特征为:用户最初以为是单一模型服务商的问题,先后更换OpenAI、Gemini、Ollama、Moonshot、Mercury-2等多个主流大模型API后,该报错仍稳定触发,尤其在执行复杂任务时高频出现。

奶爸的编程之路,也就一周冷个三天 6459

从洛谷P1085看信息学竞赛:如何高效处理每日数据统计问题

本文通过洛谷P1085题目解析信息学竞赛中的每日数据统计问题,探讨如何高效处理数据收集、转换与分析。文章对比不同算法的时间复杂度与可读性,提供代码优化技巧和竞赛实战建议,帮助参赛者在NOIP等竞赛中提升数据处理能力。

ll5678的博客 817

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

A1085 Perfect Sequence

1085 Perfect Sequence (25 分) Given a sequence of positive integers and another positive integer p. The sequence is said to be a perfect sequence if M≤m×p where M and m are the maximum and minimum num...

Highlight_Jin的博客 261

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

洛谷,P1085 [NOIP2004 普及组] 不高兴的津津C语言解法

if(h8) //计算总时长。不用数组及其他的解题方法如下。

weixin_46124814的博客 774

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

[PAT B1030/A1085]Perfect Sequence

[PAT B1030/A1085]Perfect Sequence 本题是PAT乙级1030题和甲级1085题,这里先放英文原题,如果要做乙级题的同学可以直接看后面的中文原题 题目描述 1085 Perfect Sequence (25 分)Given a sequence of positive integers and another positive integer p. The sequ...

欢迎来到我的编程小屋 633

PAT A1085 TwoPointers解法

一、题目: 二、代码: #include<cstdio> #include<algorithm> using namespace std; #define N_max 100001 int num[N_max]; int main() { int N, p; scanf("%d %d", &N, &p); for(int i =...

南七行者的博客 372

1085. Meeting

http://acm.timus.ru/problem.aspx?space=1&num=1085 简单floy 不过有细节需要注意 首先是常识性的 tram 好像是环行的 还有就是如果有月票他不需要花钱但前提他要去的点有路可走 代码: #include<iostream> #include<stdio.h> #include<string...

weixin_30871701的博客 79

关于欧拉函数及Sicily1085的解法

<br />1. 数论中的欧拉函数复习<br />F(x): 1~x中与x互质的数的个数,称为欧拉函数<br />欧拉函数是积性函数,即F(x*y)=F(x)*F(y),如果x和y互质<br />另外:F(x)=x-1,如果x是素数<br />F(xp)=xp-xp-1=xp-1*(x-1)<br />于是关于欧拉函数的求法如下:F(x)=F(x1p1*x2p2*...xnpn),然后采用上式求解<br />代码如下:<br />long long emular(int x) { long long

冰上极光的专栏 831

洛谷P1085 [NOIP2004 普及组] 不高兴的津津的python解法

妈妈认为津津应该更加用功学习,所以津津除了上学之外,还要参加妈妈为她报名的各科复习班。但是津津如果一天上课超过八个小时就会不高兴,而且上得越久就会越不高兴。假设津津不会因为其它事不高兴,并且她的不高兴不会持续到第二天。如果不会不高兴则输出 00,如果会则输出最不高兴的是周几(用 1,2,3,4,5,6,71,2,3,4,5,6,7 分别表示周一,周二,周三,周四,周五,周六,周日)。每行包括两个小于 1010 的非负整数,用空格隔开,分别表示津津在学校上课的时间和妈妈安排她上课的时间。

Steins_Gate_0的博客 629

P1085 [NOIP2004 普及组] 不高兴的津津

加油!~

m0_63613132的博客 218

洛谷:P1085 [NOIP2004 普及组] 不高兴的津津 JAVA

JAVA洛谷

m0_59321697的博客 658

[PAT-A 1085]Perfect Sequence

题目大意: 给定一个正整数数列和正整数p,设这个数列中最大值是M,最小值是m,如果M<m*p,则称这个数列是完美数列 给定参数p和一些正整数,从中选择尽可能多的数构成一个完美数列。求选择出的数的个数. 即从N个正整数中选择若干个数,使得选出的这些数中的最大值不超过最小值的p倍,问满足条件的选择方案中,选出的数的最大个数。 思路: 1)将数列从小到大排序。 2)从左至右扫描序列,对其中的每一...

RegulusF的博客 241

1085 Perfect Sequence (25 分)——3种解法(二分、two pointers)

Given a sequence of positive integers and another positive integerp. The sequence is said to be aperfect sequenceifM≤m×pwhereMandmare the maximum and minimum numbers in the sequence, respe...

韩江雪de 小屋 563

PTA甲级1085 Perfect Sequence (25分)

首先,先贴柳神的博客 https://www.liuchuo.net/ 这是地址 想要刷好PTA,强烈推荐柳神的博客,和算法笔记 题目原文 1085 Perfect Sequence (25分) Given a sequence of positive integers and another positive integer p. The sequence is said to be a per...

Huangpengyu123的博客 258
下一篇: 零基础学python第零课
ilikepython123
博客等级 码龄4年 4粉丝 4原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值