由买买提看人间百态

topics

全部话题 - 话题: vectors
首页 上页 1 2 3 4 5 6 7 8 9 10 (共10页)
q**j
发帖数: 10612
1
【 以下文字转载自 Economics 讨论区 】
发信人: qqzj (小车车), 信区: Economics
标 题: 请问有没有人用R里面的vars package做vector autoregression?
发信站: BBS 未名空间站 (Thu Oct 13 17:25:07 2011, 美东)
请问在用predict()产生预测以后如何才可以(简单的)得到covariance matrix of
the forecasts? 我知道可以得到forecast error的covariance,但是如何估计
parameter estimate带来的的forecast error呢?多谢了。
G***G
发帖数: 16778
2
来自主题: Statistics版 - support vector machine
when support vector machine method is used for model building and prediction,
should a normalization/transformation method be used for the raw data?
I have two columns of data which will be used for training
age sex
65 1
77 0
88 0
23 1
do I need to do some transform for the data in order to train SVM?
h***x
发帖数: 586
3
1) As catforfish said, the data point is not necessary to be a scalar, a
vector is fine. All my work on clustering are for multi dimension instead of
one dimension. I suggest you spending some time to learn clustering first.
2)In your example, v1 and v2 has strong correlation. If you want to take
this into account in clustering, you should not use euclidean distance as
the statistical measure, you can use other measures with the features you
like for your task.
3)For clustering, result explanati... 阅读全帖
c***z
发帖数: 6348
4
You can use correlation, or inner product, or cosine distance, or Hamming
distance, or anything you wish for distance between vectors

