HDU 1029 出现次数最多(不解)

HDU1029伊格内修斯和公主四世(题解) 原题链接:HDU1029 问题描述 “好的,你还不错,嗯……但是你永远都不能通过下一个测试。” feng5166说。 “我先告诉你一个奇数N,然后是N个整数。其中会有一个特殊的整数,在我告诉你所有整数之后,你必须告诉我哪个整数是特殊的整数。” feng5166说。 “但是特殊整数的特征是什么?” 伊格内修斯问。 feng5166说:“该整数将至少出现(N + 1)/ 2次。如果找不到正确的整数,我... 阅读详情

            我对这道题表示不解!明明题目没有什么限制条件,居然用以下第一种代码也过了。

            代码一:(虽过了,但个人觉得是错误答案!)

#include<iostream>
using namespace std;

int a[32768];

int main()
{
	int i,tem,n;

	while(cin>>n)
	{
		memset(a,0,sizeof(a));

		for(i=0;i<n;i++)
		{
			cin>>tem;

			a[tem]++;
		}

		for(i=0;i<32768;i++)
		{
			if(a[i]>=(n+1)/2)
			{
				cout<<i<<endl;
				break;
			}
		}
	}

	return 0;
}


       代码二(正解)(非本人原创,来源网络):

#include<iostream>
using namespace std;

int main()
{
	int n;

	while(cin>>n)
	{
		int time=0,ans,num;

		while(n--)
		{
			cin>>num;

			if(time==0)
			{
				ans=num;
				time++;
			}
			else
			{
				if(num==ans)
					time++;
				else
					time--;
			}
		}

		cout<<ans<<endl;
	}

	return 0;
}

             分析下第二个代码:n是个奇数,要求一个数至少出现(n+1)/2次。用time来记录解出现的次数,出现了正确解就令time自增1,不是正确解就使time自减1。

     那么,正确解对应的time一定是不小于1的。可以用一个极端的例子来说明下:输入3 3 3 3 3 3 2 1 5 6 8,开始当ans=3时,time=6,那么继续执行num!=3了,

     time开始自减,但最终time=1,始终不会进入程序if(time==0){}内部执行了。

     利用最终的time,还可以计算出解出现的次数。公式为:(n-time)/2+time。


Mooncake架构:基于KVCache解耦的LLM推理优化方案 在大语言模型推理中,KVCache是Transformer解码过程中用于缓存历史Key/Value向量的核心数据结构,它避免了序列重复计算,但会随上下文长度线性增长,成为显存占用的主要部分。其原理是在自回归生成时,将已计算过的注意力键值对存储下来,供后续Token生成时直接使用,从而提升计算效率。这项技术的核心价值在于,通过高效管理KVCache,可以显著降低长序列推理时的显存压力,提升GPU资源利用率。在实际应用场景中,尤其是在处理长上下文对话、高并发请求时,KVCache的管理策略直接决定了服务的吞吐量 阅读详情

相关推荐

3D美术14——max——fbx导入max后直接生成bip人形骨骼插件

最近经常会从unity里反八FBX到max里进行2次修改。 但是非常尴尬的事情就是,就是用max做的fbx,你在反导入回来,BIP骨骼都会变成预制体。这个时候有一个方法补救。那就是在导入的时候调整一下参数。(如下图) 把这里调整成设置为骨骼。就还可以了。 但是,如果你不是用max做的FBX。呵呵,那么你一定很头大,因为完全没有用。 所以,这个时候就要上插件了。 Autofbxtobip v.1.1 这个插件适用于2015及其以上版本。 在这之前我还用过一款叫BIPPY,但是效果相当感人,照着这个图片调整

qq_37576129的博客 1万+

kuangbin带你飞系列目录与简介

kuangbin带你飞系列是由ACM圈内的一个菊苣,上海大学的邝斌(现已研究生毕业,就职于谷歌),在vjudge平台上建立的一个题目系列,从最简单的暴力搜索,到各种高深的算法与数据结构,几乎无所不包,这一套刷下来对于每一位打ACM的人来说都将是一次水平的飞跃。 目录链接:https://cn.vjudge.net/article/187 题目分级及建议顺序链接:ACM 的正确入门方式是什么? ...

Izayoi_w的博客 1万+

Revit二次开发之获取钢筋(Rebar)的线(Line)

这里写自定义目录标题欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入 欢迎使用Markdown编辑器 你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Mar

