由买买提看人间百态

topics

全部话题 - 话题: startpos
(共0页)
e****e
发帖数: 418
1
我的解法,总觉得用Java写还有更好的。
public class LongestConsecutiveSubsequence {

private int longestLCSStartPos = 0;
private int longestLCSCount = 0;
public Vector lcs(Vector input) {
if( input == null || input.size() < 2 )
throw new RuntimeException( "Invalid input." );

lcs( input, 0 );
if ( longestLCSCount < 2 )
throw new RuntimeException( "lcs length is less than 2." );

Vector r = new Vector阅读全帖
f*******n
发帖数: 8
2
来自主题: JobHunting版 - 问一算法题
我贴一下O(n)算法的实现吧,大家自己琢磨
#include "stdio.h"
//轮换
void Cycle(int Data[],int Lenth,int Start)
{
      int Cur_index,Temp1,Temp2;
      Cur_index=(Start*2)%(Lenth+1);
      Temp1=Data[Cur_index-1];
      Data[Cur_index-1]=Data[Start-1];
   
     while(Cur_index!=Start)
     {
   &... 阅读全帖
s*********s
发帖数: 318
3
来自主题: JobHunting版 - 问个面试题
http://tiny/1fpew40ab/stacques5347howt
好像也没有明确答案。
我save了一份答案,号称O(N),不知道对不对?
#include "stdio.h"
//轮换
void Cycle(int Data[], int Length, int Start) {
int Cur_index, Temp1, Temp2;
Cur_index = (Start * 2) % (Length + 1);
Temp1 = Data[Cur_index - 1];
Data[Cur_index - 1] = Data[Start - 1];
while (Cur_index != Start) {
Temp2 = Data[(Cur_index * 2) % (Length + 1) - 1];
Data[(Cur_index * 2) % (Length + 1) - 1] = Temp1;
Temp1 = Temp2;
Cur_index = (Cur_in... 阅读全帖
v***a
发帖数: 365
4
来自主题: JobHunting版 - 收到据信了,随便写点
第一次出现理论题,好题目,
可以用XXX扫描法,名字忘记了,思想就是每次扫矩阵的一条斜线
核心程序如下:
int64 t(0LL);
for (int64 k = 0LL;;k++) {
for (int64 startpos = 0LL; startpos < k; startpos++) {
int64 speed = k - startpos;
for (int b = 0; b < 4; b++) {
int64 p = bias[b][0] * speed * t + bias[b][1] * startpos;
if (ask(p, t++) == false) continue;
...
试了所有 startPos -1000 to 1000, speed -1000 to 1000,
都可以在 1,000,000 步之内出解
试了下 start == speed == 12345
猜了 1,219,290,964 步
步数增长还是很快的,当然肯定不是指数了
s******e
发帖数: 108
5
a more concise version
public static int jump (int [] A) {
int jumpcount =0;
int startPos =0;
int max = 0;
int newmax = 0;
while(max jumpcount++;
for(int i=startPos; i<=max;i++){
newmax = Math.max(newmax, A[i]+i);
}
startPos = max+1;
... 阅读全帖
s******e
发帖数: 108
6
a more concise version
public static int jump (int [] A) {
int jumpcount =0;
int startPos =0;
int max = 0;
int newmax = 0;
while(max jumpcount++;
for(int i=startPos; i<=max;i++){
newmax = Math.max(newmax, A[i]+i);
}
startPos = max+1;
... 阅读全帖
c*******9
发帖数: 9032
7
来自主题: Programming版 - 围棋规则haskell表示
http://homepages.cwi.nl/~tromp/go/Go.hs
{-# LANGUAGE ScopedTypeVariables #-}
module Go where
import Data.Ix
import Data.List
import Data.Array
import Control.Monad
import Control.Monad.State
data Player = Black | White deriving (Eq, Enum, Show)
data Color = Empty | Stone Player deriving (Eq, Show)
newtype Position p = Position (Array p Color) deriving (Eq)
color :: (Point p) => Position p -> p -> Color
color (Position pos) p = pos!p
class (Show p, Ix p) => Point p where
pointBounds :: (p,p)
... 阅读全帖
b*******d
发帖数: 750
8
来自主题: JobHunting版 - Find consecutive repeated string

duplicate
可以用修改后的suffix tree么?build suffix是linear time,虽然那个算法非常复杂
,很难一下写出来。但是其上每个node的path(从根开始的path)都是一个substring
。把每个node设计成
node {
char c;
List startPos;// 记录下这个node的从根到该node的path的起始点在原
string的位置。是个list因为可能有很多个这种string。
int pathLen; // 记录下这个node的从根到该弄得的path的长度,即该substring的
length。
}
build suffix tree的时候,如果add node时候,发现该node已经存在,说明该
substring已经存在,如果存在一个startPos + pathLen == curStartPos,说明存在一
个连续repeated的substring。
应该是linear time
p***7
发帖数: 535
9
来自主题: Statistics版 - a sas problem find function
Thanks!
Does a startpos has an effect on returns?
please see the example below
xyz='She sells seashells? Yes, she does.';
startposvar=22;
whereisshe_22=find(xyz,'she',startposvar);
put whereisshe_22;
the answer is 27
which is as same as the one without startpos here
whereisshe=find('She sells seashells? Yes, she does.','she ');
put whereisshe;
they are both 27
t
h*******e
发帖数: 1377
10
来自主题: JobHunting版 - 发个Twitter的面试题
2哥的算法可以手动split 就是 i == strLen || isreturn(str[i]) isreturn(str[i-
1]) 不同时候 check 一下 substr(str, segStart, i - segStart ) 把 相应的字符串
拿出来检查
同一行如果先遇到了 // /* 记录下 startPos。 和startType // 期待第一个 /n /*
期待第一个 */ 字符串 内移动 在字符串内保留一个 movPos
每次 遇到 // 前 /n 后 和 / * */不移动 movPos 不移动,否则str[movPos++] =
当前的值 就是one pass的, by the way twitter 离我们公司不远:)那个地方在
twitter 搬过去之后有了很多 穿戴整齐的人,不像以前San Francisco tenderloin街
区到处都是homeless到处游荡了。
y*****e
发帖数: 712
11
来自主题: JobHunting版 - 请教L家新面经题,种花
题目从一亩看来的:
public boolean canPlaceFlowers(List flowerbed, int numberToPlace)
如果flowerbed当中为true,说明已经栽过花了,附近两个不能再栽花。numberToPlace
代表想再栽多少花到flowerbed里。让return是不是还能栽那么多谢花进去。.
这个应该是说如果flowerbed是true false false false false, 那么在Index = 3种一朵
这题是不是用greedy解就行啊?看到一个可以种花的spot就种, 然后decrement
numberToPlace, 如果到最后numberToPlace > 0, 那就不能种。。。
还是需要用DP啊?来一个dp(startPos, flowerLeft), 每一步选择种或者不种?
R********y
发帖数: 4018
12
啊呀你老难得上来啊, 我刚才还跑到gmail 也没看到你在。
星星还给我说前几天吃饭碰到你了。
前两天在梅西看到各式各样的cashmere,最便宜的V-neck style 才柳时元。
http://www1.macys.com/search/results.ognc?Action=resultsPerPage&pageid=2&startpos=25&Keyword=charterclub+cashmere&attrs=Department%3ADepartment%3ASweaters&cKey=2&sortOption=*&resultsPerPage=96&COMPARE_ITEMS_GO_BUTTON=COMPARE_ITEMS_GO_BUTTON
我手上还有extra 25% off 的friends and family card, 现在freeshipping if over
$100.
t*******e
发帖数: 2113
13
嗯嗯,我也再看梅西,这个礼拜酷胖code MACYSFF。
就是不晓得牌子如何,俺学习学习~~~
gmail现在不敢挂了,新公司,新环境,俺老老实实做人ing。
欣欣妹儿独自吃大餐,被我撞见鸟,哈哈。面前几大盘。。。。。。。。。。。。
都是素的。除了夫妻肺片。

Action=resultsPerPage&pageid=2&startpos=25&Keyword=charterclub+cashmere&at
trs=Department%3ADepartment%3ASweaters&cKey=2&sortOption=*&resultsPerPage=
96&COMPARE_ITEMS_GO_BUTTON=COMPARE_ITEMS_GO_BUTTON
over
p***7
发帖数: 535
14
来自主题: Statistics版 - a sas problem find function
if startpos have an effect, the below program should be 5
xyz='She sells seashells? Yes, she does.';
But the answer is 27, which does not make any sense.
(共0页)