由买买提看人间百态

topics

全部话题 - 话题: integers
1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
g****y
发帖数: 323
1
来自主题: Java版 - Alternative way to swap Integer
变态吧。
find from deja.com
void swap( Object[] objects ) {
Integer temp = objects[0];
objects[0] = objects[1];
objects[1] = temp;
}
void testIt() {
Integer a = new Integer(1);
Integer b = new Integer(2);
System.out.println( "a = " + a + ", b = " + b );
Object[] integers = new Object[] { a, b };
swap(integers);
a = (Integer)integers[0];
b = (Integer)integers[1];
System.out.println( "a = " + a + ", b = " + b ); }
M*******8
发帖数: 85
2
【 以下文字转载自 Programming 讨论区 】
发信人: Mueller08 (简单,真实), 信区: Programming
标 题: 怎么把 integer 转为 multi-byte integer format?
发信站: BBS 未名空间站 (Sun Feb 21 16:01:15 2010, 美东)
下面的例子是怎么把0xA0 转为 0x81 和 0x20 的? 看不懂, 能不能给讲讲, 谢谢
How to transfer an integer to multi-byte integer format?
For example, the integer value 0xA0 would be encoded with the two-byte
sequence 0x81 0x20. The integer value 0x60 would be encoded with the one-
byte sequence 0x60.
c*******r
发帖数: 309
3
来自主题: JobHunting版 - 关于Divide a integer
我看了下这题的code,看了半天没搞懂这里边的位移运算是在干嘛。 为啥不能直接
while loop里每次a-b然后count次数?
public int divide(int dividend, int divisor) {
// Start typing your Java solution below
// DO NOT write main() function

int a = Math.abs(dividend);
int b = Math.abs(divisor);

//b maybe Integer.MIN_VALUE
boolean neg = (dividend > 0 && divisor < 0) || (dividend < 0 &&
divisor > 0);
if (divisor == 0) {

return Integer.MAX_VALUE;
... 阅读全帖
M*******8
发帖数: 85
4
下面的例子是怎么把0xA0 转为 0x81 和 0x20 的? 看不懂, 能不能给讲讲, 谢谢
How to transfer an integer to multi-byte integer format?
For example, the integer value 0xA0 would be encoded with the two-byte
sequence 0x81 0x20. The integer value 0x60 would be encoded with the one-
byte sequence 0x60.
M*******8
发帖数: 85
5
多谢指点!
这个
do x = (x << 7)|(b[i] & 0x7f) until (b[i] & 0x80) == 0
是从multi-byte integer format转为regular integer 吧?
如何从integer转为 multi-byte integer format? 谢谢
z********i
发帖数: 568
6
来自主题: JobHunting版 - find the first missing positive integer.
/* find the first missing postivie integer in array A with n elements
return x if one postive integer in [1..n] is missing;
return 0 otherwise;
*/
int findFirstMissingPositiveInteger(int A[], int n){
int x,i,val,index;
/* rearrange the input array A such that
B[i]=i+1 if i+1 exist in array A, or
B[i]=A[i] if i+1 does not exist in array A
where B is the array rearraged from A.
*/
for(i=0;i /* put A[i] in A[A[i]-1] if 1<=A[i]<=n && A[i]!=i+1 */
val=A[i... 阅读全帖
z********i
发帖数: 568
7
来自主题: JobHunting版 - find the first missing positive integer.
/* find the first missing postivie integer in array A with n elements
return x if one postive integer in [1..n] is missing;
return 0 otherwise;
*/
int findFirstMissingPositiveInteger(int A[], int n){
int x,i,val,index;
/* rearrange the input array A such that
B[i]=i+1 if i+1 exist in array A, or
B[i]=A[i] if i+1 does not exist in array A
where B is the array rearraged from A.
*/
for(i=0;i /* put A[i] in A[A[i]-1] if 1<=A[i]<=n && A[i]!=i+1 */
val=A[i... 阅读全帖
l******9
发帖数: 579
8
【 以下文字转载自 JobHunting 讨论区 】
发信人: light009 (light009), 信区: JobHunting
标 题: generate unique integer ID from columns in SQL table
发信站: BBS 未名空间站 (Fri Nov 14 17:36:46 2014, 美东)
I need to generate a new column in a table in a sql database.
the given table is:
id1 value1 value2 value3 value4
9465 387 801 1990 20
All columns are integer. All columns are integer. value1 and value2 are
always 3 digits, value3 are year value, value4 is not more than 3 digits.
I need to g... 阅读全帖
l******9
发帖数: 579
9
【 以下文字转载自 JobHunting 讨论区 】
发信人: light009 (light009), 信区: JobHunting
标 题: generate unique integer ID from columns in SQL table
发信站: BBS 未名空间站 (Fri Nov 14 17:36:46 2014, 美东)
I need to generate a new column in a table in a sql database.
the given table is:
id1 value1 value2 value3 value4
9465 387 801 1990 20
All columns are integer. All columns are integer. value1 and value2 are
always 3 digits, value3 are year value, value4 is not more than 3 digits.
I need to g... 阅读全帖
j******n
发帖数: 2206
10
来看看别人的讨论,very interesting,大家有兴趣的话,可以继续讨论一下。多谢了。
You could multiply by 99999 and add 1 as suggested in the Language
Reference.
You do realize that your variable will contain a particular integer
whenever ranuni returns a value in the range
[integer/100000,integer/100000). For example it will contain 52 for
any value from .00052 to .0005299999999999. However, it will contain
100000 only when ranuni returns 1.0 exactly. Your integer
distribution will not be uniform.
You would probably be better
Y******l
发帖数: 19
11
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.
w****x
发帖数: 2483
12
跪求roman number to integer 和 integer to roman number的程序, 特别是第一个
,哪个大牛帖一个??
l******9
发帖数: 579
13
I need to generate a new column in a table in a sql database.
the given table is:
id1 value1 value2 value3 value4
9465 387 801 1990 20
All columns are integer. All columns are integer. value1 and value2 are
always 3 digits, value3 are year value, value4 is not more than 3 digits.
I need to generate a value by combining value1 to value4, suppose that it is
called "value_combine". The "value_combine" should be unique. For example,
given the different combinations... 阅读全帖
f**********n
发帖数: 258
14
The problem is "Minimum number of moves to make an integer array balance".
Move is defined as reducing one element in array and increase anther integer
.
Balance is defined as the maximum difference between two integers in whole
array is 1.
lo=floor(average of array x)
up=ceil(average of array x)
lo_sum =the sum of all (lo - x[i]) for each x[i] up_sum=the sum of all (x[i]-up) for each x[i]>up
My solution is max(lo_sum, up_sum)
Here are several examples with my solution going through.
[1 2 3]... 阅读全帖
b******y
发帖数: 9224
15
java's int and integer is using auto-boxing/auto-unboxing. Syntactic sugar I
think.
Internally, it is just int or Integer object.
So, int[] != Integer[]
Otherwise, it is too much of a waste in terms of memory usage, should you
use simple int[] array.
b****t
发帖数: 114
16
来自主题: Mathematics版 - find closest integer points in R^n space?
Hi all,
Given an arbitary point in R^n space, is there a fast way to find k (k<=2^n)
closest integer points in the space?
I know for k=1, using simply floor function to get the closest integer point.
z(i) = floor(x(i)+.5).
Can anyone give me similarly method to get k closest integer points?
Thanks a lot,
Beet
t*****n
发帖数: 225
17
来自主题: Mathematics版 - Is there such a "measure" on integers?
Define a finitely additive measure F on all the subsets
of the set Z of integers as follows:
For any subset S of integers, any positive integer n,
define f_S(n)=1/n if n is in S, and f_S(n)=0 if n is not in S.
Then f_S1+f_S2= f_S if S is the union of 2 disjoint subsets S1 and S2.
Define F(S)=lim (f_S(1)+...+f_S(n))/log n,
then
1. F(S)=0 for any finite subset S.
2. F(S) is non-negative.
3. F(S) is finitely additive.
4. F(Z)=1.
楼主发包子吧

of the set of
l*******o
发帖数: 791
18
来自主题: JobHunting版 - 请问如何安全地reverse 一个integer
看到过一个题目,给一个integer,要求把它reverse过来,有可能这个integer反过来
时会over flow。
如果检测是否会over flow呢?
s******d
发帖数: 61
19
You have 100 files, each containing 10G sorted integers. How to merge all
integers into one sorted file?
这题以前见过,现在又没思路了...求解
b******g
发帖数: 1721
20
for the second, transform the presentation from a bit vector to an integer, and then run the first algorithm.
For the xor operation, does that require the N should be equal to 2^m or just any integer number?
d****o
发帖数: 1055
21
来自主题: JobHunting版 - find the first missing positive integer.
这道题谁能解出来?(注意,这道题题意请理解清楚)
Given an unsorted integer array, find the first missing positive integer.
For example,
Given [1,2,0] return 3,
and [3,4,-1,1] return 2.
and [-3,-4,1,2,6,7] return 3
Your algorithm should run in O(n) time and uses constant space.
j*******h
发帖数: 20
22
来自主题: JobHunting版 - find the first missing positive integer.
public class FirstMissingPositive {
int min;//Integer.MAX_VALUE;
int max;//Integer.MIN_VALUE;

private void checkMinMax(){
if( max > 0 && min > 0 ){
if( max < min ){
int temp = min;
min = max;
max = temp;
}
if( max - min > 1 )
max = -1;
}
}

public int firstMissingPositive(int[] A) {
// Start typing your Java... 阅读全帖
d****o
发帖数: 1055
23
来自主题: JobHunting版 - find the first missing positive integer.
这道题谁能解出来?(注意,这道题题意请理解清楚)
Given an unsorted integer array, find the first missing positive integer.
For example,
Given [1,2,0] return 3,
and [3,4,-1,1] return 2.
and [-3,-4,1,2,6,7] return 3
Your algorithm should run in O(n) time and uses constant space.
j*******h
发帖数: 20
24
来自主题: JobHunting版 - find the first missing positive integer.
public class FirstMissingPositive {
int min;//Integer.MAX_VALUE;
int max;//Integer.MIN_VALUE;

private void checkMinMax(){
if( max > 0 && min > 0 ){
if( max < min ){
int temp = min;
min = max;
max = temp;
}
if( max - min > 1 )
max = -1;
}
}

public int firstMissingPositive(int[] A) {
// Start typing your Java... 阅读全帖
e******o
发帖数: 757
25
given an i/p file with 4 billion integers produce a integer that doesnt
exist in the file given u have only 10 mb memory
thanks
s*******y
发帖数: 12
26
来自主题: JobHunting版 - leetcode: integer to roman 结果不同
LZ的代码有点奇怪, 既然是从integer map到罗马数字, 怎么定义了一个从罗马数字到
integer的map
感觉定义个, 十, 百, 千的一个数组就够了, 然后解释给定数值的个位, 十位, 百位,
千位, 直接map, 然后链接字符串就好了.
k*********6
发帖数: 738
27
来自主题: JobHunting版 - integer to roman的考点在哪里呢?
我觉得怎么就是look up一个roman numerals mapping的大表然后组成integer就行了呢
? 这有什么可考的呢?还是我miss掉point了。
roman to integer还有个多看一位看是不是有IV的状况出现。。。然后就是mapping了
凑起来?除此以外好像也没什么考点呢。。。
C*******a
发帖数: 448
28
来自主题: JobHunting版 - 怎么改List>的值?
List> A = new ArrayList>();
假设A已经赋值了,现在想改第m行第n列元素的值,怎么做?
V****r
发帖数: 925
29
非1线公司,按package水平来算应该算4线公司,公司规模业绩也还不如我现在工作的
地方。
电面一上来就被问了 Integer to English, 限时30分钟在Google Doc写完。
这是不是存心黑啊?
https://leetcode.com/problems/integer-to-english-words/
X*****r
发帖数: 2521
30
【 以下文字转载自 EE 讨论区 】
发信人: Xfilter (支持南开的兄弟们), 信区: EE
标 题: 紧急求助!Stochastic Integer Programming
发信站: BBS 未名空间站 (Thu Feb 21 01:09:43 2008), 站内
发信人: Xfilter (支持南开的兄弟们), 信区: Mathematics
标 题: 紧急求助!Stochastic Integer Programming
发信站: BBS 未名空间站 (Thu Feb 21 01:09:33 2008), 转信
有什么算法可以达到global optimum?
或者接近global optimum?
哪怕算法很复杂,centralized,都可以
只要能达到globaloptimum就行,
向各位求助了,有这样的算法吗?
谢谢!
w*s
发帖数: 7227
31
【 以下文字转载自 Stock 讨论区 】
发信人: wds (网虫都是loser), 信区: Stock
标 题: 做机问题请教:stock ticker name 转换成 integer ID
发信站: BBS 未名空间站 (Sat Jul 27 17:07:17 2013, 美东)
据说用数字做索引,在数据库里比较快。
请问怎么把stock ticker name 转换成 integer ID。
注意有些股票会delist, 会改ticker,又会有新上市的。
怎样一次性地改成ID ?
谢谢!
m****n
发帖数: 886
32
来自主题: Java版 - Integer in heap
I'm running an application on Weblogic. I did a profile of the heap, and
find out 43% of all objects in heap are Integers and they can't be cleaned up
by GC. Why these integers stay in heap? Does that indicate a memory leak?
b******y
发帖数: 9224
33
basically, the int[] array stores the int values, the Integer[] array only
stores the pointers to the Integer objects.
z***e
发帖数: 14
34
I saw a similar post in this board, and recalled my recent interview
experience. Got this question in Amazon interview. Although I failed, it is
still a good one.
My answer:
1. Create a hash table to store all integers in this array. O(n)
2. For each int, look for sum - int in the created hash tree. Since hash
tree is the fastest look-up table, we can take advantage from it. n*O(1)
3. So this is O(n) algorithm.
Then the guy gave me the array 1, 2, 10, 20, sum is 2. My answer will return
true obv
D****A
发帖数: 360
35
interesting. 估计是每个byte取一位做连接符, 是1就看下一个byte否则结束
每个byte只有7位有效位,两个byte应该能表示一个integer的低14位
0xA0=10100000
0x81=10000001
0x20=00100000
因为一个byte只能encode7位,所以0xA0的最高位1应该在0x81里的有效最低位,
另外0xA0的低7位应该在0x20里,0xA0和0x20的低七位相通,说明这种encoding
把每个byte的最高位用做连接符了
综上转换公式应该是 do x = (x << 7)|(b[i] & 0x7f) until (b[i] & 0x80) == 0
a****l
发帖数: 8211
36
unsigned int_8 a; //8bit unsigned integer
signed int_16 b; //16bit signed integer
a=0xFF;
b=a;
What's the value of b? The question is, which happens first, unsigned->
signed or 8bit->16bit?
w*s
发帖数: 7227
37
【 以下文字转载自 Stock 讨论区 】
发信人: wds (网虫都是loser), 信区: Stock
标 题: 做机问题请教:stock ticker name 转换成 integer ID
发信站: BBS 未名空间站 (Sat Jul 27 17:07:17 2013, 美东)
据说用数字做索引,在数据库里比较快。
请问怎么把stock ticker name 转换成 integer ID。
注意有些股票会delist, 会改ticker,又会有新上市的。
怎样一次性地改成ID ?
谢谢!
g*****g
发帖数: 34805
38
来自主题: Programming版 - INTEGER搜索求建议
通常都是先上简单的,性能不够再优化吧。比如java的integer hash就是返回integer
本身。
稠密不应该是问题。

S
o******1
发帖数: 1046
39
java有没有用户自定义长度integer类型?
比如我想定义一个65536 bit的integer,可不可行?
s*******1
发帖数: 40
40
【 以下文字转载自 CS 讨论区 】
发信人: sailor321 (sailor), 信区: CS
标 题: a quick question about integer programming
发信站: BBS 未名空间站 (Thu Jan 25 00:05:52 2007)
Hi,
If I want to solve a integer programming with several thousand of
constraints,
which software will be good for solving this problem?
Thanks!
y*****a
发帖数: 580
41
来自主题: Mathematics版 - Help on random integer generator
Thank you first for any info.
I am looking for a (pseudo-) random integer generator say RANDI (N,seed)
that provides an array of N integers (from 1 to N) one and only once. It
would be great if anyone could have a code to share in Matlab, VBA or c++?
Thanks.
You have a nice day.
b*******n
发帖数: 5065
42

no solution x^n+y^n=1
for 0 and x,y are of form 1/k,
k integer ?
or equivlently
x^n+y^n=( xy)^n
x,y integers
x^n(y^n-1)=y^n
(y^n-1)/y^n=1/x^n
left->1,right->0 diverge?
j******n
发帖数: 2206
43
I use this formula
random_number=int(ranuni(0)*100000);
but it will give me 0, I don't want 0. if I add 1 to this formula,the
integer range will be 1 to 100001, which is alo not what I want.
I want exactly random integer numbers ranging from 1 to 100000.
Does anybody have an idea?
p********a
发帖数: 5352
44
☆─────────────────────────────────────☆
jingjuan (hi) 于 (Sun Sep 12 16:53:32 2010, 美东) 提到:
I use this formula
random_number=int(ranuni(0)*100000);
but it will give me 0, I don't want 0. if I add 1 to this formula,the
integer range will be 1 to 100001, which is alo not what I want.
I want exactly random integer numbers ranging from 1 to 100000.
Does anybody have an idea?
☆─────────────────────────────────────☆
DaShagen (Unbearable lightness) 于 (Sun Sep 12 17:14:27 2010, 美东) 提到:
0<=ranu
M*******8
发帖数: 85
45
来自主题: JobHunting版 - 问个 multibyte integers 的问题
why the integer value 0xA0 would be encoded with the two-byte sequence 0x81
0x20?
俺不懂事咋encode的, 能不能说说, 谢谢
b********e
发帖数: 693
46
来自主题: JobHunting版 - O(N) sort integer array
这个怎么做到? 如果是32位integer的话 如果是做redix sort的话,是不是就可以O(N)了
h**e
发帖数: 13
47
来自主题: JobHunting版 - O(N) sort integer array
输出的时候要遍历整个bitmap (128MB个integer), size大于n,能算作O(n)吗?
迷惑中。。。
z****n
发帖数: 28
48
来自主题: JobHunting版 - 一道面试题(integer to binary string)
不能用Java library 的 Integer.toBinaryString(int i) , 自己写算法。大家写写看.
public static String convertToBinary(int i) {
}
y*********e
发帖数: 518
49
来自主题: JobHunting版 - 一道面试题(integer to binary string)
上完整代码:
public String intToBits(int value) {
long i = value;
if (i < 0)
i = Integer.MAX_VALUE - (-i) + 1;
// i is unsigned then
char[] buff = new char[32];
for (int j = 31; j >= 0; j--) {
boolean bit = (i & 1 == 1);
buff[j] = '0' + (int)bit;
i = i >> 1;
}
return new String(buff);
}
x*****p
发帖数: 1707
50
来自主题: JobHunting版 - 一道面试题(integer to binary string)
You do not have to worry about the negative integers because its binary
representation is to use the complementary code.
The code is as follows.
public static String convertToBinary(int i) {
StringBuffer sb = new StringBuffer();
int n = i;
sb.append("" + (n%2));
n>>1;
while (n>0) {
sb.append("" + (n%2));
n>>1;
}
sb.reverse();
return sb.toString();
}
1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)