c中的阵列谜语 [英] array riddle in c

查看:74
本文介绍了c中的阵列谜语的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个大小为n的数组,并以随机顺序填充从1

到n的连续整数,即[1,2 ... n-1,n]。两个整数被移除,

意味着将零置于其位置。给O(n)高效算法

找到它们?

解决方案

" puzzlecracker" < IR ********* @ gmail.com>在消息中写道

news:11 ********************* @ f14g2000cwb.googlegro ups.com ...

给定一个大小为n的数组,并以随机顺序填充从1
到n的连续整数,即[1,2 ... n-1,n]。删除了两个整数,意味着将零置于其位置。给O(n)高效的算法找到它们吗?




请尝试做自己的功课。如果您需要

帮助,请咨询您的老师。一定要问你的b $ b老师O(n)意味着什么,那么答案应该是明显的。


" puzzlecracker" < IR ********* @ gmail.com>写道:

给定一个大小为n的数组,并以随机顺序填充从1
到n的连续整数,即[1,2 ... n-1,n] 。删除了两个整数,意味着将零置于其位置。给O(n)高效算法找到它们?




使用位向量,需要O(n)时间和空间。

-

如果我曾告诉过你一次,我已经告诉过你LLONG_MAX次,不要夸大夸张。

- 杰克克莱恩


>位向量

没有额外空间!


Given an array of size n and populated with consecutive integers from 1
to n i.e. [1, 2...n-1, n] in random order. Two integers are removed,
meaning zero is placed in their places. Give O (n) efficient algorithm
to find them?

解决方案

"puzzlecracker" <ir*********@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...

Given an array of size n and populated with consecutive integers from 1
to n i.e. [1, 2...n-1, n] in random order. Two integers are removed,
meaning zero is placed in their places. Give O (n) efficient algorithm
to find them?



Please try to do your own homework. If you need
help, then ask your teacher. Be sure to ask your
teacher what O(n) means, then the answer should
become obvious.


"puzzlecracker" <ir*********@gmail.com> writes:

Given an array of size n and populated with consecutive integers from 1
to n i.e. [1, 2...n-1, n] in random order. Two integers are removed,
meaning zero is placed in their places. Give O (n) efficient algorithm
to find them?



Use a bit vector, requiring O(n) time and space.
--
"If I''ve told you once, I''ve told you LLONG_MAX times not to
exaggerate."
--Jack Klein


>bit vector
No extra space!


这篇关于c中的阵列谜语的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