由买买提看人间百态

topics

全部话题 - 话题: array
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
h******o
发帖数: 334
1
谢谢回复!
我想把每一列的值存入一个1D array,这样循环存入。不知道能不能直接把2D array的
每列的值通过index直接存入一个新的1D array?
h******o
发帖数: 334
2
A .txt file. Use the below java code to read the file and use a 2-D array (
one dimension for the users and other dimension for the products) to store
the order#. Also, use a dictionary to map each users to its corresponding
array row. How to replace the missing value with 0 in the 2D array?
Users, Products, order#:
name1 p1 5
name1 p2
name1 p3 2
name2 p1 3
name2 p2 1
name2 p3
name3 p1 5
name3 p2
name3 p3 2
name4 p1 3
name4... 阅读全帖
x*****u
发帖数: 3419
3
来自主题: Computation版 - 再请教Re: 请教大家c++ array
首先谢谢大家的回帖,受益良多。
在下还有一件极幼稚的事情不明,还望大家帮忙解释解释。
不知道大家用过MTL(The Matrix Template
Library)没有。当我使用MTL里面的Matrix时,发现运行速度降低。于是我做了一个比较

发现MTL array的执行效率,低于c++ array。对于我使用的这个算例,竟有四倍之差!
*************************
the dimension is 301*301
using c++ dynamic array...
using SOR ...
the relax factor = 1.8
time in the solver(sec): 44.91
interations 11669 ~~~~
Norm of error < 0.000159678
*****************
the dimension is 301*301
using MTL array...
using SOR ...
the relax factor = 1.8
time in the solver(sec):
a***r
发帖数: 420
4
来自主题: Computation版 - [C++]string array?
我有一个n*m的dataset,里面的信息是两个没有顺序的字母,ie.A B,B C,C B...
因为dataset很大,打算用C++处理,有个基础问题,网上教程老看不明白,
就是如何建立一个string的array?
比如在把这些信息存入C++的array时,我现在是建了一个三维的char数组,可否/如何
直接建立一个
string的二维数组呢?
如果上面这个问题成立,即如果可以有string的数组
有什么好办法可以把一个string分成指定大小,存入指定长度的string的数组呢?
比如我为了sql方便,把每行的m个col合成一个field
相当于成了一维的string数组
然后我在mysql里面sort啥的完了
用getline(cin,line),重新读入c++的二维数组,这时我希望把这个field按两个两
个放到
string的array里,但是getline似乎没有相应的命令,或者,我应该在合成field的时
候,就在每
两个字母间加个delimiter,然后用getline(cin,line,delim)?
另外,从generally的来说,string,是不是可以完全... 阅读全帖
s********8
发帖数: 50
5
thanks !
but what I want is put them in an array.
Array abc(*) Q29B4B--Q29B30B (if they are next to each other in dataset.
and
Array abc(*) Q29B4B-Q29B30B (in SAS, it didn't work out)
so I am thinking if there is a smart way to do instead of
Array abc(*) Q29B4B Q29B5B Q29B6B,,,,,,,,,,,Q29B30B (type one by one)
any hint?
thanks
n**m
发帖数: 156
6
来自主题: Statistics版 - 怎么给新的array名字加一个前缀
array new(3) jan feb mar;
array old(3) log_jan log_feb log_mar:
* do loop * take log for every variable in array
但是array比较长,没法一个一个列,我记得以前看到过,可以用一句话表示,在原来
的var名字上加一个前缀。
有没有人知道怎么做。谢谢。
x***y
发帖数: 633
7
we can reduce it to 2 arrays problem...First compare the median of 3 arrays, if A[n/2] C[0:n/2-1] together, we can find the median of these two in logn, compare
it witht the median of B, eliminate corresponding part of B and A, C
combination. To do it in A, C combination, we have to find the position of
median in both A and C, O(logn) time. This B and A,C combination is just a 2
array problem except to find median and do e
w**********8
发帖数: 121
8
I was trying to reduce the problem to 2 arrays but I did not succeed. In
your solution, even if you find median of A and C. How do you compare it
with B to find the median of A, B,C.
A:1 4 6 10 18
B:22 28 33 45 58
C:7 9 100 180 200
you find the median of A and C is 9 or 10. Tell me how do you use them to
find the median of 3 arrays.

arrays, if A[n/2] A[n/2:n-1] and
2
h********0
发帖数: 440
9
来自主题: JobHunting版 - discuss an array rearrange question
given an array with data like: a1 a2... an b1 b2 ...bn
Change the array to a1 b1 a2 b2 ... an bn
看到career cup上这个题目可以用divide and conquer,但是那个exchange的部分我
test了几个情况,好像都有问
题。
Rough idea:
find the middle index r = floor((p+q)/2)
It partitions the array to part 1 [p, r] and part2 [r+1, q]
then exchange the second half of part [(p+r)/2...r] and the first half of
part 2 [r+1, (r+q)/2]
recursively call this function.
Initially, call this function func(p,q) use parameters p=1,q=2n
Test case 1: a1 a2 a3 a
a*u
发帖数: 97
10
来自主题: JobHunting版 - 请教suffix array的问题
给一个string建立suffix array,然后sort这些substrings,复杂度是多少?O(nlgn)
or O(n^2lgn)?
比如 String "bananna", size n = 7
suffix array
{
banana
anana
nana
ana
na
a
}
after sorting
{
a
ana
anana
banana
na
nana
}
for a string size n, creating the suffix array is O(n), sorting is supposed
to be O(nlgn), but I somehow feel it is O(n^2lgn), since the comparison
between two substrings are O(n).
Where did I miss?
b******n
发帖数: 823
11
http://www.mitbbs.com/article/JobHunting/31548441_0.html
每个array取第k/2个元素比较,假设array1较小,那么array1的前k/2个元素必然在2个
array的前k小中,干掉这k/2个元素,找2个array剩下的第k/2小元素,recursion。
log k
h*****g
发帖数: 944
12
来自主题: JobHunting版 - C++里get array size的问题
C++里是不是现在没有现成的get array size/length的function??
如果没有的话,我在网上看到了一个code
#include
template char (&array(T(&)[N]))[N];
#define length(a) (sizeof a / sizeof a[0])
int main()
{
int a[10];
std::cout << sizeof array(a) << '\n';
std::cout << length(a) << '\n';
}
请问这个code对所有的data type都work吗? 我试试了,好象是可以的。中间有什么错
误吗?
j*****g
发帖数: 223
13
yours is essentially what roufoo said:
发信人: roufoo (五经勤向窗前读), 信区: JobHunting
标 题: Re: MMD, 死在了longest contiguous increasing sub-array上了.
发信站: BBS 未名空间站 (Fri Oct 29 01:57:19 2010, 美东)
if the # of rest elements is smaller than or equal to len, and a[i]>=a[i+1
]
then exit?
this only improves slightly near the end of the array. if the array is very
long, then the improvement is so small that is negligible.
l****n
发帖数: 844
14
来自主题: JobHunting版 - NGS/Array Job opportunity -Illumina (转载)
【 以下文字转载自 Biology 讨论区 】
发信人: linden (说LP不对的参见第一条), 信区: Biology
标 题: NGS/Array Job opportunity -Illumina
关键字: job Illumina
发信站: BBS 未名空间站 (Tue Nov 2 13:59:09 2010, 美东)
希望能帮到自己人. New graduate/postdoc有做NGS或array的找工作看过来. 这个
position主要侧重technology/method development. Hiring manager希望找
biotechnology方面有经验的.
Advanced Research group in Illumina is currently looking for an assay
technology scientist, the person will play an integral role in
developing innovative assay technologies for second-generation
... 阅读全帖
g***s
发帖数: 3811
15
来自主题: JobHunting版 - find median for k sorted arrays
1. put all number into one array, size = k*n O(k*n)
2. find the median of the array O(k*n)
I think LZ is asking for a better solution since the above method doesn't
care if it is sorted or not in the k arrays.
【 在 lolhaha (haha) 的大作中提到: 】
B*******1
发帖数: 2454
16
谢谢dino
再弱问
这问题不是用presum array就可以解决了? 看不是很懂那code
int A[]={1,2,3,4,5,-9,-5,0,4};
presum array {1,3,6,10,15,6,1,1,5};
不就是找presum array里面 相等得2个数之间的间隔吗?
难道我哪里错了?
v***a
发帖数: 365
17
WC2009有篇论文有suffix array的实现,非常精简,但是要说明的话……谁能在20分钟
内教会面试官Suffix Array呢,除非他也懂……
当年算法老师花了2节课,3个小时才讲完基本的 Suffix Array,然后有一半多学生退
课了
论文:http://boj.5d6d.com/thread-3181-1-1.html
关键是论文里面的应用,都是很难的题目,
如果有公司面试考这种级别的程序,麻烦告诉我一下……
Y******l
发帖数: 19
18
Given an array of N integers from range [0, N] and one is missing. Find the
missing number.
1) how to find the missing number if the element of array is integer value
2) if the element of the array is a bit vector, presenting the integer
number. for example, 000 --> 0, 010 --> 2.
o*******y
发帖数: 115
19
题目是给定一个unsorted int array, 怎么找到第一个大于0,并且不在此array的
integer。
比如[1,2,0] return 3, [3,4,-1,1] return 2
版上找到的题 据说有time O(n), constant space的解
讨论一下哈
d**0
发帖数: 124
20
来自主题: JobHunting版 - Quick selection for k unsorted arrays
请教一个题目: k个unsorted arrays,假设都是n个元素。怎么样快速求出median?
不能把所有的array拼到一起再做quick selection。
我用类似quick selection的方法使用同一个pivot element在k个arrays里quick
select,再求 方法应该是这样,但是复杂度分析不出来。一个naive的bound是o(kn),但是这样就和拼
到一起做quick select一样。最后猜了一个o(nlogk)但是自己也不是很信服。
请大牛指教,谢谢!
y*****n
发帖数: 243
21
put all elements of one array into an hashtable, then scan another array to
check if current element is in hashtable, if yes then current element is
belong to intersection.
for union, just use hashset, put all elements in two arrays in hashset, then
the elements in hashset is what you want.
hashset will not permit repeated elements(at least in java= =)
l*********8
发帖数: 4642
22
来自主题: JobHunting版 - Rotating an array in place
Another method (Block swap algorithm for array rotation):
void swapBlock(int a[], int block1, int block2, int blockSize)
{
int block1End = block1 + blockSize;
while (block1 < block1End) {
int tmp = a[block1];
a[block1++] = a[block2];
a[block2++] = tmp;
}
}
void leftRotate(int a[], size_t N, int k)
{
if (N<2) return;
k = (k%N + N) % N;
if (k == 0) return;
int start = 0; // start index of unprocessed array
int end = N; // end index of unprocessed array
int leftK ... 阅读全帖
e***n
发帖数: 42
23
第一遍扫描array用hashmap存array[i],
第二遍扫描找出hashmap(target - array[i])
但是如果遇到重复多次的数(如下例程 x=5)且x+x=target=10, C++ 的hashtable (
map) 就只存第一次出现的x 请问有什么办法解决?
#include
#include
#define N 12
using namespace std;
void find2SumTarget(int arr[N], int target){
map hashT;
int i;
map::iterator m;
for (i=0; i hashT.insert(make_pair(arr[i], i));
}
for (i=0; i m = hashT.find(target - arr[i]);
if ( m!=hashT.end() && i!=... 阅读全帖
j*****n
发帖数: 1545
24
来自主题: JobHunting版 - 问1道array hop的题
没想明白,这个是DP还是什么?
Start with an array A of positive numbers. Start at index 0. From index i,
you can move to index i+x for any x <= A[i]. The goal is to find the minimum
number of moves needed to get to the end of the array.
更新,面试时候的题目说这个array 只是非负,会有0的情况,跳那就卡死了。
请指教....
d****n
发帖数: 1637
25
来自主题: JobHunting版 - find index of an element in sorted array
size_t left, right, found;
size_t found=bsearch(array, start, end, target );
left=right=found;
while (array[left--]==target) left=found;
while (array[right++]==target) right=found;
return left, right
d********t
发帖数: 51
26
来自主题: JobHunting版 - 请教一个题: Median of Two Sorted Arrays
Median of Two Sorted Arrays
There are two sorted arrays A and B of size m and n respectively. Find the
median of the two sorted arrays. The overall run time complexity should be O
(log (m+n)).
解答如下:
问题1> max(0, (m-n)/2)和min(m-1, (m+n)/2)用处是什么
问题2> 这个解答的总体思路是什么
多谢了
double findMedianSortedArrays2(int A[], int m, int B[], int n) {
return findMedianHelper2(A, m, B, n, max(0, (m-n)/2), min(m-1, (m+n)
/2));
};
double findMedianHelper(const int A[], const int m, const int B[], const
int... 阅读全帖
g*****e
发帖数: 282
27
k sorted array merge有很多解法,根据各array长短的情况各种算法效率各异。大家
一般还是选择建个k heap而不是每次选两个array merge吧?那样的话写个heap实现还
是挺麻烦的。能假设有现成的min heap或者max heap可以调用么?哪位朋友实际面试里
碰到过的讲讲吧。多谢!
c*******t
发帖数: 1095
28
来自主题: JobHunting版 - 问求array中3个数和最接近k的解法
O(n^2)下面这段code有反例么? 没想出来反例

for(each ele in the sorted array)
{
ele = arr[i] - k;
let front be the pointer to the front of the array;
let rear be the pointer to the rear element of the array.;
// till front is not greater than rear.
while(front <= rear)
{
if(*front *rear == ele)
{
print "Found triplet "<<*front<<","<<*rear<<","< break;
}
else
{
// sum is > ele, so ... 阅读全帖
a******3
发帖数: 113
29
来自主题: JobHunting版 - Scala怎么通过index访问set或者array

def keyIterator: Iterator[Key] = new Iterator[Key] {
val newMap=getMapClone
var array=newMap.keySet().toArray
var pos = 0
def hasNext = pos < newMap.size()
def next: Key = { val z = array(pos) ; pos += 1 ; z }
}
[error] found : z.type (with underlying type Object)
[error] required: Key
[error] def next: Key = { val z = array(pos) ; pos += 1 ; z }
[error] one error found
然后变成获取的内容有问题了。。
n****r
发帖数: 120
30
An operation "swap" means removing an element from the array and appending
it at the back of the same array. Find the minimum number of "swaps" needed
to sort that array.
Eg :- 3124
Output: 2 (3124->1243->1234)
x*****0
发帖数: 452
31
关于这道题的时间复杂度,有个疑问。
基本算法是参考
ref1:
http://www2.myoops.org/course_material/mit/NR/rdonlyres/Electri

ref2:
http://leetcode.com/2011/03/median-of-two-sorted-arrays.html#co
来做的。
大致介绍一下ref1中所描述的算法,基本思路是binary search.
假设数组A和B,长度分别为nA和nB。nA+nB=n。
(1)median 不是在A中就是在B中。(基本是一句废话,:-))
(2)选择数组A的median,假设其index为i=(l+r)/2(初始时l=0,r=nA-1)。比较A[i
]和B[j],B[j+1],j=n/2 - i - 1。j做如此选择,是因为如果A[i]是meidian of two
sorted arrays的话,A[i]必须大于B中的j个元素。
(3)如果B[j]<=A[i]<=B[j+1],那么A[i]必定是我们要找的结果。
(4)如果A[i]阅读全帖
H**r
发帖数: 10015
32
来自主题: JobHunting版 - python的list和array是一个东西?
python里面有array,和C的array作用差不多
用array稍微performance好一点有的时候
coursera有个米饭大学的python课程,有一个小project可以做做,很简单的那种。
m*******i
发帖数: 34
33
来自主题: JobHunting版 - 请问一个关于array median 的问题
求一个array的median的值, 但是这个array有duplicate的元素, median该怎么算,
比如, array=[3, 3, 5] 或 [3, 3, 3, 5],那median是什么?
谢谢。
a********9
发帖数: 129
34
来自主题: JobHunting版 - 请问一个关于array median 的问题
还是照算啊,第一个是奇数个, 就取最中间的,array[1],就是3
第二个是偶数,应该是取中间的两个再取平均值,(array[1]+array[2])/2 = 3
d******w
发帖数: 2213
35
这个其实蛮难的。经典的做法是sort两个array,然后用merge sort的思想来做。相通了
很好做,没相通就卡了。
投机取巧的办法就是把一个array放到hash set里去,然后看另一个array那些数也在
hash set里面。
你要是看人顺眼,就重新问人一道题好了

吗?
S*******C
发帖数: 822
36
来自主题: JobHunting版 - find union for 2 arrays不准用Set怎么做
find union and intersection for 2 arrays without using sets/other data
structure
难道只能先对较长的array排序,再对另一个array中的元素用binary search一一查询
?有没有更好的方法?
a**********0
发帖数: 422
37
来自主题: JobHunting版 - reverse an array
请教个关于reverse array的算法问题
question 1: Do not use any extra space but just the two iterators to reverse
an array.
question 2: Use just one iterator and no extra space and reverse an array.
Thanks!
z*l
发帖数: 30
38
easy....the data in a array are allocated in a linear manner. So any element
in
the array could be fetched by getting the data at array[0] + offset*size_t;

time)
s*****w
发帖数: 215
39
来自主题: DotNet版 - 问一个Array Sort的问题
因为平常处理大量数据的时候都是import到database里面的。所以没有想过这个问题。
最近遇到一个问题,是关于Array Sort的。
Array有Array.Sort()方法,看了msdn说他用了Quick Sort Algorithem. The average
the method is O(nlogn) operation, the worst case it is an O(n^2) operation.
这是不是意味着,我们处理这些数据的时候没有必要自己写binary tree的data struct
ure,(C#里面没有BinaryTree的data type),因为BTree是O(nlogn) operation. 如果
自己写BTree,好处在哪里?
y********o
发帖数: 2565
40
Thanks a lot! Yes, I also do for loop, but I had thought that there must be
some smarter way of doing that. The one you offered looks good.
发信人: goodbug (好虫), 信区: Java
标 题: Re: How to check if an element is in an array?
发信站: BBS 未名空间站 (Thu Nov 23 11:38:48 2006), 转信
People usually do a for loop to check, if you are really lazy,
try Arrays.asList(array).contains()
s*******y
发帖数: 558
41
来自主题: Java版 - array to list
Hi I have a stupid question: how to convert an array to a list?
For example, I want to convert double [] a = {1.0, 2.0}; to a type of List<
Double>.
How to do it without using a loop to visit every element in the array?
I tried Arrays.asList but got an "incompatible type" error message.
Thanks
s******d
发帖数: 901
42
来自主题: Java版 - oracle help: pass array to oracle SP
有没有人碰到过这个问题?
I created an oracle stored procedure that takes DBMS_SQL.NUMBER_TABLE as one
of the input parameters, but when executing this SP by Java, i did
something like
ArrayDescriptor descriptorID = ArrayDescriptor.createDescriptor( "DBMS_SQL.
NUMBER_TABLE", connection );
ARRAY array_ID = new ARRAY( descriptorID, connection, values));
values is an array of integers. Running the app will fail at the line of
creating descriptor. The error is as following:
java.lang.ClassCastException:org.apac... 阅读全帖
r******r
发帖数: 700
43
不知你们说的哪个 Array, 我是说这个:
java.lang.Object
extended by java.lang.reflect.Array
楼主用的是大写的 Array,这个看上去就是个 utility class.
g*****g
发帖数: 34805
44
ArrayList is backed by an array, in case you need high performance, a good
initialization parameter matters.
Array is only for reflection, you are probably talking about Arrays.
d****i
发帖数: 4809
45
来自主题: Java版 - error: generic array creation
You need to use the following to create a generic array. Java's generics has
type erasure, so you can't create generic array at compile-time since it
needs runtime info.
public static > void sort(T[] a, Class clazz) {
T[] tmp = (T[]) Array.newInstance(clazz, a.length);
}
Or you can just use ArrayList directly without the hassle.
yy
发帖数: 45
46
来自主题: Programming版 - 何谓 heap array?
看more effective c++:
有个地方说到 heap array,
请问什么是heap array, 它何non-heap array 有什么区别?
Thanks a lot1
c********e
发帖数: 383
47
来自主题: Programming版 - 何谓 heap array?
array on heap and array on stack.
in general c++ doesnt go well with old-style array, there are just way too
many cavities for ppl to handle.
c*******d
发帖数: 353
48
来自主题: Programming版 - C++ OO approach to use multi-dim array for HPC
the purpose of this class is for high performance computing, therefore
performance and ease of use is very important, especially for people
with a heavy fortran background.
for example, the declaration should be simple:
array a3d(3,3,3);
not array a3d(vector(3,3,3)); // also overhead of creating vector
class

, or an array (correct size is ensured by your main program). You could also
define another template class called pixel, or point, or vector:
P*****f
发帖数: 2272
49
在sorted array中找一个数,binary search。
有个题是sorted array right/left shift 了k位(k unkown),问怎么查找。
这也是个老题了,我所知的solution是用modified binary search, 根据 left end,
right end 和middle point 的大小关系来判断下一次搜索的范围。不过今天突然想到
一个例子;
original array = { 1,2,3,3,3,3,3,3,3,3,3,3,,3,....3}. shift k位后成了
{3,3,3,3...3,1,2,3,3,3,3,3,3,3}.这个似乎二分查找无法搞定,只能线性搜索了吧。
讨论一下
b***y
发帖数: 2799
50
来自主题: Programming版 - [合集] address of array
☆─────────────────────────────────────☆
ruisher (aa) 于 (Fri Sep 2 21:58:32 2005) 提到:
Suppose I have a class which has an array as a private member, if I want to
get the address of the array,
class A{
public: ...
.....
//if I want to get the address of the array
float & get_xyz { return xyz[0];}
or
float * get_xyz { return xyz;}
what's the difference between this two?For the first one, why can't I use
const sth like "float & get_xyz const{ return xyz[0];}
.......
private:
float xyz[
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)