由买买提看人间百态

topics

全部话题 - 话题: it1
1 (共1页)
E*******0
发帖数: 465
1
来自主题: JobHunting版 - 实现next_permutation
// NextPermutation.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include
#include
using namespace std;
#include
bool myfunction (int i,int j) { return (i>j); }
bool nextPermutation(vector &num) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
//If vector size is 1, permutation is its self.
if (1==num.size())
return true;
// rit is the iterator indicates current ite... 阅读全帖
E*******0
发帖数: 465
2
来自主题: JobHunting版 - 调试成功的next_permutation代码
// 2 4 7 6 3 1
// it1 it2 it3
// switch it1 and it3
// 2 6 7 4 3 1
// sort it2 to end
// 2 6 1 3 4 7
bool nextPermutation(vector &num) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
//If vector size is 1, permutation is its self.
if (1==num.size())
return true;
vector::iterator rit=num.end();
rit--;
vector::iterator... 阅读全帖
p****o
发帖数: 46
3
来自主题: JobHunting版 - 狗家面经
cool. 什么编程语言?第二题, 上个c++:
using namespace std;
list intersect(list intList1, list intList2){
list::const_iterator it1 = intList1.begin();
list::const_iterator it2 = intList2.begin();
list intList3;
while((it1 != intList1.end()) && (it2 != intList2.end())) {
if (*it1 == *it2) {
intList3.push_back(*it1);
++it1;
++it2;
} else if (*it1 < *it2) {
++it1;
... 阅读全帖
E*******0
发帖数: 465
4
来自主题: JobHunting版 - 实现next_permutation
我说下我的算法,大家帮忙看看有没有问题。
#include
class Solution {
public:
void nextPermutation(vector &num) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if (1==num.size())
return;
vector::reverse_iterator rit;
vector::reverse_iterator it1,it2;
for ( rit=num.rbegin() ; rit < num.rend(); ++rit )
{
rit++;
it1=rit;
rit--;
it2=rit;
... 阅读全帖
E*******0
发帖数: 465
5
来自主题: JobHunting版 - 实现next_permutation
我的基本想法是
1 2 3 4 5 6
- 从vector的最后一个开始循环,两个指针it1, it2分别指向当前循环指针和之前一个。
for example, 一开始it1指向6,it2 指向5.
- 比较这两个数
a) it1 >= it2 继续循环。这样可以保证所有在it1之后的书是逆序排列。
b) it1 < it2,把it1 to end 中第一个比it2大的数找到,和it2环位置,并且把从
it1 to end的数顺序排列。
- 直到所有的数都是逆序排列。
E*******0
发帖数: 465
6
来自主题: JobHunting版 - 实现next_permutation
我的基本想法是
1 2 3 4 5 6
- 从vector的最后一个开始循环,两个指针it1, it2分别指向当前循环指针和之前一个。
for example, 一开始it1指向6,it2 指向5.
- 比较这两个数
a) it1 >= it2 继续循环。这样可以保证所有在it1之后的书是逆序排列。
b) it1 < it2,把it1 to end 中第一个比it2大的数找到,和it2环位置,并且把从
it1 to end的数顺序排列。
- 直到所有的数都是逆序排列。
e*******i
发帖数: 56
7
来自主题: JobHunting版 - Facebook Phone Interview
#include
#include
#include
using namespace std;
void printEqProducts(int n)
{
typedef unordered_multimap > MyMap;
typedef unordered_map ProductMap;
MyMap resMap;
ProductMap proMap;
for(int i=1; i<=n;i++)
for(int j=1;j<=n;j++)
{
resMap.insert( MyMap::value_type(i*j, pair(i, j)) );
proMap.insert( pair(i*j,i*j) );
}
pair阅读全帖
e*******i
发帖数: 56
8
来自主题: JobHunting版 - Facebook Phone Interview
#include
#include
#include
using namespace std;
void printEqProducts(int n)
{
typedef unordered_multimap > MyMap;
typedef unordered_map ProductMap;
MyMap resMap;
ProductMap proMap;
for(int i=1; i<=n;i++)
for(int j=1;j<=n;j++)
{
resMap.insert( MyMap::value_type(i*j, pair(i, j)) );
proMap.insert( pair(i*j,i*j) );
}
pair阅读全帖
s******i
发帖数: 236
9
来自主题: JobHunting版 - 求教EA一道面试题
https://www.hackerrank.com/challenges/unfriendly-numbers
There is one friendly number and N unfriendly numbers. We want to find how
many numbers are there which exactly divide the friendly number, but does
not divide any of the unfriendly numbers.
Input Format:
The first line of input contains two numbers N and K seperated by spaces. N
is the number of unfriendly numbers, K is the friendly number.
The second line of input contains N space separated unfriendly numbers.
Output Format:
Output the a... 阅读全帖
p*****2
发帖数: 21240
10
来自主题: JobHunting版 - [google面试]iterator访问
大概这个样子吧。
class flat implements Iterator
{
Iterator> it1=null;
Iterator it2=null;

void Getit2()
{
it2=null;
if(it1!=null)
{
while(it1.hasNext())
{
Vector v=it1.next();
if(v!=null && v.size()!=0)
{
it2=v.iterator();
return;
};
}
}
}
public flat(Vector> a)
{
if(a!=null)
{
it1=a.iterator();
Getit2();
}
... 阅读全帖
p****o
发帖数: 46
11
oj 在{0, 1}测试的结果是{{1}, {0,1}, {1,0}}
但我自己运行打印出来是{{0,1}, {1,0}}
请大伙帮忙看看。
代码如下
#include "stdio.h"
#include
using namespace std;
class Solution {
public:
vector > permute(vector &num) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
vector v(0);
doPermute(v, num);
return vv;
}

void doPermute(vector &v, vector &num) {
if(num.empty()) {
vv.push_back(v); ... 阅读全帖
l****c
发帖数: 782
12
来自主题: JobHunting版 - 准备回来跟大家一起练习做题了
My method is that to use two hash_table to store the point_x and point_y.
When we could not find any same value in x_table or y_table, counter++ and
save the new value; When there is at least one same value in either table,
we don't need add counter.
However, I wonder how to use unordered_table more beautiful. Please give me
some suggestion.
int minNumofPoint(vector> point){
unordered_map hash_given_points_x;
unordered_map hash_given_points_y;
hash_given... 阅读全帖
x*****0
发帖数: 452
13
来自主题: JobHunting版 - 两道最近onsite算法题
(2) C++ code:
void split_by_whitespace(string& s, vector& result)
{
stringstream ss(s);
string cur;

while(ss >> cur)
result.push_back(cur);
}
void maxi_assonance(vector& x)
{
vector::iterator it = x.begin();
vector > r;
map key_ind;

for(; it!=x.end(); ++it)
{
string cur = *it;
if(cur[0]=='a' || cur[0]=='e' ||
cur[0]=='i' || cur[0]=='o' ||
cur[0]=='u')
{ ... 阅读全帖
t***q
发帖数: 418
14
【 以下文字转载自 Programming 讨论区 】
发信人: treeq (treeq), 信区: Programming
标 题: 天,如何能让程序转得快点?有包子。
发信站: BBS 未名空间站 (Fri Feb 27 23:26:22 2015, 美东)
天,如何能让程序转得快点?
原帖在这里:
http://www.mitbbs.com/article_t0/Programming/31381809.html
主要是要做 title matching.
有两个 file, file A 162283 行 X 12 列。 File B 3695 行 X 6 列。用 A 的 第五
列和 B的第四列进行比较, 对 B 的第四列的每一行, 从 A的 那 162283 行中 找出
与之最相似的那一行。A 的第五列和 B 的第四列都是些影视作品的 title, 是一些长
短不一的 string. 我用的是 Levenshtein algorithm 算每一对string 的相似度,再
把相似度排序,从高到低,找出相似度最大的那一个 string, 也就是影视作品的
title, ... 阅读全帖
t***q
发帖数: 418
15
【 以下文字转载自 Programming 讨论区 】
发信人: treeq (treeq), 信区: Programming
标 题: 天,如何能让程序转得快点?有包子。
发信站: BBS 未名空间站 (Fri Feb 27 23:26:22 2015, 美东)
天,如何能让程序转得快点?
原帖在这里:
http://www.mitbbs.com/article_t0/Programming/31381809.html
主要是要做 title matching.
有两个 file, file A 162283 行 X 12 列。 File B 3695 行 X 6 列。用 A 的 第五
列和 B的第四列进行比较, 对 B 的第四列的每一行, 从 A的 那 162283 行中 找出
与之最相似的那一行。A 的第五列和 B 的第四列都是些影视作品的 title, 是一些长
短不一的 string. 我用的是 Levenshtein algorithm 算每一对string 的相似度,再
把相似度排序,从高到低,找出相似度最大的那一个 string, 也就是影视作品的
title, ... 阅读全帖
t***q
发帖数: 418
16
天,如何能让程序转得快点?
原帖在这里:
http://www.mitbbs.com/article_t0/Programming/31381809.html
主要是要做 title matching.
有两个 file, file A 162283 行 X 12 列。 File B 3695 行 X 6 列。用 A 的 第五
列和 B的第四列进行比较, 对 B 的第四列的每一行, 从 A的 那 162283 行中 找出
与之最相似的那一行。A 的第五列和 B 的第四列都是些影视作品的 title, 是一些长
短不一的 string. 我用的是 Levenshtein algorithm 算每一对string 的相似度,再
把相似度排序,从高到低,找出相似度最大的那一个 string, 也就是影视作品的
title, 加到 file B 对应的那一个title 那一行。再加入一个从file A 出来的对应的
一个id, 到 file B 里。算相似度前,我先对每个title 组成的string做预处理,去掉
“:”,”-“,”season”,”episode “ , 等一些词。... 阅读全帖
t***q
发帖数: 418
17
把 c++ 程序改成这样,快了许多,虽说程序不work,但至少说明,应该在算distance
之前就把 string processing 都做了:
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
size_t uiLevenshteinDistance(const std::string &s1, const std::string &s2)
{
const size_t m(s1.size());
const size_t n(s2.size())... 阅读全帖
h**6
发帖数: 4160
18
来自主题: JobHunting版 - 问个stl的iterator问题
I think you can use a pointer to an iterator as below:
typdef vector vi;
void main()
{
int input[] = {1, 4, 5};
vi weight = vi(input, input+sizeof(input)/sizeof(input[0]));
vi::iterator it1 = weight.begin();
vi::iterator it2 = weight.end()-1;
vi::iterator *pit = new vi::iterator;
if(1+1 == 3)
*pit = it1;
else
*pit = it2;
int result = **pit;
delete pit;
cout< }
E*******0
发帖数: 465
19
来自主题: JobHunting版 - 实现next_permutation
举个例子
1 2 3 4 5 6
找出 4 6 5 3 2 1的next permutation.
it1 -> 6 it2 ->4 since 6 5 3 2 1是逆序排列。
找出 it1 to end 中第一个比4大的数5,(note:这里第一个币it2大的数,不是位置,
是大小上第一个比it2大的数)把5和4位置换一下。
5 6 4 3 2 1 在把6 to end 顺序排列。
so next permutation是 5 1 2 3 4 6。
b********n
发帖数: 609
20
来自主题: Programming版 - A C++ STL question
咱能不能不这麽死心眼啊?
it = hash_table.begin();
while (it != hash_table.end())
{
hash_table::iterator it1 = it+1;
if (some_condition)
hash_table.erase (it);
it = it1;
}
g*********s
发帖数: 1782
21
来自主题: Programming版 - stl iterator has "NULL" like const?
It's a long story.
I'm designing a LRU cache. For each char ch being accessed, there's an int
typed time stamp. For example, ('a', 3) means @ time 3 we access char 'a'.
The cache must support fast operations of the following:
query(char ch)
insert(char key, int time_stamp)
get_earliest_time(int time&)
get_latest_time(int time&).
I use a vector X and a sorted doubly linked list Y. The sorted linked list
would keep the latest time stamp of each char, and the vector would keep the
address of each e... 阅读全帖
u***r
发帖数: 4825
22
来自主题: Military版 - 被低估的华为
http://www.cb.com.cn/companies/2014_0604/1063999.html
【中国经营网注】华为,一个以“狼性文化”著称的全球通信设备制造企业,被冠
以“神秘”、“封闭”、“不开放”的名号,然而却很少真正有人领略了华为的实力。
这家公司已经在很多IT领域有所建树,甚至已经到了可怕的程度。
据21世纪经济的报道,尽管华为早已是中国IT产业的旗帜,但是,它依然是一家被
低估的企业。在BAT们大行其道、互联网企业站在舞台中央的时候,这种低估就更为明
显了。
在电信设备、企业网和手机三个领域,华为已经是电信设备领域的王者无人争议,
与爱立信共同处于产业链最顶端。2013年华为来自电信领域的营收仅次于爱立信,总收
入则超过了爱立信,利润更是高居行业第一。对华为的低估,主要源自企业网和手机领
域。大多数人只看到华为的手机,对它的低估显得很正常。毕竟,它在这个领域还显得
有些蹩脚,对消费者的把握能力还显得简单粗暴,虽然也正在初步找到感觉。但是,一
旦回到B2B领域,华为的实力就显得那么可怕,像是一支训练有素的军队。
IT战场的幼狮
先看一组不怎么被媒体关注的数字。
服... 阅读全帖
l*********8
发帖数: 4642
23
来自主题: JobHunting版 - 求教EA一道面试题
倒数第6行:
divisors.erase(*it1) 改成
divisors.erase(*it2)
就行了。
我试过了,可以通过。

N
t**e
发帖数: 1805
24
prices going down? look forward to it1
d******n
发帖数: 1713
25
来自主题: Money版 - discover水很深哈
目前有四种卡,网站上没有sort
1. more 据说是垃圾,本来打电话想转会it
2. miles 不能online申请,不知道怎么样?是买机票还是转点到航空公司
3. it1, 平常1%,季节性5%
4. it2, 油和饭常年2%,其它1%,但没季节性5%了
感觉discover真是没落了现在
chase的崛起,让discover10年前的优势不再哈呵呵
y****m
发帖数: 35
26
来自主题: Chinese版 - Anybody wants to join the army?
I do. And I'll be in the army reserve on Friday.So So happy about it1
From then on I'll be a more worthy person.
n***d
发帖数: 8857
27
来自主题: PhotoGear版 - local出个东西可真费劲
我没空,说你取了钱再告诉我,it1个小时后打电话. 上来就"hey, I have a
situation here, I only have xxx in my account, would you consider ...?" 我就
打断it,"I won't", 挂电话。
b***n
发帖数: 462
28
t2_mutex 是我想岔了。
f1中 t1_ready = 1 在 if (1==t1_ready) 后面能,也就是说,每两次 (0==(it1 % N
))才能又一次进入 if (1==t1_ready),让thread sleep。不知道这个是不是你要求的。
当f2加入进来,每一个循环都t1_ready=0, 那么,f1可能永远也没有机会进入sleep。
不知掉这样的话他们交换的数据是否是相同步骤的。
当临界情况发生的时候,能满足你的需求吗?
而且,会不会两个同时sleep?这个我还没想好。
不过学习了一下pthread_cond_wait,很有意思的一个东西。
l****i
发帖数: 3339
29
I have one 3 and 1 years old when i start my cpa jouney. Now I passed 3 and
one
is waiting for the result.
i study at night when they go to bed and weekend sometimes. my mom came and
helpin betweens. so you should be able to do it1
1 (共1页)