由买买提看人间百态

topics

全部话题 - 话题: pos
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
a********a
发帖数: 219
1
来自主题: JobHunting版 - 寻找子序列/子段落
给自己积点福。
int match[100][100];
string sub(string a, string b) {
int oo = 10000000001;
int mn = oo;
int pos = -1;
memset(match, oo, sizeof(match));
memset(match[0], 0, sizeof(match[0]));
for(int i = 1; i <= b.size(); i ++)
for(int k = 1; k <= a.size(); k ++) {
match[k][i] = match[k - ((b[i - 1] == a[k - 1]) ? 1 : 0)][i - 1]
+ 1;
pos = ((k == a.size() && match[k][i] < mn) ? i : pos);
mn = (pos == i) ? match[k][i] : mn;
}
return (mn == o
C****u
发帖数: 18
2
来自主题: JobHunting版 - 1 11 21 1211 sequence的代码
1 def count(s,i):
2 o = i
3 c = s[i]
4 while (i < len(s) and c == s[i]):
5 i += 1
6 return (c,i - o)
7
8 def foo(s):
9 res = ''
10 pos = 0
11 while(pos < len(s)):
12 (ch,cnt) = count(s, pos)
13 res += str(cnt)
14 res += ch
15 pos += cnt
16 return res
17
18 s = '1'
19 print s
20 for i in range(10):
21 s = foo(s)
22 print s
运行结果:
python seq.py
1
11
21
1211
111221
312211
13112221
1113213211
31131211131221
13211311123113112211
111312211331121
k*******a
发帖数: 772
3
来自主题: JobHunting版 - 请教3道 brain teasers
第一题(程序算得)
#马 #可能结果
2 3
3 13
4 75
5 541
6 4683
7 47293
8 545835
附我的R code:
total<-c()
for (n in 2:8)
{
x<-(n-2):0
x<-2^x
count<-c()
for (i in 0:(2^(n-1)-1))
{
y<-floor(i/x)%%2
pos<-c(0,(1:(n-1))[y==1],n)
dif<-pos[-1]-pos[-length(pos)]
dif<-prod(factorial(dif))
dif<-factorial(n)/dif
count<-c(count,dif)
}
new<-data.frame(n=n,count=sum(count))
total<-rbind(total,new)
}
c****p
发帖数: 6474
4
来自主题: JobHunting版 - 一道G老题
find_union(BST_node* root, int * array, int array_start, int array_end, int*
union)
{
if(root == NULL)
return;
if(array_start > array_end)
return;
val = root->key;
pos = array.find(val, array_start, array_end);
if(array[pos] == val)
union.push(val);
find_union(root->left, array, array_start, pos - 1, union);
find_union(root->right, array, pos + 1, array_end, union);

}
其中array.find()应当返回“>= val的最小元素”或者“<=val的最大元素”的下标
union用vecto... 阅读全帖
f*******t
发帖数: 7549
5
来自主题: JobHunting版 - large file的一道题
这个是很基本的数据结构,建议看一下wiki
我前几天实现了它,只有基本的insert和search,没有对查找child list进行优化,代
码贴出来供参考:
#include
#define MAX_LENGTH 64
using namespace std;
static char buff[MAX_LENGTH];
class Trie {
public:
Trie();
Trie(char value);
bool Insert(const char *str);
bool Search(const char *str) const;
void PrintAll(int pos) const;
private:
char _value;
Trie *_sibling;
Trie *_child;
};
Trie::Trie()
{
_value = 0;
_sibling = NULL;
_child = NULL;
}
Trie::Trie(char value)
... 阅读全帖
m******e
发帖数: 353
6
来自主题: JobHunting版 - 从水木上看到个数组题
say you have n negatives
neg = 0; //start slot for negative numbers
pos = n; //start slot for positive numbers
//start examining array[0-N]
i = 0
while(neg if array[i] < 0 swap array[neg] and array[i], neg++
else swap array[pos] and array[i], pos++
i++

Think again, that's not O(1) space.
Unless you calculate the correct positions and store them in O(n) space, you
cannot achieve O(n) in time.
m******e
发帖数: 353
7
来自主题: JobHunting版 - 从水木上看到个数组题
say you have n negatives
neg = 0; //start slot for negative numbers
pos = n; //start slot for positive numbers
//start examining array[0-N]
i = 0
while(neg if array[i] < 0 swap array[neg] and array[i], neg++
else swap array[pos] and array[i], pos++
i++

Think again, that's not O(1) space.
Unless you calculate the correct positions and store them in O(n) space, you
cannot achieve O(n) in time.
f*******t
发帖数: 7549
8
来自主题: JobHunting版 - 出道简单题让大家练练白板
大致应该是这样,一些边界条件需要考虑。
int pos = 0;
for(int i = 1; i < n; i++) {
if(A[i] == A[pos])
continue;
else
pos++;
A[pos] = A[i];
}
}
s*******e
发帖数: 35
9
来自主题: JobHunting版 - facebook一题
用HASHMAP 找出每个WORD 所在的位置 occurrence map,在做一个反向的由所在位置(
position)到WORD 的reverse occurrence map。 吧这些position 排序,然后递归搜索。
package smartnose;
import java.util.Arrays;
import java.util.*;
public class SubWordSeq {


public static void main(String [] args){
List L = new LinkedList();

L.add("fooo");L.add("barr");L.add("wing");L.add("ding");L.add("wing"
);

String S= "lingmindraboofooowingdingbarrwingmonkeypoundcake";

HashMap<... 阅读全帖
s*******e
发帖数: 35
10
来自主题: JobHunting版 - facebook一题
用HASHMAP 找出每个WORD 所在的位置 occurrence map,在做一个反向的由所在位置(
position)到WORD 的reverse occurrence map。 吧这些position 排序,然后递归搜索。
package smartnose;
import java.util.Arrays;
import java.util.*;
public class SubWordSeq {


public static void main(String [] args){
List L = new LinkedList();

L.add("fooo");L.add("barr");L.add("wing");L.add("ding");L.add("wing"
);

String S= "lingmindraboofooowingdingbarrwingmonkeypoundcake";

HashMap<... 阅读全帖
m********g
发帖数: 272
11
来自主题: JobHunting版 - 麻烦谁贴一个bug free的BST next node
public static Node successorInBST(Node root, int key)
{
Node pos = findInBST(root, key);

if(pos == null)
{
throw new IllegalArgumentException("Cannot find the key in the
BST");
}

if(pos.getRight() != null)
{
return findSmallest(pos.getRight());
}

Node successor = null;

while(root != null)
{
if(key < root.getKey())
{
su... 阅读全帖
i**********e
发帖数: 1145
12
没想明白为什么要用hash_map呢,可以省些空间吗?
用一个table来记录用过的index,然后跳过重复的元素代码如下:
vector > permuteUnique(vector &num) {
sort(num.begin(), num.end());
vector > ret;
int n = num.size();
bool *used = new bool[n];
int *index = new int[n];
memset(used, 0, n*sizeof(bool));
permuteUnique(num, used, index, 0, ret);
delete[] used;
delete[] index;
return ret;
}
void permuteUnique(vector &num, bool used[], int index[],
int pos, vecto... 阅读全帖
e****e
发帖数: 418
13
来自主题: JobHunting版 - 昨天的F家店面
public class LineReader {
private int pos = 0;
private List chars = null;

public Character[] readLine() {
if ( chars == null || chars.size() == 0 )
chars = Arrays.asList( read4096() );

List line = new ArrayList();

int i = pos;
while ( i < chars.size() && chars.get(i) != '\n' && chars.get(i) !=
'\0' )
line.add( chars.get(i++) );

if ( chars.get(i) == '\n' ) {
... 阅读全帖
k*****y
发帖数: 744
14
来自主题: JobHunting版 - 请教一道单链表问题
Maintain the increasing subsequence ending at current position. Should run
in O(n) time.
int largestRectangleArea( vector &height ){
stack< pair > st;
st.push( make_pair(-1, 0) );
int ans = 0;
for( int ith=0; ith int pos = ith;
while(1){
pair &top = st.top();
if(top.second > height[ith] ){
pos = top.first;
ans = max( ans, top.second*(ith - pos) );
... 阅读全帖
b******g
发帖数: 77
15
来自主题: JobHunting版 - A面经
C++ code:
class LongestBetweenTwo
{
static int solution(int arr[], int n)
{
int z = 0; // longest distance
unorder_map pos; // record position of first appearance
for (int i = 0; i < n; i++)
{
if (!pos.count(arr[i])) pos.insert(make_pair(arr[i], i));
else z = max(z, i - pos[arr[i]];
}
return z;
}
};
l*********8
发帖数: 4642
16
来自主题: JobHunting版 - 发个一直没有见过满意答案的题吧
Given: n by m matrix A,
k
定义
int low[n]; // low[i]是在第i行查找的下限
int high[n]; // high[i]是在第i行查找的上限
low数组初始为全0, high全部是m.
取一个pivot (比如第n/2行的第k/n个元素), 在每行的low[i]和high[i]元素范围中找
该pivot对应的upper boundary,存为pos[i].
num = sum( pos[i] - low[i] | for all i) 就是比pivot小的element的数目。
if (num == k-1) {
return pivot;
} else if (num > k-1) {
// 把high数组(查找上限)update为pos数组的值。
// 在新的low,high范围内递归查找k-th smallest element
} else { // num < k-1
// 把low数组(查找下限)update为pos数组的值。
// 在新的low,high范围内递归查找... 阅读全帖
l*********8
发帖数: 4642
17
来自主题: JobHunting版 - 发个一直没有见过满意答案的题吧
如果在每行使用binary search,那么每轮更新是nlog(m).
但如果采用顺序查找,因为矩阵A在每列也是有序的,所以查找的下标在一轮中是不用
回头的。
例如:
假如pos[4]值为13,因为A[5][13] >= A[4][13],所以pos[5]就从13开始递减搜索,
假如pos[5]值为8,因为A[6][8] >= A[5][8], 所以pos[6]就从8开始递减搜索。
....
查找下标最多移动m次,重复使用的下标值最多n次,所以是O(n+m).
当然,如果m相对n很大,可以用binary search, 这样nlog(m)的效率还是比 O(n+m)好
些。
c****9
发帖数: 164
18
刚刚写的,不知道算是DP还是recursive,基本上是brute force
bool checkpos(vector& cur, int pos)
{
for(int i=0;i {
for(int j=0;j {
if(cur[i][j] =='Q')
{
if(j==pos)
{
return false;
}
else if(i+j == pos + cur.size())
{
return false;
... 阅读全帖
i******s
发帖数: 301
19
来自主题: JobHunting版 - triplets 题怎么做比较高效?
这不就是抄interviewstreet上的么.
下面是我的python code,idea一样,处理重复有一点技巧,你可以自己想想。Time
complexity 应该是O(n^2),主要花在build smaller, greater array上,不过应该能
做到O(nlogn) on average case。我没仔细想过。
import sys
import bisect
arr_size = int(sys.stdin.readline())
arr = map(int, sys.stdin.readline().split())
smaller_than = [0 for i in range(arr_size)]
greater_than = [0 for i in range(arr_size)]
index_map = {}
for i in range(arr_size):
if arr[i] in index_map:
index_map[arr[i]].append(i)
else:
index_map[arr[... 阅读全帖
g***9
发帖数: 159
20
来自主题: JobHunting版 - 问一道题(7)
遵照大牛的思路写了个实现:
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int getMaxEvenSeq(vector &v) {
int n = v.size();
if (n < 2) {
return 0;
}
vector pos(2*n+1, -1);
int zeros, ones;
int i, t, diff, index, dis, ans;
zeros = ones = 0;
ans = 0;
for (i = 0; i < n; i++) {
t = v[i];
if (t == 0) {
... 阅读全帖
w********8
发帖数: 55
21
来自主题: JobHunting版 - 请教一道Groupon的题目
借鉴楼上各位大牛的做法,我也写了一份Java的代码。。。。
public void mySolution(int num) {
if (num >= 5) {
String str = String.valueOf(num);
helper(num, "", 0, str.length(), false);
}
}
private void helper(int max, String prefix, int pos, int len, boolean
have5) {
if (pos == len) {
int cur = Integer.parseInt(prefix);
if (cur <= max) {
System.out.print(cur + ", ");
}
return;
}
for (int... 阅读全帖
w********8
发帖数: 55
22
来自主题: JobHunting版 - 请教一道Groupon的题目
借鉴楼上各位大牛的做法,我也写了一份Java的代码。。。。
public void mySolution(int num) {
if (num >= 5) {
String str = String.valueOf(num);
helper(num, "", 0, str.length(), false);
}
}
private void helper(int max, String prefix, int pos, int len, boolean
have5) {
if (pos == len) {
int cur = Integer.parseInt(prefix);
if (cur <= max) {
System.out.print(cur + ", ");
}
return;
}
for (int... 阅读全帖
m*****n
发帖数: 204
23

The following is an O(nlgn) solution for string of size n.
It maintains a heap for eligible chars, preferring longer streams.
Ineligible chars are maintained in a candidate queue, and added back
to the working queue when their position constraint is removed.
public class MinDistance {
public String rearrange(String source, int distance) {
// TODO Check params.

// WorkingQueue of eligible streams. Longest stream at head,
// but BackupStream at tail.
PriorityQueue阅读全帖
h******e
发帖数: 52
24
来自主题: JobHunting版 - 请问一道关于binary tree的题
这个题需要用一个trick去记住当前相对与root的位置。
int max = int.MinValue, maxPos = 0;
Inorder(Node node, int pos)
{
if(node == null)
return;
Inorder(node.left, pos*2);
if(max < node.val)
{
max = node.val;
maxPos = pos;
}
Inorder(node.left, pos*2+1);
}
Now we get max and the maxPos associated with it.
Then divide the maxPos by 2 all the way to 0, for example,
maxPos = 25, we get
1<-3<-6<-12
r->r->l-l
save the array 1,3, 6, 12 and start from 1 and b... 阅读全帖
z****l
发帖数: 5282
25
☆─────────────────────────────────────☆
oakyouth (oaks) 于 (Sat Jan 28 00:51:55 2012, 美东) 提到:
那种prepaid visa卡,假如卡里剩下6刀。我并不知道余额是6刀。
超市结账的时候,金额比较大,假如是30刀。可以用几张卡付款。
我用剩下6刀的那张卡付的时候,可以不告诉收银员余额,直接让他刷卡。然后机器能
自动把剩下6刀都扣完吗?
我怕麻烦,不想每刷一次卡,自己算个余额。
☆─────────────────────────────────────☆
lycsky (flying) 于 (Sat Jan 28 00:55:08 2012, 美东) 提到:
会被decline
☆─────────────────────────────────────☆
yudeli (babe) 于 (Sat Jan 28 01:01:42 2012, 美东) 提到:
yes, most of grocery stores will automatically deduct the... 阅读全帖
h******o
发帖数: 979
26
浅谈信用卡的安全使用
2013-04-09 16:12:34
近日很多网友at我,让我评评招行信用卡。我原不是很想表态,因为大家都知道我大爱
中国银行,我说任何话,会被认为带有偏向性。
但是,午饭后来到办公室,同事告诉我,她的同事,也是我的学妹,其招行信用卡,3
月中旬被盗刷了2000美元。我就跑去学妹办公室,向她了解完具体情况,又想说几句了
。(有几句,其实我在微博里说过不止一次。)
她持有的是招行携程联名卡银联威士(VISA)双标版,也就是俗称的双币卡,额度为人
民币15000元或等额美元。申请此卡是在2009年,是唯一的信用卡,但平时用得不多,
出国消费过。
2009年以来,在哪几个外国用过呢?亚洲是印度和印尼,欧洲是法国和西班牙。
注意:学妹对信用卡安全使用并不是特别了解。我问她平时是否把卡背面的三位码(如
是带美国运通American Express标志的卡,三位码则可能在卡正面)用贴纸掩盖时,她
说没有。因此,在海外,她可能也不曾注意遵守“刷卡必须当着持卡人之面进行”等原
则。
盗刷很刁钻,是在某周末的凌晨,在一家叫iherb.com的海外食品销售网站。第一笔刷
了2000... 阅读全帖
a*x
发帖数: 131
27
来自主题: Money版 - 搞不清加油站买gc算什么的
google一下MCC(Merchant category code)。信用卡公司是按一个transaction的mcc来
判断是不是gas transaction。加油站pump上的刷卡器(pos)都是设成mcc 5542(fuel
dispenser, automated)。至于加油站店里的pos设的是什么mcc,就ymmv了。有的加油
站内外pos全都设成5542,那就恭喜你了,不管买吃的还是gc全都按gas拿%5。有的加油
站分的细一些,店里的算grocery,所以有人买的gc拿不到gas的%5。这样的店要格外注
意,如果店里先交钱再加油有可能也不算gas,因为是刷的店里的pos
觉得有用的就给个包子吧:)
e***a
发帖数: 1982
28
pos写明了point of sales啊。。。。。。就是客户端刷卡,要刷磁条的
我记得他们的package写明了
1. pos where pin is entered
2. pos where pin is entered 但是你还取了cash back
3. pos where card was swiped as credit card
你的意思是他们虽然这么写了,但是其实并没有enforce这条要求?
这样的话,真的就很容易了!
h*****6
发帖数: 114
29
这正是我要说的,采用这种所谓升级版的POS机后,闪付似乎强制了,尤其针对有芯片
的美国信用卡。
一上来直接刷卡会被要求插卡,插卡后,它要你必须挥卡,像以前那样马上再刷卡(不
按取消键)无效。但是美国的信用卡挥卡也没有用。试验了N多次都不行。而且不止一
家店遇到此种情况。收银员还很自豪的说,他们店后半年刚刚更新的增强型POS机都这
样。。。
我感觉他这POS机也许还能接受没有芯片的卡,兴许直接刷卡就过了。。。有芯片的
Discover卡就彻底不行了。
就是2016年后半年开始,这种POS机似乎越来越多,以前的能用的店,现在不行了。
c*******u
发帖数: 12899
30
☆─────────────────────────────────────☆
tyxfxvv (tyxfx) 于 h 提到:
其实乙肝对成年人的威胁很低很低。高感染风险的是婴幼儿,好在现在有疫苗了,出生
时及时接种即可。乙肝妈妈现在都能生育,她们关心的问题已经是抗病毒服药期间能否
要宝宝了。下面四个part分别解释:
单独的乙肝病毒本身不会导致肝硬化乃至肝癌;
需要治疗的“小三”往往比“大三”难治,“大三”常常病情最轻;
成人共餐感染微乎其微;
乙肝不可以也可以治愈。
希望可以澄清一些误区。
Part 1,乙型肝炎病毒(HBV)介绍——HBV本身不会导致肝硬化乃至肝癌
毋庸置疑的血液传播,不是消化道传染病。即使是那些顽固坚持和感染者吃饭有危险要
分餐消毒的人,理由也是可能会通过口腔溃疡等进入血液而传染。
结构上,HBV分三层,一般只关心最外面两层。最外面的是表面抗原,其他不用看,单
看这一项,阳性即代表感染,阴性就是没有感染,阳性转阴性就代表最终治愈。中间的
是e抗原,感染者e抗原阳性基本等同于民间说的“大三”, e抗原阴性则是“小三”。
有抗原就有相应的抗体。乙肝五项检测... 阅读全帖
d******m
发帖数: 2333
31
来自主题: Parenting版 - 准备怀孕,请问哪种保险好?
只看in network的话,你的POS要先掏500最多1500, HSA先掏1250最多2500.其他的
after deductible, pos要付copy,要付10%,hsa全付。 考虑到pos最多也才1500,ms是
POS更合算一下。当然还要看你的premium。至于条件,就要看两个的network都包括什
么了。
你这个已经是summary了,mm多做点research就能看懂,以后还是得自己选。
h****s
发帖数: 16779
32
来自主题: Travel版 - 紧急求救:信用卡被盗的事
人家为什么帮你查呢?告诉我个原因先!
实际上正确的姿势是:
1、联系发卡银行客服人员,告知卡片被伪冒盗刷。此时,客服人员与你核对身份信息
无误后,会主动管制你的卡片,俗称“下code”。然后告知你:
1.1 到最近的ATM机做一笔查询交易;
1.2 报警;
1.3 复印最新的正本护照;
1.4 报警记录和护照复印件传真至发卡银行指定传真号码。
想必各位知道了发卡银行上述要求的作用——证明信用卡现在在客户手中,且客户在伪
冒交易时点不在伪冒交易发生地(针对题主在国外被盗刷的情况)。
有了以上证据,发卡银行一般可认定是客户卡片被测录后盗刷,不属于客户个人欺诈。
2、如确认属犯罪分子盗刷,发卡行会注销客户卡片,即下X CODE,并为客户换发新卡
。同时查看资金是否已经从发卡行清算出去。如无,会拦截。这一步时效性非常高。
3、发卡行作业部工作人员登场,调扣人员会通过卡组织,联系收单行,先争取冻结向
收单商户清算交易资金,并要求调取pos签单,核对签名。在此过程中,一般小额偶发
争议交易,冻结未必能成功。
4、同时,发卡行风控部门的反欺诈人员针对客户被盗刷情况和历史交易记录,再结合
一定期间内其... 阅读全帖
z***f
发帖数: 1182
a***h
发帖数: 29
34
来自主题: Database版 - backup and refresh a web site server
backup and refresh a web site server
there is a SQL Server server on a web site. i want to
backup, calculate data,
and refresh the web site server every evening. my plan is:
Setting up a POS (also SQL Server) offline, using ISDN (DDN
is too expensive) to dial up and connect to the web site
Server, and transmit the data from the web site server to
POS, calculate the data in POS, and tranmit the new data to
the web site server. and i want the POS to dial up
AUTOMATICALLY every evening.
is my plan
B*****g
发帖数: 34098
35
来自主题: Database版 - 这个新功能我喜欢
WITH
FUNCTION get_domain(url VARCHAR2) RETURN VARCHAR2 IS
pos BINARY_INTEGER;
len BINARY_INTEGER;
BEGIN
pos := INSTR(url, 'www.');
len := INSTR(SUBSTR(url, pos + 4), '.') - 1;
RETURN SUBSTR(url, pos + 4, len);
END;
SELECT DISTINCT get_domain(catalog_url)
FROM product_information;
/
h**o
发帖数: 548
36
我想comment out 某一行。
suppose the content of a.txt is:
111111111
222222222
33333AAA
444444444
我写到:
pos=`grep -n "AAA" a.txt |cut -d':' -f1`
sed "${pos} d" a.txt >b.txt
sed '
$pos i\
#33333AAA\
' b.txt>a.txt
前两个命令没问题, 最后一个命令得到错误信息:
sed: command garbled: $pos i\
请问错在哪? 其实我用:
sed '
3 i\
#33333AAA\
' b.txt>a.txt
就对了。 可能和variable 有关。
h**o
发帖数: 548
37
来自主题: Programming版 - 如何用’sed‘ comment out 某一行。
我想comment out 某一行。
suppose the content of a.txt is:
111111111
222222222
33333AAA
444444444
我写到:
pos=`grep -n "AAA" a.txt |cut -d':' -f1`
sed "${pos} d" a.txt >b.txt
sed '
$pos i\
#33333AAA\
' b.txt>a.txt
前两个命令没问题, 最后一个命令得到错误信息:
sed: command garbled: $pos i\
请问错在哪? 其实我用:
sed '
3 i\
#33333AAA\
' b.txt>a.txt
就对了。 可能和variable 有关。
s****n
发帖数: 1237
38
来自主题: Programming版 - 请教char *和char []的判断
在练习一道面试题
Implement an algorithm int removeDuplicate(char[] s)
For instance change ”abbcccdda” to “abcda” and return 4(the number of
characters deleted).
我自己写了一个
int removeDuplicateString(char str[]){
int count = 0;
int pos = 0;
char *c = str;
while(*c){
if(*c == *(c+1)){ count+=1;}
else{str[pos]=*c; pos++;}
c++;
}
str[pos]='\0';
return count;
}
但是调用的时候
char string[] = "ccc"; int n =
t*********o
发帖数: 143
39
来自主题: Programming版 - python比java慢这么多呀
谢谢大家讨论。楼上贴的benchmark results非常有用,跟我的数据很吻合,很好 :)
我的python核心代码如下。很简单,一行一行的读,把某一列的数据重新label一下,
然后写到一个新的文件。
我已经决定就用java了。从benchmark比较结果来看,java速度已经位列最快的一波了
,居然比c#还快。
pos = 10; // 11th column of the data
valueMap = {}
cnt = 0
for ln in sys.stdin:
vals = ln.split('\t')
val = vals[pos]
if val == null or len(val) == 0: continue
else:
if (not valueMap.has_key(val)):
... 阅读全帖
r*******n
发帖数: 3020
40
来自主题: Programming版 - python比java慢这么多呀
我按你的思路改了一下,看效果有没有改善, 然后再用pypy试试.
def process_file(input_file, output_file):
pos = 10
valueMap = dict()
cnt = 0
output = []
with open(input_file, 'r') as f:
lines = f.readlines()
for each_line in lines:
vals = each_line.split('\t')
val = vals[pos]
if val == '' or val == 'null':
continue
else:
if val not in valueMap:
valueMap[val] = len(valueMap) + 1
... 阅读全帖
t*********o
发帖数: 143
41
来自主题: Programming版 - python比java慢这么多呀
谢谢大家讨论。楼上贴的benchmark results非常有用,跟我的数据很吻合,很好 :)
我的python核心代码如下。很简单,一行一行的读,把某一列的数据重新label一下,
然后写到一个新的文件。
我已经决定就用java了。从benchmark比较结果来看,java速度已经位列最快的一波了
,居然比c#还快。
pos = 10; // 11th column of the data
valueMap = {}
cnt = 0
for ln in sys.stdin:
vals = ln.split('\t')
val = vals[pos]
if val == null or len(val) == 0: continue
else:
if (not valueMap.has_key(val)):
... 阅读全帖
r*******n
发帖数: 3020
42
来自主题: Programming版 - python比java慢这么多呀
我按你的思路改了一下,看效果有没有改善, 然后再用pypy试试.
def process_file(input_file, output_file):
pos = 10
valueMap = dict()
cnt = 0
output = []
with open(input_file, 'r') as f:
lines = f.readlines()
for each_line in lines:
vals = each_line.split('\t')
val = vals[pos]
if val == '' or val == 'null':
continue
else:
if val not in valueMap:
valueMap[val] = len(valueMap) + 1
... 阅读全帖
o**2
发帖数: 168
43
来自主题: Programming版 - FMP tutorial

何做呢?
FMP本身不提供强制中断的机制,这和FMP的model有关,model里的每个active object
都是平等的,你只能发message发request给一个active object,但不能干涉它如何处
理它的message。
所以干涉或中断的责任就由用户承担了。比如之前的FileAnalyzer要实现“中断查找”
就要能接受两种message。一是开始,二是终止。然后在查找的过程中要时不时的暂停
,看看有没有终止message进来。这个暂停的效果,目前也是由用户用message来实现的。
下面是改写后的FileAnalyzer。
public class FileAnalyzer {
private GuiMessenger messenger;
private boolean working;
public FileAnalyzer (GuiMessenger messenger) {
this.messenger = messenger;
}
public void countWord (File file... 阅读全帖
D******n
发帖数: 2836
44
来自主题: Statistics版 - 神奇的proc means
this way works, but stacking data is not that efficient. I came up with this
, just do more data manipulation on the means output.
----------------------------------------------->
data a1;
input x_1 y z weight;
datalines;
1 0 4 0.1
1 0 4 0.5
0 1 1 0.2
0 1 1 0.2
1 0 2 0.1
0 1 2 0.5
1 0 3 0.2
0 1 3 0.2
;
run;
proc means data=a1 noprint;
var x_1 y z;
weight weight;
output out=b sum= mean= nmiss=/autoname;
run;
proc transpose data=b(drop= _type_ _freq_) out=b2;run;
data b2;
... 阅读全帖
l****s
发帖数: 6
45
来自主题: Statistics版 - 请教有关用R做t-test
高手们都不愿意回答你这样的入门问题。
每一行的pos是不是唯一的?如果是,可以就下面loop代码。如果不是,就稍改一下t.
test那行。看你数据结构,不象是配对t-test,但如果是,也稍改一下t.test那一行。
假设你读入的数据对象名为myData。
#++++++++++++++++++++++++++++++++++++++++
output<-vector("list",length(myData$pos))
n=0
for(ii in unique(myData$pos))
{
n=n+1
indx<-which(myData$pos==ii)
output[n]<-t.test(myData[ind,2:5],myData[ind,6:9])
}

发帖数: 1
46
来自主题: DataSciences版 - 求助一道sql问题,谢谢 (转载)
SELECT bus.n1, bus.c1, stops.name, bus.n2, bus.c2 FROM
(
SELECT b1.num n1, b1.company c1, b1.stop stop, b2.num n2, b2.company c2
FROM
(
SELECT route.num num, route.company company, route.stop stop FROM
(SELECT num, company, MIN(pos) pos, stop FROM (SELECT id, name FROM
stops WHERE name = 'Craiglockhart') s1 INNER JOIN route ON s1.id = route.
stop GROUP BY num, company, stop) r1
INNER JOIN route
ON r1.num = route.num AND r1.company = route.company
WHERE route.stop <> r1.... 阅读全帖
i***s
发帖数: 39120
47
银行卡未离身,密码没泄露,从没去过澳门……
她的卡在澳被盗刷45万
银行:我们没过错没责任
2011年12月,市民董历丽银行卡里40余万元被盗刷。然而,令董历丽没有想到的是,当她找到发卡的银行讨要赔付时,对方却称自己没有责任而拒绝赔付。
丢钱:45万元被盗刷
2009年6月30日,重庆渝北区市民董历丽在一家银行办了一张卡,该卡仅办理存取款及理财业务,未开通网银及其他金融业务。
2011年12月26日晚,董历丽在重庆一餐厅刷卡消费时被告知余额不足,她以为POS机出了问题,并没有太在意。直到她当晚再次刷卡消费无果时,才意识到事情的严重性。她赶紧查询余额,发现卡中的455377.92元早已不翼而飞。
“我立即拨打客服电话并前往银行查询,被告知该笔存款于2011年12月26日17:02在澳门经他人通过购买珠宝首饰刷POS机划走。在此期间,我从没有离开重庆,该银行卡一直随身携带,密码从没有泄露给他人,也没有进行过大额的取款和交易。”董历丽说。
据董历丽介绍,她立即到渝北区公安机关报了案,但从报案到现在已经过了大半年,仍旧没有任何结果。
一位银行职员告诉记者,银行卡的防盗主要是通过两种方式来完成:... 阅读全帖
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)