qq_25986069的博客 1312

[kuangbin带你飞] 专题一 简单搜索 题解(超详细注释,史上最强题解)

[kuangbin带你飞] 专题一 简单搜索 题解(超详细注释,史上最强题解)

m0_60962081的博客 5544

逆变器技术解析:DDSRF双解耦在正负序分离中的关键作用

本文深入解析了DDSRF双解耦技术在逆变器正负序分离中的关键作用。通过建立正反旋转坐标系并利用交叉反馈解耦网络,DDSRF能快速、精准地分离电网电压中的正负序分量,从而显著提升锁相环在电网不平衡条件下的精度与系统稳定性,是现代高性能并网逆变器的核心算法之一。

m3n5b7v8c9x的博客 413

告别有线:用PVE直通无线网卡,打造一台真正的‘无线’Win10软路由/测试机

本文详细介绍了如何通过PVE直通无线网卡技术,构建全无线Win10软路由或测试机。从硬件选型、PVE环境配置到PCIe和USB双模直通技术,逐步指导实现Wi-Fi AP和蓝牙连接功能,为家庭实验室和小型办公环境提供灵活高效的网络解决方案。

weixin_28683689的博客 588

kuangbin带你飞专题合集

[kuangbin带你飞]专题一 简单搜索 [kuangbin带你飞]专题二 搜索进阶...

繁凡さん的博客 2643

立创EDA实战:基于NE555的夜间氛围呼吸灯电路设计与模式切换

本文详细介绍了使用立创EDA设计基于NE555芯片的夜间氛围呼吸灯电路。项目核心是利用NE555产生PWM信号,并通过RC充放电电路实现LED亮度的缓慢周期性变化,形成呼吸效果。文章手把手教学,涵盖从电路原理分析、元件参数计算,到在立创EDA中进行原理图绘制、PCB布局布线,直至焊接调试的完整硬件设计流程,是电子爱好者入门实战的经典项目。

weixin_42153793的博客 126

HDU-1029题解