numbers.
K***a
发帖数: 72
5
来自主题: Statistics版 - vector regression?
谁能给解释一下什么是vector regression?
i*********5
发帖数: 19210
6
小道消息,鸵鸟上Garmin Vector了!
i*********5
发帖数: 19210
7
Garmin-Sharp is obliged to use the Garmin Vector power-meter pedals,
although most riders are only using the bodies, not the meters themselves
http://forum.slowtwitch.com/cgi-bin/gforum.cgi?post=5156476;sb=
It's an eSs aRe aM, which is a SRM having its logos taped over
Lots of anecdotal evidence on the garmin forums, amazon, and various cycling
forums of people complaining they are fragile and temperamental to
correctly setup. I don't know how they would fare in the pro peloton with
the crashes ... 阅读全帖
b****n
发帖数: 15
8
转让 Xterra Mens Vector Pro Full Suit, Medium Size.
今年夏天买的,穿过4次开水。没有任何问题。照片请站内私信。$179 shipped in US
不怎么发帖, 如有违版规,请版主告知。谢谢!
f**o
发帖数: 12
9
RT,最近开始在尝试在R里面做一下support vector machine试一下效果和速度,不过
不知道现在一般都是流行用哪一个package。 我在网上搜到一个叫e1017的package,不
知道还有没有其他的可用的呢。
w*******y
发帖数: 60932
10
Beltronics V995 Vector Radar and Laser Detector (Black/Silver)
Brand New $ 159.99
Sale price 199.99 - 20% off code -enter code QJJQ5P73
Amazon .com
This is one of the best you can buy under $ 300.00
w*******y
发帖数: 60932
11
RadioShack has the Beltronics Vector 995 in stores for $79.97. This unit
shares the M4 horn with the RX65, GX65 8500 X50, and 9500ix. Includes radar
unit, coiled smart cord, mount, 4 suction sups, soft zippered travel case.
Link:
http://www.radioshack.com/product/index.jsp?productId=2760953
tmaxx445
f**d
发帖数: 768
12
来自主题: Neuroscience版 - eBook: From computer to brain
这是一本计算神经科学的优秀著作,全文拷贝这里(图和公式缺),有兴趣的同学可以
阅读
如需要,我可以分享PDF文件(--仅供个人学习,无商业用途)
From Computer to Brain
William W. Lytton
From Computer to Brain
Foundations of Computational Neuroscience
Springer
William W. Lytton, M.D.
Associate Professor, State University of New York, Downstato, Brooklyn, NY
Visiting Associate Professor, University of Wisconsin, Madison
Visiting Associate Professor, Polytechnic University, Brooklyn, NY
Staff Neurologist., Kings County Hospital, Brooklyn, NY
In From Computer to Brain: ... 阅读全帖
l*******t
发帖数: 79
13
用c++写了一下用memoization的版本,需要84ms过leetcode。不用memoization的话反
而只需要16ms。。。是因为memoization过程中有很多copy导致的吗?如果是这样,面
试过程中用哪种方法比较好呢?(或者代码可以更精简不用这么多copy?...) 毕竟前者
worst case复杂度是o(n^2),而后者是(2^n)额。。。求版上大神指点 跪谢Orz
class Solution {
public:
vector> partition(string s) {
vector> f(s.size(), vector(s.size()));
isPalindrome(f, s);

return dfs1(f, 0, s);
}

private:
unordered_map>> cache_;

void isPalind... 阅读全帖
R******1
发帖数: 58
14
来自主题: JobHunting版 - 请教leetcode Subsets II
刚写了一个可以work的,但是感觉效率很低
还是实现了一个find的function
class Solution {
public:
vector > subsetsWithDup(vector &S) {
vector myset = S;
sort (myset.begin(), myset.end());
return subset (myset);
}


vector< vector > subset (vector &S) {
vector < vector > res;
vector < vector > imediate;
vector < vector >::iterator it;
vector temp;
int lastdigit, pre;
if (S.size() == 1... 阅读全帖
A*****o
发帖数: 284
15
来自主题: JobHunting版 - FB onsite面经加求bless
祝LZ拿到offer ~~
顺便献丑贴个email那题自己的完整代码,真心觉得不简单... 我是用了并查集来
统计合并,
请大牛给个简单点的解法吧,面试中是不可能有时间写这种代码的感觉...
#include
#include
#include
#include
#include
using namespace std;
/*
第二题是有这么一个class Contact,里面有一个String的name,和一个List
装着email address,是这个Contact有的address,用一个list装着是因为一个人有可
能有多个email,现在给你an array of Contact,比如
#1 John [j**[email protected]]
#2 Mary [m**[email protected]]
#3 John [j**[email protected]]
#4 John [j**[email protected], j**[email protected], j**[email protected]]
#5 Bob [bo... 阅读全帖
A*****o
发帖数: 284
16
来自主题: JobHunting版 - FB onsite面经加求bless
祝LZ拿到offer ~~
顺便献丑贴个email那题自己的完整代码,真心觉得不简单... 我是用了并查集来
统计合并,
请大牛给个简单点的解法吧,面试中是不可能有时间写这种代码的感觉...
#include
#include
#include
#include
#include
using namespace std;
/*
第二题是有这么一个class Contact,里面有一个String的name,和一个List
装着email address,是这个Contact有的address,用一个list装着是因为一个人有可
能有多个email,现在给你an array of Contact,比如
#1 John [j**[email protected]]
#2 Mary [m**[email protected]]
#3 John [j**[email protected]]
#4 John [j**[email protected], j**[email protected], j**[email protected]]
#5 Bob [bo... 阅读全帖
l*******t
发帖数: 79
17
题目就是find all primes less or equal than n,要求体现OOD和写unit test。求拍
砖,多谢各位!
ps:不确定如果面试中让写C++ unit test,不用gtest, boost.test这些库,写成这样
可以吗?。。。因为之前自己写代码没有养成写unit test的习惯,感觉不太规范。。
#include
#include
#include
#include
#include
using namespace std;
class PrimeFinder {
friend class PrimeFinderTest;
public:
PrimeFinder(int n = 2) {
is_prime_.push_back(false);
is_prime_.push_back(false);
is_prime_.push_back(true);
primes_.... 阅读全帖
S******t
发帖数: 151
18
来自主题: JobHunting版 - 问两道fb题
我贴一个第一题能通过的代码吧:
vector bestA;
int bestLen;
void search(int idx, int sum, int len, vector>>& f,
vector& ret, vector& A) {
//cout << idx << " " << sum << " " << len << endl;
if (idx == 0) {
int lenA = bestA.size();
vector v = ret;
/*
for (int i = 0; i < v.size(); i++)
cout << v[i] << " ";
cout << endl;
*/
if (v.size() < lenA || lenA == 0) {
bestA = v;
return;
... 阅读全帖
p*****p
发帖数: 379
19
用checked标记封闭的区域,用markChecked把O变成X
small能过,large挂了,莫非是因为偷懒用dfs造成溢出了?
class Solution {
public:
void solve(vector> &board) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if (board.size() <= 1) return;
int rows = board.size();
int cols = board[0].size();
vector> visited(rows, vector(cols, false));
vector> checked(rows, vector(cols, false));

f... 阅读全帖
Q*****a
发帖数: 33
20
来自主题: JobHunting版 - airBnb电面面经
实现了4种方法
1: 直接遍历完整计算edit distance. 285 clocks.
2: 直接遍历,计算edit distance到 >k 就返回. 149 clocks.
3: Trie+shortcut edit distance. Build trie: 606 clocks, process: 6 clocks.
http://stevehanov.ca/blog/index.php?id=114
4: Generate delete k transformation. Build dict: 17033 clocks. process: 0
clocks.
但这里不仅需要生成delete k的pattern, 还需要生成所有delete 1..k-1的pattern,
否则不能handle如(chrome brome)的case
http://blog.faroo.com/2012/06/07/improved-edit-distance-based-s
#include "common.h"
class Trie {
public:
class TrieNo... 阅读全帖
Q*****a
发帖数: 33
21
来自主题: JobHunting版 - airBnb电面面经
实现了4种方法
1: 直接遍历完整计算edit distance. 285 clocks.
2: 直接遍历,计算edit distance到 >k 就返回. 149 clocks.
3: Trie+shortcut edit distance. Build trie: 606 clocks, process: 6 clocks.
http://stevehanov.ca/blog/index.php?id=114
4: Generate delete k transformation. Build dict: 17033 clocks. process: 0
clocks.
但这里不仅需要生成delete k的pattern, 还需要生成所有delete 1..k-1的pattern,
否则不能handle如(chrome brome)的case
http://blog.faroo.com/2012/06/07/improved-edit-distance-based-s
#include "common.h"
class Trie {
public:
class TrieNo... 阅读全帖
x*******9
发帖数: 138
22
来自主题: JobHunting版 - 问一道G家热题
做了一下
>> 给定一个数字数组 ,其中每个元素是从末端数小于原数组中该元素的个数。求原数
组。
Time complexity: O(n * logn) // quick-sort + traverse
Memo complexity: O(n)
>> 令s[i]为a[i+1..n-1]中比a[i]大的数的数量。求最大的s[i]。要求O(nlogn)
Time complexity: O(n * logn) // Manipulate the Binary Indexed Tree
Memo compleixty: O(n)
#include
#include
#include
#include
#include
#include
using namespace std;
#define print(x) cout << x << endl
#define input(x) cin >> x
const int SIZE = 1024;
// @brief Bin... 阅读全帖
k****s
发帖数: 1209
23
来自主题: Biology版 - 蜕皮素
原文在
http://www.skizit.biz/2013/07/21/ecdysone-insect-hormone-an-ind
Ecdysone Insect Hormone Switches on Disease
21 Jul 2013 | ECDYSONE
MORGELLONS:
INSECT HORMONE ECDYSONE TRIGGERS GENETIC CHANGES
TO BUILD NEW HAIR, SKIN, NAILS and CAUSE DISEASES
SkizitGesture-2013
Morgellons is a military grade entomological terror weapon being used to
torture and kill innocent civilians. The medical community has not been
informed about this disease and its complexity keeps it from being properly
identified, ... 阅读全帖
j*****j
发帖数: 201
24
来自主题: JobHunting版 - leetcode上一题,求正解
我的解法, test case都通过了
vector > combinationSumrec(vector candidates, int start,
int end,int target){
vector > toreturn;
if (target == 0){
vector temp;
toreturn.push_back(temp);
return toreturn;
}
if (target return toreturn;
if (start > end)
return toreturn;
if (start == end){
if (target%(candidates[start... 阅读全帖
r**a
发帖数: 536
25
来自主题: Programming版 - 帮忙看一个code
我试了试下面两个code,第一个比我原来贴的那个速度明显快了但是还是比不上第二个。
Code1:
#include
#include
using namespace std;
class A
{
public:
A(const size_t N): _N(N) {}
vector > getXY()
{
//vector xytemp;
//for (size_t i = 0; i != 2; ++i)
// xytemp.push_back(i+3);
vector > xy(_N);
for (size_t i = 0; i != _N; ++i)
for (size_t j = 0; j != 2; ++j)
xy[i].push_back(j+3... 阅读全帖
k***t
发帖数: 769
26
来自主题: Programming版 - 能帮我看看Ruby的这道题吗?
This question is to define Ruby classes for vectors and matrices.
Define two classes MyVector and MyMatrix with the methods described be-
low.
A MyVector object represents a row vector while a MyMatrix object repre-
sents a matrix that internally organized as an array of MyVector objects.
Methods for MyVector
1. The initialize method takes an array of integers as argument.
2. The length method returns the size of the vector
3. The * method takes an argument a:
if a is a vector, then it returns t... 阅读全帖
A**u
发帖数: 2458
27
来自主题: JobHunting版 - G家电面砸了,面经
我有笨办法
#include
#include
#include
#include
using namespace std;
vector P( int n );
vector R( int n );
vector P( int n )
{ vector code;
if ( n == 1 )
{
code.push_back(string("0"));
code.push_back(string("1"));
}
else
... 阅读全帖
p****e
发帖数: 3548
28
修改下BFS也可以,要记下路径就行
用'a'-'z'方法再写了一个
大数据: 750ms
class Solution {
public:
void getrows(vector, unordered_map::
iterator> > &path,
int col, vector &row, vector > &
ret){
row.push_back(path[col].second->first);
vector & cp = path[col].first;
for(int i=0; i if(cp[i] < 0){
reverse(row.begin(), row.end());
ret.push_back(row);
... 阅读全帖
p****e
发帖数: 3548
29
修改下BFS也可以,要记下路径就行
用'a'-'z'方法再写了一个
大数据: 750ms
class Solution {
public:
void getrows(vector, unordered_map::
iterator> > &path,
int col, vector &row, vector > &
ret){
row.push_back(path[col].second->first);
vector & cp = path[col].first;
for(int i=0; i if(cp[i] < 0){
reverse(row.begin(), row.end());
ret.push_back(row);
... 阅读全帖
o******3
发帖数: 91
30
来自主题: JobHunting版 - 面试F家让先做programming puzzle
决定把题目跟我写的很挫的代码贴上来,有需要的同学可以来看。。。
代码可以过sample test
但是目前还不能过所有的Test
题目:
There are K pegs. Each peg can hold discs in decreasing order of radius when
looked from bottom to top of the peg. There are N discs which have radius 1
to N; Given the initial configuration of the pegs and the final
configuration of the pegs, output the moves required to transform from the
initial to final configuration. You are required to do the transformations
in minimal number of moves.
A move consists of picking the topm... 阅读全帖
o******3
发帖数: 91
31
来自主题: JobHunting版 - 面试F家让先做programming puzzle
决定把题目跟我写的很挫的代码贴上来,有需要的同学可以来看。。。
代码可以过sample test
但是目前还不能过所有的Test
题目:
There are K pegs. Each peg can hold discs in decreasing order of radius when
looked from bottom to top of the peg. There are N discs which have radius 1
to N; Given the initial configuration of the pegs and the final
configuration of the pegs, output the moves required to transform from the
initial to final configuration. You are required to do the transformations
in minimal number of moves.
A move consists of picking the topm... 阅读全帖
d**e
发帖数: 6098
32
☆─────────────────────────────────────☆
oneid (Mobius) 于 (Fri Dec 28 19:12:49 2012, 美东) 提到:
比如careercup,glassdoor上每个公司那么多题,难道大家都做完了?
还是leetcode has OJ?比较容易发现code的问题?
但是大家觉得leetcode的题被问得几率比careercup上针对性的公司的题概率高么?不可
能把?
☆─────────────────────────────────────☆
luckynoob (菜鸟) 于 (Fri Dec 28 19:20:06 2012, 美东) 提到:
题目肯定是做不完的,重要的是实现一下一些重要方法吧,书还是要看的
☆─────────────────────────────────────☆
lolhaha (人生如棋,棋如人生) 于 (Fri Dec 28 19:21:35 2012, 美东) 提到:
careecup上的题你做得完吗?
那上面的很多回帖都有问题,没有正确答案

☆─────... 阅读全帖
p****o
发帖数: 46
33
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); ... 阅读全帖
i**********e
发帖数: 1145
34
来自主题: JobHunting版 - 请问一道很难的面试题
刚想到很精简的 code,不需要用 post-fix stack-based expression,直接储存进一
个 string 数组即可。
效率应该是不错的了,有一些方面可以考虑提高效率,例如用 vector 需要删除元素可
能会慢些,但 vector 里的元素很少,应该影响不大。
还有一点就是每次传递归的时候,都需要把所有的数组重新 copy 一次。这是无可避免
的,因为每次进入下一层递归时必须传 copy,不能在原有数组中更改。
#include
#include
#include
#include
#include
using namespace std;
void generate(vector A, int target, int s, vector expression);
template
void eraseAt(vector &vec, int i) {
typename vector::iterator ... 阅读全帖
l********t
发帖数: 878
35
来自主题: JobHunting版 - 求leetcode 4sum的O(n^2)解法
/*accepted*/
bool equalVector(vector v1, vector v2){
for(int ii = 0; ii < v1.size(); ++ii){
if (v1[ii] != v2[ii]) return false;
}
return true;
}
bool compareVector(vector v1, vector v2){
for(int ii = 0; ii < v1.size(); ++ii){
if (v1[ii] < v2[ii]) return true;
else if (v1[ii] > v2[ii]) return false;
}
return false;
}
class Solution {
public:
vector > fourSum(vect... 阅读全帖
l********t
发帖数: 878
36
来自主题: JobHunting版 - 求leetcode 4sum的O(n^2)解法
/*accepted*/
bool equalVector(vector v1, vector v2){
for(int ii = 0; ii < v1.size(); ++ii){
if (v1[ii] != v2[ii]) return false;
}
return true;
}
bool compareVector(vector v1, vector v2){
for(int ii = 0; ii < v1.size(); ++ii){
if (v1[ii] < v2[ii]) return true;
else if (v1[ii] > v2[ii]) return false;
}
return false;
}
class Solution {
public:
vector > fourSum(vect... 阅读全帖
y*****i
发帖数: 141
37
来自主题: JobHunting版 - 问道G家的题
照着Maxthon的编码解法写了一个:
#include
#include
#include
#include
using namespace std;
bool bool_vec_none(const vector & vec) {
for(auto elem : vec) {
if (elem) {
return false;
}
}
return true;
}
bool bool_vec_all(const vector & vec) {
for(auto elem : vec) {
if (!elem) {
return false;
}
}
return true;
}
string word_abbreviation(string target, vector dict)
{
if (t... 阅读全帖
b******g
发帖数: 3616
38
来自主题: JobHunting版 - 共享一道电面题k-sum
今天正好复习到这题。顺手写了个k-sum的代码,过了LC的3sum和4sum的test。有兴趣帮
着找找有没有没发现的bug。我觉得理解了3sum的算法,并写过4sum以后,这个kSum其
实也就一个小变种,一个葫芦里的药了。由于代码不短,感觉面试的时候还是分成子程
序写比较好,即使时间来不及写完,至少思路能和面试官说清楚。
思路和排板好看点的代码写在自己的复习总结博客里了:
http://bangbingsyb.blogspot.com/2014/11/leetcode-4sum.html
代码:
class Solution {
public:
vector > fourSum(vector &num, int target) {
vector> allSol;
vector sol;
sort(num.begin(),num.end());
kSum(num, 0, num.size()-1, target, 4, sol, allSol);... 阅读全帖
s****h
发帖数: 3979
39
来自主题: DataSciences版 - spark 问题
data frame API 1.3 才有。
弄进一个dense vector很直接:
import org.apache.spark.mllib.linalg.{Vector, Vectors}
val path = "~/test60m.txt"
val minPartitions = 4

val parsed = sc.textFile(path, minPartitions)
.map(_.trim)
.filter(line => !(line.isEmpty || line.startsWith("#")))
val a = parsed.map({ line =>
val fields = line.split(" ")
(fields(0).toInt, fields(1))})
val dataLoad = a.map(x => (x._1, Vectors.dense(x._2.split(',').map(_.
toDouble))))
可是sparse vector就不会了。
不知道怎么结合下面的例子
// Create a dense vector (... 阅读全帖
x********o
发帖数: 519
40
来自主题: JobHunting版 - 问个算法题,修改版
here is the C++ code:
#include
#include
#include
using namespace std;
void print_vector(const vector &v){
vector::const_iterator iter=v.begin();
while(iter!=v.end()){
cout<<*iter<<" ";
++iter;
}
cout< }
void subset(vector v, vector sub, int size,set > &s){
if(sub.size()==size){
sort(sub.begin(),sub.end());
s.insert(sub);
return;
}
vector::iterator iter=v.begin();
size_t l=v.size();
for(int ... 阅读全帖
d****n
发帖数: 233
41
来自主题: JobHunting版 - 问一到题目
vector subsets(vector a) {
int n = a.size();
// minimum negative sum
int min = 0;
// max postive sum
int max = 0;

for(int i = 0; i < n; i++) {
if (a[i] < 0) {
min += a[i];
}
else {
max += a[i];
}

// mask[i] = 1 means there is a sub sum equals to i
int mask[] = new int[-min + max + 1];
// lookupTable[i, j] = 1 means there is a sub sum equals to j
// and a[i] is in the sub set
ve... 阅读全帖
i**********e
发帖数: 1145
42
来自主题: JobHunting版 - leetcode出了新题word ladder
word ladder II 有人过了 large tests 吗?
我抛砖引玉一下吧,希望有大牛可以提出更好的解法。
思路就是按照 wwwyhx 的思路 backtrack 重建路径。昨晚写了一下,果然简洁很多,
整个程序不到50行。
基于程序可读性,所以 bottom up 返回路径,产生了很多不必要的拷贝而导致效率会
差很多。但路径组合没那么多,所以性能上也没什么影响。
typedef unordered_multimap Map;
typedef pair PairIter;
vector> findLadders(string start, string end, unordered_set<
string> &dict) {
Map map, map2;
queue q, q2;
q.push(start);
bool goal = false;
while (!q.empty()) {
... 阅读全帖
t********6
发帖数: 348
43
来自主题: JobHunting版 - leetcode出了新题word ladder
第二题,求指导:
class Solution {
public:
void traverse(string& start, string& root, unordered_map string> >& prev, vector& current, vector>& result) {
auto iter = prev.find(root);
for (string str : iter->second) {
current.push_back(str);
if (str == start) {
vector new_one(current.size());
reverse_copy(current.begin(), current.end(), new_one.begin()
);
result.push_ba... 阅读全帖
i**********e
发帖数: 1145
44
来自主题: JobHunting版 - leetcode出了新题word ladder
word ladder II 有人过了 large tests 吗?
我抛砖引玉一下吧,希望有大牛可以提出更好的解法。
思路就是按照 wwwyhx 的思路 backtrack 重建路径。昨晚写了一下,果然简洁很多,
整个程序不到50行。
基于程序可读性,所以 bottom up 返回路径,产生了很多不必要的拷贝而导致效率会
差很多。但路径组合没那么多,所以性能上也没什么影响。
typedef unordered_multimap Map;
typedef pair PairIter;
vector> findLadders(string start, string end, unordered_set<
string> &dict) {
Map map, map2;
queue q, q2;
q.push(start);
bool goal = false;
while (!q.empty()) {
... 阅读全帖
t********6
发帖数: 348
45
来自主题: JobHunting版 - leetcode出了新题word ladder
第二题,求指导:
class Solution {
public:
void traverse(string& start, string& root, unordered_map string> >& prev, vector& current, vector>& result) {
auto iter = prev.find(root);
for (string str : iter->second) {
current.push_back(str);
if (str == start) {
vector new_one(current.size());
reverse_copy(current.begin(), current.end(), new_one.begin()
);
result.push_ba... 阅读全帖
f*********0
发帖数: 17
46
来自主题: JobHunting版 - 一道google面经难题
实现了一下,用了dfs,略有不同的是:
上面左边做dfs时,value+1
右边下面dfs时,value+10
这样就用这个矩阵记录这轮dfs是否访问过这个节点。
所以这样每个节点最多被访问一次,复杂度为O(N*N);
代码求拍
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int N;
bool isValidIndex(int x, int y) {
return x >= 0 && x < N && y >= 0 && y < N;
}
void dfs(vector > &matrix, int set,
vector > &result, int x, int y) {
if (result[x][y] >= set) return;
result[x][y] += set;
for (int i = 0; i < 4; ++i) {
if (isValidIndex(x+dx[i], y+dy[i])... 阅读全帖
b******g
发帖数: 77
47
一个martrix,每行每列都是sorted,找到前kth 个
Analysis:
Applying a quick-select algorithm will achieve an O( n * n ) time
complexity. Can we do better? Yes. Here is a algorithm:
1. Like quick-select algorithm, this algorithm applies divide-and-
conquer.
2. Initialize those two boundary lines to (n * [0] and n * [n]) to
include all array items in boundary.
3. Process subarray between boundary lines (lo, hi ) in each
recursive call:
a. select a random item in su... 阅读全帖
x******a
发帖数: 6336
48
来自主题: Programming版 - C++ problem
I got thousands problems on the following piece of code "dumpfile.h" when I
compile under cygwin. it is ok under visual stduio... can anyone help?
Thanks!
#include
#include
#include //ostream_iterator
#include //cerr
#include //std::copy
template
void dump_to_file(const char* filename, const std::vector& v_d){
std::ofstream ofs(filename);
if(!ofs){
std::cerr<<"Unable to open the file to write!n";
return ;... 阅读全帖

发帖数: 1
49
来自主题: Military版 - 12 月26日 可能的真相
【Filariasis
From Wikipedia, the free encyclopedia
Filariasis
Life cycle of Wuchereria bancrofti, a parasite that causes filariasis
Classification and external resources
Specialty Infectious disease
ICD-10 B74
ICD-9-CM 125.0-125.9
Patient UK Filariasis
MeSH D005368
[edit on Wikidata]
Filariasis is a parasitic disease caused by an infection with roundworms of
the Filarioidea type.[1] These are spread by blood-feeding black flies and
mosquitoes. This disease belongs to the group of d... 阅读全帖

发帖数: 1
50
来自主题: Military版 - 中美进入你死我活新时代
12月27日 为什么我要替中国辩护
我要替中国辩护,并不是因为我是一个中国人,而是因为我知道中国就和这世界上绝大
数的国家一样,虽然有很多丑陋的现象,但是他们是受害者。就
象这个犯罪集团里很多的人一样,他们来自各种种族,他们可能充当了工具,但他们不
是制造这一切,谋划这一切的人。虽然经常会暴露中国产品出现问题。但要知道中国是
世界工厂,他们只是打工者,他们只是按照各种雇主提供的配方来生产,他们并不知道
他们会产生怎样的后果。或者这些工人知道后果,但他们只是奴隶,他们又如何去改变
这一切? 所以,当我的调查不断往前推进的时候,不可避免地会涉及各国的企业,但
这并不表明是针对这个国家或这个国家的人民,而是针对一种社会现实和丑陋现象。就
拿菲律宾来说,菲律宾是一个犯罪猖獗的国家,有很多犯罪分子,但是菲律宾人民却是
这个集团的受害者,他们/她们被绑架,沦为了牺牲品,人体实验对象。一个日本人,
强奸上千名菲律宾女孩,却没有受到惩罚。以前我也提到过,有20个国家的名单,这20
个国家的人民其实都是受害者。现在他们把矛头对准中国,或许仅仅是因为我揭示了他
们图害世界人民的内幕,而我是一个中国人的缘... 阅读全帖
首页 上页 1 2 3 4 5 6 7 8 9 10 (共10页)