由买买提看人间百态

topics

全部话题 - 话题: pos
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
M******a
发帖数: 6723
1
http://lx.huanqiu.com/lxnews/2018-12/13908891.html
2018-12-27 10:25检察日报
王晓晓
医科大学毕业生放弃到医院就业的机会,走上复制他人信用卡的犯罪道路。被抓获
后,他多次向办案人员哭诉——
“我是大学生,请放我出去”
庭审现场
复制他人信用卡
寒窗苦读十余载,赵航考入某重点医科大学,可是经过五年的医学学习,赵航愈发
嫌弃医务工作太累。2015年,他大学毕业,放弃到医院工作的机会,选择回家待业,想
找一份清闲的工作。
一时找不到合适工作,他就上网打发时间,很快沉迷于网络世界。一次偶然机会,
赵航认识了一个网名叫“我想稳定”的网友,对方称自己是做POS机盗刷信用卡业务的
。赵航立即被这一“黑科技”吸引,专门购买了一张手机卡并加了该网友为微信好友,
虚心向其请教。在该网友的指导下,他又加入一个专门教授信用卡诈骗犯罪的QQ群,在
群里系统学习了通过POS机复制信用卡的技术,企图通过“黑科技”狠赚一笔,实现人
生逆袭。
2017年6月,赵航的女朋友李冰(化名)向其透露,自己母亲经营的烟酒店想办理一
台POS机,赵航立即表示自己可以... 阅读全帖
g***s
发帖数: 3811
2
public class MyTest2 {
static final int a[] = new int[]{-9,6,10000, 6, 3, 7, 1,2,5};
public static void main(String arg[]){
System.out.println("the min missing number is : " +
findMissingNum(a));
}
static private int findMissingNum(int a[]){
for (int i = 0 ; i< a.length; i++){
while (needMove(i,a))
move(i,a);
}
int i;
for (i = 0 ; i< a.length; i++){
if (a[i] != i+1 ) return i+1;
}
re... 阅读全帖
x*****0
发帖数: 452
3
开始做leetcode,按二爷的总结,由易到难,一天两道。
今天是 remove duplicates from sorted array 1, 2
http://leetcode.com/onlinejudge#question_26
http://leetcode.com/onlinejudge#question_80
下面是我的代码:
int rightMost_of_curElem(int A[], int curElem, int ind, int n)
{
while(ind {
if(A[ind]!=curElem)
break;
++ind;
}

return --ind;
}
(1)
int remove_duplicates(int A[], int n)
{
int i=0;
int unique_num = 0;
while(i {
int cur_elem = A[i];
int pos =... 阅读全帖
T*******e
发帖数: 4928
4
算了,给你贴一个: http://www.itint5.com/oj/#26
int getNumber(const string &expr, int &pos){
int num=0;
while(expr[pos]&&expr[pos]<='9'&&expr[pos]>='0'){
num=num*10+expr[pos++]-'0';
}
return num;
}
//返回表达式expr的值
int evaluate(const string& expr) {
int res=0;
int size=expr.size();
if(size==0) return res;
vector v;
int pos=0;
v.push_back(getNumber(expr, pos));
while(pos char op=expr[pos++];
int num=getNumber(expr, pos);
... 阅读全帖
j*****8
发帖数: 3635
5
来自主题: JobHunting版 - 讨论下lc最新的那道hard题吧
题目如下:
Given a string that contains only digits 0-9 and a target value, return all
possibilities to add binary operators (not unary) +, -, or * between the
digits so they evaluate to the target value.
给的几个例子:
"123", 6 -> ["1+2+3", "1*2*3"]
"232", 8 -> ["2*3+2", "2+3*2"]
"105", 5 -> ["1*0+5","10-5"]
"00", 0 -> ["0+0", "0-0", "0*0"]
"3456237490", 9191 -> []
下面是我的java code,有个test case一直超时,求大牛指点优化。我的思路很简单,
先生成所有可能的计算式,然后对每个计算式求值与target比较。
public List addOperators(String num, int target) {
... 阅读全帖
s***e
发帖数: 793
6
来自主题: Programming版 - 来,做题吧。
发信人: shaye (wonderfull), 信区: JobHunting
标 题: Re: 来,做题吧。
发信站: BBS 未名空间站 (Sun Nov 11 04:32:21 2007)
原来写过一个,应该work
bool nextPermutation(char* a, int n){
int pos=n-1;
while(pos>0 && a[pos]<=a[pos-1]) pos--;
if(pos==0)return false;
int s=pos;
int e=n-1;
while(e>s){std::swap(a[s],a[e]),s++;e--;}
for(int i=pos;i if(a[i]>a[pos-1]){
std::swap(a[i],a[pos-1]);
break;
}
return true;
}
void printAllPermutation(char* a, int n){
std::sort(a,a+n);
std::cout< while(nextPermutation(a,n)) std
s*****y
发帖数: 897
7
大牛,我测试过几个input都对的阿,可否给个反例阿。
你的code这里
static private boolean needMove (int pos, int[] a){
return !(a[pos] == pos + 1 || a[pos] >= a.length || a[pos] <= 0
|| a[a[pos]-1] == a[pos] );
}
我的确没有看懂这个a[a[pos]-1] == a[pos]。 请指点。
谢谢。
b*****1
发帖数: 52
8
来自主题: JobHunting版 - 再问一个算法题。
rotate from the current searched element to the found position in the 2nd
half element. The total number of rotation will be no more than n. The
search is logn. So the total complexity is O(nlogn)
1,3,6,8,-5,-2,3,8
#1 search a[0]=1 between i=4 to 7: found 1 before i=6, rotate the array
before i=6:
-5 -2 1 3 6 8 3 8
#2 search a[3]=3 between i=6 to 7: found 3 before i=7, roate the array
between i=3 (current search position) and i=7 (found position)
-5 -2 1 3 3 6 8 8
#3 search a[5]=6 between i=7 to... 阅读全帖
K*****k
发帖数: 430
9
要求in place, 只要求O(m + n)的方法,不需要log(m + n)那个。我写的代码还是觉得太长,怎么简化才能在白板上写的下?
double GetMedian(int A[], int m, int B[], int n)
{
bool odd_length = ((m + n) % 2 == 0)? false : true;
int m1, m2;
int pos = (m + n + 1) / 2;
int count = 0;
int i = 0;
int j = 0;
while (i < m && j < n)
{
count++;

if (A[i] <= B[j])
{
if (count == pos)
{
m1 = A[i];
if (odd_length)
return m1;... 阅读全帖
f*******t
发帖数: 7549
10
来自主题: JobHunting版 - Exposed上一道string permutation的题
#include
#include
#include
#define BUFFSIZE 1024
using namespace std;
char buff[BUFFSIZE];
int idx;
void enumerate(const string& s, int pos)
{
if(pos == s.size()) {
if(idx == 0)
printf("{Empty}\n");
buff[idx] = 0;
printf("%s\n", buff);
}
else if(pos != 0 && s[pos] == s[pos-1]) {
enumerate(s, pos+1);
}
else {
buff[idx] = s[pos];
idx++;
enumerate(s, pos+1);
idx--;
enume... 阅读全帖
k*****y
发帖数: 744
11
来自主题: JobHunting版 - facebook一题
Python写了一个,练练手
L = ['fooo', 'barr', 'wing', 'ding', 'wing']
S = 'lingmindraboofooowingdingbarrwingmonkeypoundcake'
# L1 stores distinct stings in L
# multiples counts the corresponding multiples
L1 = []
multiples = []
for str in L:
if str not in L1:
L1.append(str)
multiples.append(L.count(str))
# k is the lenght of each substring
k = len(L[0])
match = [0]*len(S)
checklist = []
for i in range(0, len(L1)):
mul = multiples[i]
list_pos = []
# find all possible positio... 阅读全帖
k*****y
发帖数: 744
12
来自主题: JobHunting版 - facebook一题
Python写了一个,练练手
L = ['fooo', 'barr', 'wing', 'ding', 'wing']
S = 'lingmindraboofooowingdingbarrwingmonkeypoundcake'
# L1 stores distinct stings in L
# multiples counts the corresponding multiples
L1 = []
multiples = []
for str in L:
if str not in L1:
L1.append(str)
multiples.append(L.count(str))
# k is the lenght of each substring
k = len(L[0])
match = [0]*len(S)
checklist = []
for i in range(0, len(L1)):
mul = multiples[i]
list_pos = []
# find all possible positio... 阅读全帖
s*******y
发帖数: 44
13
来自主题: JobHunting版 - leetcode 这题insert interval怎么做?
我一开始也是这个思路,顺序遍历,找到左右overlap的interval,然后删除、插入。
查找过程可以用binary search优化到logn。
vector insert(vector &intervals, Interval
newInterval) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int size = intervals.size();
if (size == 0) {
intervals.push_back(newInterval);
return intervals;
}

int i=0, pos;
while (i < size && intervals[i].end < newInterval.start) i++; //
lef... 阅读全帖
s*******y
发帖数: 44
14
来自主题: JobHunting版 - leetcode 这题insert interval怎么做?
我一开始也是这个思路,顺序遍历,找到左右overlap的interval,然后删除、插入。
查找过程可以用binary search优化到logn。
vector insert(vector &intervals, Interval
newInterval) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int size = intervals.size();
if (size == 0) {
intervals.push_back(newInterval);
return intervals;
}

int i=0, pos;
while (i < size && intervals[i].end < newInterval.start) i++; //
lef... 阅读全帖
M*****e
发帖数: 568
15
来自主题: JobHunting版 - 直方图下雨这道题怎么解?

写了一个扫一遍找出每个interval关键点,然后算水量的
int WaterInArray(vector data)
{
vector keys(data.size());
int open = -1;
for (int i=0; i {
while (open>0 && data[i]>data[keys[open]] && data[keys[open]] keys[open-1]])
open--;
keys[++open] = i;
}
int total = 0, pos = 0;
while (pos < open)
{
int min = (data[keys[pos]] data[keys[pos+1]];
for (int i=keys[pos]+1; i阅读全帖
b****e
发帖数: 45
16
来自主题: JobHunting版 - 两道google的题
将初始数列设为1..n,然后扫描signature, 碰到“I”就跳过,碰到连续的"D"就翻转
相应位置上的数字。代码如下:
vector FindSmallestPermutation(string signature) {
vector res(signature.size() + 1, 0);
for (int i = 0; i < res.size(); i++) {
res[i] = i + 1;
}
int pos = 0;
int start = 0;
while (pos < signature.size()) {
if (signature[pos] == 'D') {
start = pos;
while (pos < signature.size() && signature[pos] == 'D')
pos++;
reverse(res.begin() + st... 阅读全帖
d*k
发帖数: 207
17
来自主题: JobHunting版 - leetcode N-Queens II 我的c++要400多毫秒
请问这正常吗?是不是我的算法还不够好?
我用的方法是dfs,逐行枚举能够放下皇后的位置,对于每个位置,需要O(1)的时间判
断是否能够放下皇后。没有其他剪枝。更新buffer是把当前解存下来,是为了做N-
Queens时候用的。代码如下。
class Solution {
public:
void search(int row, int pos, int* buffer, bool* taken, bool* diag_left_
taken, bool* diag_right_taken, int* count, int row_num) {
if (row == row_num) {
*count += 1;
return;
}

if (pos == row_num) {
return;
}

int diag_left = pos - row + row_num;
int di... 阅读全帖
b*******3
发帖数: 109
18
来自主题: JobHunting版 - 一道string matching的题目
贴个java solution O(n m) :
public String minWindow (String originalString, String patternString)
{
List valuePairs = new ArrayList();
int shortestWindowLength = originalString.length();
int shortestHolderIndex = 0;

for (int i=0; i< originalString.length(); i++)
{
if (patternString.indexOf(originalString.charAt(i))>=0)
{
ValuePair valuePair = new ValuePair(originalSt... 阅读全帖
h****p
发帖数: 87
19
研究下KMP算法,看到wiki上的解释有一点不是很理解 请大牛帮忙解释解释
算table如下:
algorithm kmp_table:
input:
an array of characters, W (the word to be analyzed)
an array of integers, T (the table to be filled)
output:
nothing (but during operation, it populates the table)
define variables:
an integer, pos ← 2 (the current position we are computing in T)
an integer, cnd ← 0 (the zero-based index in W of the next
character of the current candidate substring)
(the first few v... 阅读全帖
r***e
发帖数: 29
20
来自主题: JobHunting版 - linkedin,rocketfuel, google面经若干
应该是从左向右找第一个逆序,如42,31,去除逆序数。 如果无逆序,去最后一个数。
string removal(string value)
{
if(value.length()<2)
{
return value;
}
string vt;
unsigned int pos = 0;
for(; pos {
if(value[pos]>value[pos+1])
{
break;
}
}
if(pos < value.length()-1)
{
vt = value.substr(0, pos)+value.substr(pos+1);
} else
{
vt = value.substr(0, pos);
}
return vt;
}
U***A
发帖数: 849
21
来自主题: JobHunting版 - 好挫的F家面经
这个怎么样?
int maxSubY(vector &s, int y){
int size = (int)s.size();
if(size == 0) return 0;
int result = 0;
vector sum(size+1, 0);
map pos;
for(int i=1; i<=size; i++){
sum[i] = sum[i-1]+s[i-1];
if(pos.find(sum[i]) == pos.end()){
pos.insert(make_pair(sum[i], i));
}
}

for(int i=0; i<=size; i++){
if(sum[i] == y){
result = result > i ... 阅读全帖
w****3
发帖数: 232
22
来自主题: JobHunting版 - 问一道Facebook近期电面题
先除去左(右)括号,再除去右(左)括号。
这应该算是一个stack吧。
string rmRight(string bal)
{
int low = 0;
string result;
int pos = 0;
int count = 0;
while(pos {
if(bal[pos]=='(')
{
result.push_back('(');
count++;
}
else
{
if(count>0)
{
count--;
result.push_back(')');
}
}
pos++;
}
return result;
}
string rmLeft(string bal)
{
int ... 阅读全帖
d*****0
发帖数: 1500
23
来自主题: TexasHoldem版 - 屌丝的扑克研磨日记 06-06-13
1 1K 11
2 750 3.3 $7.78
3 1.5K 11
4 1K 11
5 1.5K 3.3+3+3 $28.75
6 3K 11+10+10
1号,UTG+1,TJs 12bb open shove,take down。UTG A7o open shove 14bb into QQ,
knockout
2号,大盲位88 14bb 3bet shove rock 2.1x open + a flatter,take down。换桌,
第一把,UTG 16bb open shove with A9o,被两家AJo call到,suckout!紧接着第二
把,AKo,接了16bb 和8bb的两连推,hold!wow!card dead + busy with other
tables = auto ITM,呵呵。hero 大盲位,55 10bb stack call EP 5bb shove>A9s。
UTG+1 TJo 13bb shove,take down。换桌,UTG 33,15bb,看到大小盲均... 阅读全帖
m******e
发帖数: 353
24
来自主题: JobHunting版 - 从水木上看到个数组题
ok, my bad, keep track of range [0, neg) and [numNeg, pos), and do not
rearrange those (since they are already in the correct place)
use [neg, numNeg) and [pos, N) as circular buffer for un-processed elements
#include
#include
#include
using namespace std;
void print(const vector& input) {
for(size_t i = 0; i < input.size(); ++i) {
cout << input[i] << " ";
}
cout << endl;
}
int numNegatives(const vector& input) {
int cnt = 0;
... 阅读全帖
k*****y
发帖数: 744
25
来自主题: JobHunting版 - 请教一道题目
traverse一遍string,记当前位置是i;
用map pos记录word里面相应字母出现在i之前最后的位置;
如果word中每个字母都出现了,找出pos中位置最小的一个,就可以算出以i为结尾最短
的长度。
====================================
string getShortestSubstr(string &word, string &str) {
map pos;
int left, length=str.length()+1;
for( int i=0; i char ch = str[i];
if( word.find(ch) != string::npos ) {
pos[ch] = i;
if( pos.size() == word.size() ){
int leftPos = i;
... 阅读全帖
d****n
发帖数: 233
26
来自主题: JobHunting版 - F面经
bool isDigit(const string &expr, int pos)
{
return expr[pos] >='0' && expr[pos] <= '9';
}
void parseNum(const string &expr, int &pos)
{
if (expr[pos] == '0') {
pos++;
// if the first char is '0', it is a number
// following digits should be treated as separate number.
return;
}

while(isDigit(expr, pos))
pos++;

return;
}
bool validate(const string& expr) {
stack st;
int i = 0;
while(i < expr.length()) ... 阅读全帖
r*c
发帖数: 167
27
来自主题: JobHunting版 - 问一道题(6)
贴个pattern字符串有重复字符的解法, 是dek,cpp1等大牛的解法的扩展。
#include
#include
#include
#include
using namespace std;
#define INT_MAX 2147483647
#define INT_MIN -2147483648
class MinWindowSolution
{
public:
struct TreeNode
{
TreeNode *parent;
int val;
vector children;
TreeNode(int i, TreeNode *p) : val(i), parent(p){}
};
void FindMinWindow_Tree(const vector& input , const vector&
query , int& nStart,... 阅读全帖
i****y
发帖数: 84
28
来自主题: JobHunting版 - 八皇后位运算的问题
请问下面有一行:
pos = upper & (~(row | ld |rd));
这里为什么要upper&?upper不都是1吗?
class Solution {
public:
int cnt,upper;
int totalNQueens(int n) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
cnt = 0;
upper = (1< Queen(0,0,0);
return cnt;
}
void Queen(int row,int ld,int rd)
{
int pos,p;
if(row!=upper)
{
pos = upper & (~(row | ld |rd));
while(po... 阅读全帖
A*****o
发帖数: 284
29
来自主题: JobHunting版 - G面经 求bless
Bless LZ.
写了个onsite第二轮的python解法, 感觉这题不简单啊...
used = [0 for _ in xrange(10)]
def check(s):
global used
for k in xrange(10):
if used[k] > 1:
return False
return True
def min_unused():
for i in xrange(10):
if not used[i]:
return i
return -1
def add1(l):
global used
n = len(l)
k = c = t = pos = -1
for i in xrange(n-1, -1, -1):
c = l[i]
t = (c+1) % 10
if not used[t]:
pos = i
k =... 阅读全帖
s******r
发帖数: 21
30
来自主题: JobHunting版 - 请教一道Groupon的题目
用递归,基本思路是,
考虑第i位的数字,取得值可以是0-9;唯一要注意的是最后一位数字,如果5没有出现
过,只能取5.
public class Solution {
public void str5(String number, String prefix, int length, int pos,
boolean has5) {
if (pos >= length) {
System.out.println(prefix);
} else if (pos < length - 1 || has5) {
for (int i = 0; i <= 9; i++) {
String tmp = prefix + i;
if (Integer.parseInt(tmp) > Integer.parseInt(number.
substring(0, pos + 1))) {
... 阅读全帖
s******r
发帖数: 21
31
来自主题: JobHunting版 - 请教一道Groupon的题目
用递归,基本思路是,
考虑第i位的数字,取得值可以是0-9;唯一要注意的是最后一位数字,如果5没有出现
过,只能取5.
public class Solution {
public void str5(String number, String prefix, int length, int pos,
boolean has5) {
if (pos >= length) {
System.out.println(prefix);
} else if (pos < length - 1 || has5) {
for (int i = 0; i <= 9; i++) {
String tmp = prefix + i;
if (Integer.parseInt(tmp) > Integer.parseInt(number.
substring(0, pos + 1))) {
... 阅读全帖
x****7
发帖数: 86
32
来自主题: JobHunting版 - 请教一道G的电面题。。
C++:
#include
void replaceWildCard (std::string str, size_t pos)
{
if (pos >= str.size()) {
std::cout << str << std::endl;
return;
}
if (str[pos] == '*') {
str[pos] = '0';
replaceWildCard (str, pos + 1);
str[pos] = '1';
replaceWildCard (str, pos + 1);
}
else {
replaceWildCard(str, pos + 1);
}
}
int main (int argc, char ** argv)
{
replaceWildCard (std::string(argv[1]), 0);
return 0;
}
c*******y
发帖数: 98
33
来自主题: JobHunting版 - 非死不可电面出了新花样
面筋都是按行打印,今天让我按列打印。手忙脚乱了一阵。。用了个父节点做出来的。
电面只写了一道题是不是挂了。。
更新题目具体内容:
按列打印,
a
/ \
b c
/
d
/
e
/
f
结果:
f
b e
a d
c
我刚发现,我的方法错了,老印最后没提醒我。已挂无悬念。
现在想到的方法是直接DFS,把column和value放到map
value>里,然后直接用map里的信息打印就好了。空间大一点但简单易操作。
fuck me....
新写了个,大伙看看对不对。。
void dfs(Node* node, int pos, int& left, map>& index){
if (!node) return;
left = left > pos ? pos : left;
if (index.find(pos) == index.end()){
index[pos] = {node->val};
}
... 阅读全帖
f*******w
发帖数: 1243
34
来自主题: JobHunting版 - 问两道onsite题目
写了一下第二题,O(k),用hash来实现swap..
vector randomPick(vector > &input, int k) {
int n = input[0].size(), total = input.size() * n;
unordered_map visited;
vector res; int start = 0;
for (int i = 0; i < k; ++i) {
int pos = rand() % (total - start) + start;
int x = pos / n, y = pos % n;
if (visited.find(pos) != visited.end()) {
res.push_back(visited[pos]);
int tmp = visited[pos];
visited[pos] = (visi... 阅读全帖
l****c
发帖数: 782
35
来自主题: JobHunting版 - FB Onsite新题,有人能看看吗?
这个DFS对吗?
bool FindThiefDFS(const vector& S, int idx, int n, int pos,
unordered_map, bool, HashPair>& cache) {
if (idx >= S.size()) return false;
if (S[idx] == pos) return true;
if (cache.find({idx, pos}) != cache.end()) return false;
if (pos >= 1 && FindThiefDFS(S, idx + 1, n, pos - 1, cache))
return true;
if (pos <= n - 2 && FindThiefDFS(S, idx + 1, n, pos + 1, cache))
return true;
cache[{idx, pos}] = fal... 阅读全帖
w*****h
发帖数: 423
36
有人不愿意进去看的话,我贴这
private static List findMaxIsLand(int[][] m)
{
List poslist = new ArrayList();
if(m.length == 0 || m[0].length == 0)return poslist;

int x = m.length, y = m[0].length;
boolean[][] visited = new boolean[x][y];

for(int i = 0; i < x; i++)
{
for(int j = 0; j < y; j++)
{
if(m[i][j] == 0 || visited[i][j])continue;

Stack stk = new Stack阅读全帖
j**7
发帖数: 143
37
来自主题: JobHunting版 - 一道用叶子过河题
// time O(N). space O(X)
public int solution(int[] A, int X, int D) {
LinkedList deque = new LinkedList();
int[] pos = new int[X + 1];
pos[0] = 0;
pos[X] = 0;
for (int i = 1; i < X; i++) {
pos[i] = -1;
}
for (int i = 0; i < A.length; i++) {
if (pos[A[i]] == -1) {
pos[A[i]] = i;
}
}
int[] DP = new int[X + 1];
DP[0] = 0;
deque.add(0);
... 阅读全帖
j**7
发帖数: 143
38
来自主题: JobHunting版 - LiveRamp笔试题求解——frog jump
// time O(N). space O(X)
public int solution(int[] A, int X, int D) {
LinkedList deque = new LinkedList();
int[] pos = new int[X + 1];
pos[0] = 0;
pos[X] = 0;
for (int i = 1; i < X; i++) {
pos[i] = -1;
}
for (int i = 0; i < A.length; i++) {
if (pos[A[i]] == -1) {
pos[A[i]] = i;
}
}
int[] DP = new int[X + 1];
DP[0] = 0;
deque.add(0);
... 阅读全帖
g****g
发帖数: 1828
39
来自主题: WaterWorld版 - vector
SGI Logo
vector

Category: containers Component type: type
Description
A vector is a Sequence that supports random access to elements, constant
time insertion and removal of elements at the end, and linear time insertion
and removal of elements at the beginning or in the middle. The number of
elements in a vector may vary dynamically; memory management is automatic.
Vector is the simplest of the STL container classes, and in many cases the
most efficient.
Example
vector V;
... 阅读全帖
k****i
发帖数: 101
40
来自主题: Java版 - 今天碰到一个面试题

public static int solveDuplicateElement(Integer[] ar) {
int pos = 0, len = ar.length, bigO = 0;
while (pos < len) {
int slot = ar[pos];
if (slot == pos || slot == len) {
// being in place or invalidated
++pos;
} else {
int next = ar[slot];
if (next == slot) {... 阅读全帖
t**r
发帖数: 3428
41
int atoi(const char *str) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if (!str){return 0;}
int i=0;
bool pos=true;
int res=0;
while (str[i]==' '){ i++;}
if (str[i]=='+'){ pos=true;i++;}
if (str[i]=='-'){ pos = false;i++;}
if (!isdigit(str[i])){return 0;}
while (isdigit(str[i])){
if (pos && res>INT_MAX/10){return INT_MAX;}
if (pos && res==INT_MAX/10... 阅读全帖
b*****i
发帖数: 491
42
xslt code
=========
http://www.w3.org/1999/XSL/Transform">











阅读全帖
b*****i
发帖数: 491
43
xslt code
=========
http://www.w3.org/1999/XSL/Transform">











阅读全帖
a********a
发帖数: 219
44
来自主题: JobHunting版 - 攒人品,回答问题
你既然说已经有人讨论过了,那问我还有什么意义呢?
任何bi-partition/sub-set都是NPC问题。但是NPC并不一定很难解,受到其他限制,
NPC很容易转化成polinomial问题。这个题的关键是sum.我们需要找到的是所有可能的
子集总和,然后就可以找到最小difference。显然是一个dp题。
解dp题,第一就是状态定义:
状态: bool state[pos][number][sum];
这个状态的第一位指的是在前面pos个元素的集合里。
第二位指的是选择多少个元素,在前面pos个里面。
第三位指的是这些元素的和的可能性。
结果指的是是否这个组合可以达到。
初始值是false, state[0][0][0] = true;
递推公式是state[pos][number][sum] = state[pos - 1][number][sum] | state[pos
- 1][number - 1][sum - source[pos - 1]];
寻找结果是
int sum = accumulate(source.begin(), source.end(), 0);
V*****i
发帖数: 92
45
来自主题: JobHunting版 - 问两道google题
There is no need to pass Dictionary and lookup table, use global variable or
use class. My solution as follows:
#include
#include
#include
#include
using namespace std;
// T(n) = \sum_{i=1}^{n-1} (T(i) * H(i+1))
const int MAXSIZE = 100;
class find_str {
private:
set dict;
int lookup_table[MAXSIZE];
public:
find_str(set &d) {
dict = d;
for (int i=0; i ... 阅读全帖
i*******6
发帖数: 107
46
来自主题: JobHunting版 - amazon onsite 面经
#5.输入一个linkedlist和一个数字例如:9->7->8->6->1->2 和 3,输出还是一个
linkedlist但是每三个数reverse一下,例如8->7->9->2->1->6。
扩展了这道题,写成可以自己设置每几个数reverse一下。
思路大概是这样,一个原始链表为
0->1->2->3->4->5->6
如果每3个数反转一下的话,那么先把5指向0,6指向3,2指向null (换言之则是把第kn
个节点指向(k-2)*n+1个节点,再把第n个节点指向null),可以得到
6->3->4->5->0->1->2
然后把整个链表反转就是我们要的结果:
2->1->0->5->4->3->6
附上java代码和数据结构,以及测试用例,在netbeans5.5测试通过:
class ListElement{
public ListElement next;
public int data;
public ListElement(){

}
public ListElement(int data){
th... 阅读全帖
q****x
发帖数: 7404
47
来自主题: JobHunting版 - 收到据信了,随便写点
the pos and speed always integer?
q1: pos 1 at time 1? => pos k at time k
q2: pos 4 at time 2? => pos 2k at time k
q3: pos 9 at time 3? => pos 3k at time k
...
v***a
发帖数: 365
48
来自主题: JobHunting版 - 一道题:Vertical Sticks

// D[i], input
double solve() {
double ans = 1.0;
for (int pos = 2; pos <= N; pos++) {
double t1 = 0.0;
for (int i = 0; i < N; i++) { // choose i in position pos
int x = C[ i ][0]; // < D[i]
int y = C[ i ][1]; // >= D[i]
double pre = 1.0;
int k = 1;
for (; k <= (pos - 1); k++) {
double t2 = pre * ( (double)y / (double)(x + y) );
t1 += (t2 * k);
pre *= ( (double)x ... 阅读全帖
c*****n
发帖数: 96
49
来自主题: JobHunting版 - fb面试题【转】
char* readLine(){
static char[BUFSIZE] buf;
static char* ptr = buf;
static int bufSize = 0;
int outputSize = 0;
char *output = NULL;

while (1){
int pos = getNewLinePos(ptr, bufSize);
if (pos > 0){
// found new line char in the buffer
output = realloc(output, outputSize+pos+1); // one extra char for '
\0'
// TODO: check realloc return value
memcpy (output + outputSize, ptr, pos);
output[outputSize + pos] = '\0';
... 阅读全帖
h*****g
发帖数: 312
50
来自主题: JobHunting版 - fb面试题【转】
多谢你的解答 觉得 //1 处的outputSize 应该时刻更新吧?
char* readLine(){
static char[BUFSIZE] buf;
static char* ptr = buf;
static int bufSize = 0;
int outputSize = 0;
char *output = NULL;

while (1){
int pos = getNewLinePos(ptr, bufSize);
if (pos > 0){
// found new line char in the buffer
output = realloc(output, outputSize+pos+1); // one extra char for '
\0'
// TODO: check realloc return value
memcpy (output + outputSize, ptr, pos);
outpu... 阅读全帖
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)