题意很简单,给你一堆数字,让你找出这堆数字中相同次数大于 (n+1)/2的 思路: 一开始想的是map,后来发现还有更省时间和空间的做法: long long a;int b; while (scanf("%d", &n) != EOF) { int num,count; count=0; for (int i = 0; i < n; i++) { scanf("%lld", &a);

刘其琦的博客 272

XRoboToolkit —— 基于 PICO 4 Ultra 的机器人遥操作方案(一)

视觉-语言-动作模型(Vision-Language-Action models)的快速发展催生了对大规模、高质量机器人演示数据集的迫切需求。尽管遥操作是数据采集的主要方法,但现有方法存在可扩展性有限、设置流程复杂以及数据质量不佳等问题。本文提出XRoboToolkit,这是一个基于OpenXR标准的跨平台扩展现实(XR)机器人遥操作框架。该系统具备低延迟立体视觉反馈、基于优化的逆运动学算法,并支持多种跟踪模态,包括头部、控制器、手部及辅助运动追踪器。

2506_90492529的博客 3318

YOLOv11目标检测模型性能评价指标详解,涉及混淆矩阵、F1-Score、IoU、mAP、参数量、计算量等,一文打尽所有评价指标

本文主要讲解的是计算机视觉网络模型的性能评价指标,这是每一篇论文中都需要展示的内容。熟悉每一个评价指标也能够帮助我们在训练和改进模型过程中,更好的观察模型的变化效果。

Limiiiing的博客 8414

“kuangbin带你飞”专题计划——专题一:简单搜索

kuangbin带你飞 1.难以提升emmmm。试着埋头搞专题,看能不能提升效率。 2.顺便当是复习了蓝桥杯了。 专题一:简单搜索 1.POJ-1321-棋盘问题 标签:暴力,搜索 题解:直接暴力,注意不要重复搜索 代码:我自己看的话点题目的链接就好了。粘贴在这里太繁琐,就没弄了。 2. ...

I_have_a_world的博客 476

机器学习扩散模型简介

​ 扩散模型是生成模型,在过去几年中越来越受欢迎,这是有充分理由的。仅在 2020 年代发布的几篇开创性论文就向世界展示了 Diffusion 模型的能力,例如在图像合成方面击败 GAN[6]。最近,从业者将看到DALL-E 2(OpenAI 上个月发布的图像生成模型)中使用的扩散模型。

gongdiwudu的专栏 4271

HDU1029——Ignatius and the Princess IV,HDU1030——Delta-wave,HDU1031——Design T-Shirt

列的矩阵,计算每列的总和,然后找出总和最大的前k列并按照要求的格式输出这些列的索引。这种类型的代码常见于数据分析、统计排序等问题中,尤其是需要根据数据集中的数值进行排序和筛选的场景。函数来估计最近的完全平方数的根,然后加1以确定行号。这是因为每行的左斜线坐标是线性递增的,而且行内第一个点的左斜线坐标为1。计算方法与左斜线坐标类似,但使用了不同的公式,考虑到右斜线坐标的特性。:接下来,代码计算了三个方向上的差异:行、左斜线和右斜线。:最后,将这三个差异相加,并输出结果,这就是两个点在该特殊坐标系下的总距离。

u014114223的博客 1980

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

lwip-2.0.3

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

hdu-1029 Ignatius and the Princess IV

hdu-1029 Ignatius and the Princess IV题目描述 Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32767 K (Java/Others)Total Submission(s): 28646    Accepted S

oYinGui1 1333

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

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

HDOJ 1029 Ignatius and the Princess IV

题意:求n个数中个数最多的数 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1029 思路:map维护即可 注意点:无 以下为AC代码: Run ID Submit Time Judge Status Pro.ID Exe.Time Exe.Memory Code Len. Language Author

luminous11的专栏 370

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

hdu 1029

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1029 这本来是一道水题,但是还是错了很多次,因为有可能没有解,不用输出。也可以利用排序。 写这篇博客,主要是一种思想, 参考代码:http://blog.sina.com.cn/s/blog_ace0c3ed01016v66.html 利用两个数进行pk,比如说:1 2 3 4

youlingjisuan的专栏 555

HDU1029 Ignatius and the Princess IV(数组中出现次数最多的数)

题目:HDU1029 Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32767 K (Java/Others) Total Submission(s): 44112Accepted Submission(s): 19470 Problem De...

CarreLiu 198

HDU 1029 Ignatius and the Princess IV 【桶 | 排序】

题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1029 ★这题我用的最机械(愚蠢 )的方法,一个装数字的桶,然而简单的方法也有awa,我用三种方法解决 翻译: 再次感谢 kuangbin的基础DP训练 中的翻译,但不知道这题跟DP啥关系233 思路: 方法一:通过一个桶(数组),若出现的数a,num[a]++;输入完后 循环一次,num[i]大...

HungTeen的博客 253

HDU1029

Ignatius and the Princess IV Problem Description "OK, you are not too bad, em... But you can never pass the next test." feng5166 says. "I will tell you an odd number N, and then N integers. T

wyj_2016的博客 226

hdu1029

hdu1029 找出数列中出现(N+1)/2次的数,暴力模拟 1 #include<stdio.h> 2 #include<map> 3 using namespace std; 4 5 int main(){ 6 int n; 7 while(scanf("%d",&n)!=EOF){ 8 ...

weixin_34342578的博客 94

kuangbin专题十二 HDU1029 Ignatius and the Princess IV

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1029 被专题的第一题吓到了,以为还是一道难题,就复杂考虑了。排序,然后 dp[i] = (a[i] == a[i-1]) ? dp[i-1] + 1 : 1 后来才发现必定有解,直接输出就可以了 AC代码: #include &lt;iostream&gt; #include &lt;stdi...

ACMerszl的博客 198

hdu_1029_hash/map

http://acm.hdu.edu.cn/showproblem.php?pid=1029 太水了,一次过,直接上代码吧,只想说最愚蠢的hash都要比map快! 1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<cmath> ...

weixin_30920513的博客 105

HDU1029 Ignatius and the Princess IV

问题链接:HDU1029 Ignatius and the Princess IV。基础练习题,用C++语言编写。 题意简述:输入n(n是奇数),然后输入n个整数,求出现(n+1)/2次的整数。 问题分析:n是奇数,(n+1)/2是n的一半以上,只要将n个数据排序,出现(n+1)/2次的整数必然会出现在中间位置。 本问题使用C++语言编写的原因是函数sort()...

weixin_34406061的博客 89
上一篇: heap_sort
下一篇: HDU1128 self number("优化"版暴力)
lulipeng_cpp
博客等级 码龄15年 169粉丝 130原创
评论 5
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值