由买买提看人间百态

topics

全部话题 - 话题: vec
1 2 3 4 下页 末页 (共4页)
x*******9
发帖数: 138
1
来自主题: 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... 阅读全帖
b****e
发帖数: 45
2
来自主题: JobHunting版 - 两道google的题
多谢!确实是个很低级的错误...
不过我觉得这个办法修改一下还是可行的。按照你的提醒,更新的思路如下:
1. 对每一个值,都判断是否大于first并且小于second, 如果是则更新second为当前值;
2. 用一个新的min_val变量记录当前为止遇到的最小值,遇到increased pair时,如果
不能返回结果,则更新first使其为min_val, 并继续扫描。
更新后的代码如下,请指正~
vector FindIncreasingNum(vector vec) {
if (vec.size() < 3)
return vector();
int first = INT_MAX;
int second = INT_MAX;
int min_val = vec[0];
for (int i = 1; i < vec.size(); i++) {
if (vec[i] > vec[i - 1]) {
if (vec[i] > second) {
... 阅读全帖
w****x
发帖数: 2483
3
来自主题: JobHunting版 - twitter intern面经
/*
Given tweet's inverted index,how to find phrases combination,e.g
phrase "twitter good tool", "twitter is a good tool" is better than "twitter
is good,
facebook is a better tool"
*/
bool GetClosestPhrase(hash_map>& dic, vector& strs,
int& nStart, int& nEnd)
{
for (vector::iterator it = strs.begin(); it != strs.end(); it++)
{
if (dic.find(*it) == dic.end())
return false;
}
int nNum = strs.size();
vector*> vec;
ve... 阅读全帖
w****x
发帖数: 2483
4
来自主题: JobHunting版 - twitter intern面经
/*
Given tweet's inverted index,how to find phrases combination,e.g
phrase "twitter good tool", "twitter is a good tool" is better than "twitter
is good,
facebook is a better tool"
*/
bool GetClosestPhrase(hash_map>& dic, vector& strs,
int& nStart, int& nEnd)
{
for (vector::iterator it = strs.begin(); it != strs.end(); it++)
{
if (dic.find(*it) == dic.end())
return false;
}
int nNum = strs.size();
vector*> vec;
ve... 阅读全帖
s****e
发帖数: 638
5
来自主题: JobHunting版 - G新鲜面经
1.2 暴力加剪枝
vector used;
void transform(vector A, vector& vec){
int i=vec.size()-1;
if (i>0) {
if (( i&1 && vec[i] < vec[i-1]) ||
(!(i&1) && vec[i] > vec[i-1])) return;
}
if (vec.size()==A.size()) {
for(int i = 0 ; i < vec.size() ; ++i) cout< cout< return;
}
for(int i = 0 ; i < A.size() ; ++i) {
if (!used[i]) {
used[i] = true;
vec.push_back(A[i]);
transform(A, vec);
vec.pop_back();
used[i] = fa... 阅读全帖
h****y
发帖数: 137
6
来自主题: JobHunting版 - A家面经
double find_kth_largest_unknown_length(istringstream &sin, int k)
{
vector vec;
double x;
while (sin >> x)
{
vec.emplace_back(x);
if (vec.size() == (k << 1) - 1)
{
nth_element(vec.begin(), vec.begin() + k - 1, vec.end(), greater
());
vec.resize(k);
}
}
nth_element(vec.begin(), vec.begin()+k-1, vec.end(), greater());
return vec[k-1];
}
h****y
发帖数: 137
7
来自主题: JobHunting版 - A家面经
double find_kth_largest_unknown_length(istringstream &sin, int k)
{
vector vec;
double x;
while (sin >> x)
{
vec.emplace_back(x);
if (vec.size() == (k << 1) - 1)
{
nth_element(vec.begin(), vec.begin() + k - 1, vec.end(), greater
());
vec.resize(k);
}
}
nth_element(vec.begin(), vec.begin()+k-1, vec.end(), greater());
return vec[k-1];
}
f*******d
发帖数: 339
8
一般说来,如果总电荷不为零,通过选择坐标有可能使有限系统的电偶极矩为零, 因为
\vec p = \int \vec x \rho(x)
如果不为零, 可以取
\vec x' = \vec x - \vec x0
\vec p' = \int \vec x \rho (x) - \vec x0 \int rho (x)
所以只要选
\vec x0 = (\int rho(x) \vec x)/\int \rho(x) = (\int rho(x) \vec x) / Q_tot
就足以令电偶极矩为零。这里的条件是总电荷不为零, 如果总电荷为零就没有办法了。
电四极矩有五个独立分量,独立的坐标变换有六个(三个平移三个旋转), 因此也可以
选座标
使之为零, 具体公式我就不写了,总之是写出其变换方程,然后求解。
但是不能同时使电偶极距为零。 如果总电荷和电偶极矩都恰为零, 那么上述平移变换不
起作用,
也无法使电四极矩为零。 总之, 最低一级不为零的多极矩是与坐标无关的,不可能消去
s******e
发帖数: 108
9
来自主题: JobHunting版 - 攒人品,twitter二面面经
可以用 hashset 来替代 vector ,
public class RandomHash {
HashMap > hashmap = new HashMap LinkedHashSet>();
Vector vec = new Vector();
public void insert(K key) {
vec.add(key);
if( ! hashmap.containsKey(key) ) {
LinkedHashSet hashSet = new
LinkedHashSet();
hashSet.add(new Integer(vec.size()-1));
hashmap.put(key,hashSet);
} else {
h... 阅读全帖
g*****x
发帖数: 799
10
来自主题: JobHunting版 - 问一个算法题
void rangeBinarySearch(const vector &vec, const int val, int &range_beg
, int &range_end)
{
range_beg = -1;
range_end = -1;
int beg = 0;
int end = vec.size();
int mid;
while(beg < end)
{
mid = (end - beg) / 2 + beg;
if(vec[mid] == val && (mid == 0 || vec[mid - 1] < val))
{
range_beg = mid;
break;
}
if(vec[mid] >= val)
end = mid;
else
beg = mid + 1;
}
if(range_b... 阅读全帖
S******0
发帖数: 71
11
来自主题: JobHunting版 - 比较久之前T家的面试
改成BFS了
//each time can jump up or down 2^k steps, find fewest jumping step,
//always start from the first step
vector getJumpSteps(int nCur, int nMaxStep)
{
vector vec;
if (nCur <= 0 || nMaxStep < nCur)
return vec;
int flg = 1;
while (nCur + flg <= nMaxStep)
{
vec.push_back(nCur + flg);
flg = (flg << 1);
}
flg = 1;
while (nCur - flg > 0)
{
vec.push_back(nCur - flg);
flg = (flg << 1);
}
return vec;
}
int... 阅读全帖
r*c
发帖数: 167
12
//矩阵求连接图
#include
#include
#include
#include
#include
using namespace std;
enum ColorEnum{White, Black};
struct Cell
{
int row;
int col;
Cell(int r, int c): row(r), col(c){}
};
struct Cluster{
bool visited;
vector vec;
Cluster(int i, int j) : visited(false) {
vec.push_back(Cell( i, j));
}
bool isWithinRange(const Cell& a, const Cell& b){
return abs(a.row - b.row) <= 1 ... 阅读全帖
r*c
发帖数: 167
13
//矩阵求连接图
#include
#include
#include
#include
#include
using namespace std;
enum ColorEnum{White, Black};
struct Cell
{
int row;
int col;
Cell(int r, int c): row(r), col(c){}
};
struct Cluster{
bool visited;
vector vec;
Cluster(int i, int j) : visited(false) {
vec.push_back(Cell( i, j));
}
bool isWithinRange(const Cell& a, const Cell& b){
return abs(a.row - b.row) <= 1 ... 阅读全帖
b*******t
发帖数: 459
14
来自主题: Programming版 - C++编程问题:union inside struct
比如我要定义一个class叫做vec(向量),它有三个变量和一堆函数:
class vec {
public:
double x,y,z;
public:
vec(){};
~vec() {};
...
}
现在我希望定义某种union结构能让我也能用vec.xa[0],vec.xa[1],vec.xa[2]
来访问vec.x, vec.y, vec.z,如何能够实现呢?谢谢。。。
s******e
发帖数: 108
15
来自主题: JobHunting版 - 攒人品,twitter二面面经
public class RandomHash {
HashMap hashmap = new HashMap();
Vector vec = new Vector();
public void insert(K key) {
vec.add(key);
hashmap.put(key, new Integer(vec.size()-1));
}
public K getRand() {
if(vec.size()<=0)
return null;
Random randomGenerator = new Random();
int rndnum = randomGenerator.nextInt(vec.size());
return vec.get(rndnum);
}
public boole... 阅读全帖
l*****a
发帖数: 14598
16
来自主题: JobHunting版 - 问道amazon面试题
void GetPath(int size, int x,int y,vector& vec)
{
if(x==size&&y==size)
{ vector::iterator it;
for(it=vec.begin();it!=vec.end();++it) { cout<<*it; }
cout< return;
}
if(x vec.push_back('R');
GetPath(size,x+1,y,vec);
vec.pop_back();
}
if(y vec.push_back('D');
GetPath(size,x,y+1,vec);
vec.pop_back();
}
return;
}
w****x
发帖数: 2483
17
迭代法:
//Find the nth number which is composed by factor 2, 3 and 5
void PrintSerials(int n)
{
assert(n > 0);
vector vec;
vec.push_back(1);
int nI2 = 0;
int nI3 = 0;
int nI5 = 0;
int nCount = 1;
while(nCount < n)
{
int nTmp2 = vec[nI2]*2;
int nTmp3 = vec[nI3]*3;
int nTmp5 = vec[nI5]*5;
int nMin = min(min(nTmp2, nTmp3), nTmp5);
if (vec.back() != nMin)
{
vec.push_back(nMin);
nCount++;
... 阅读全帖
p*****3
发帖数: 488
18
const int N = 100;
void printWays(int dp[N][N], int i, int j, vector& vec)
{
if (i < 0 || j < 0 || dp[i][j] <= 0)
return;
if (j == 0)
{
for (vector::iterator it = vec.begin(); it != vec.end(); it++)
cout<<*it<<" ";
cout< return;
}
vec.push_back(i);
printWays(dp, i, j-i, vec);
vec.pop_back();
printWays(dp, i-1, j, vec);
}
int getUniqueWays(int n)
{
if (n <= 0)
return 0;
int dp[N][N] = { 0 }... 阅读全帖
m**q
发帖数: 189
19
来自主题: JobHunting版 - 几道老题 的解答
同样,当检查一个新的点时,需要把x-h之前的点从map中去掉,
其实可以用一个map存[x-h,x]中的点,key是y坐标。在向map中
添加一个新的点时,先检查map里是否有y坐标相同的点,有则删除;
同时把x-h之前的点依据它们的y坐标,把它们从map中删除。
总复杂度不超过O(nlgn)。
#include
#include
#include
#include
#include
using namespace std;
#define REVESE_PAIR(x) (make_pair(x.second, x.first))
#define PAIR(x) (make_pair(x.first, x.second))
double dist(pair a, pair b)
{
int x = abs(b.first - a.first);
int y = abs(b.second - a.second);
doubl... 阅读全帖
x*******5
发帖数: 152
20
来自主题: JobHunting版 - Subset of size m Problem
谢谢大牛指导,但是好像C++的还是不work
void Pearl::GetSubset(vector& array, int target,int start,vector&
vec){
if (vec.size()==target){

Pearl::Print(vec);
return;
}
if (start==array.size()) return;
for (int i=start;i vec.push_back(array[i]);
GetSubset(array,target,start+1,vec);
vec.pop_back();
}
return;
}
测试:
int a[]={1,2,3};
vector v(a,a+3);
vector vec;
Pearl::GetSubset(v,2,0,vec);
Outp... 阅读全帖
w****x
发帖数: 2483
21
来自主题: JobHunting版 - 被gray code打击了
做了无数recursion的题后花了两小时才整出gray code解, 大家鄙视我吧, 哈哈哈:
/*
The gray code is a binary numeral system where two successive values differ
in only one bit.
Given a non-negative integer n representing the total number of bits in the
code, print the sequence of gray code. A gray code sequence must begin with
0.
For example, given n = 2, return [0,1,3,2]. Its gray code sequence is:
00 - 0
01 - 1
11 - 3
10 - 2
*/
void _inner_sol(int& nCur, vector& vec, int nStopPos, int nPos)
{
if (nPos < 0)
{
... 阅读全帖
b****e
发帖数: 45
22
来自主题: JobHunting版 - 两道google的题
刚写了个第一题的代码:
vector FindIncreasingNum(vector vec) {
int first = INT_MAX;
int second = INT_MAX;
for (int i = 1; i < vec.size(); i++) {
if (vec[i] > vec[i - 1]) {
if (vec[i] > second) {
vector res;
res.push_back(first);
res.push_back(second);
res.push_back(vec[i]);
return res;
}
else {
first = vec[i - 1];
second = vec[... 阅读全帖
w****x
发帖数: 2483
23
来自主题: JobHunting版 - g 两轮店面面经 失败告终
那个烙印这些题根本就是想灭你嘛, 楼主不要自责。
中国人最后那题可能是要这个解法:
void inner_get_rightmost(NODE* pNode, vector& vec, int nLev)
{
if (NULL == pNode)
return;
if (nLev >= vec.size())
vec.push_back(pNode);
inner_get_rightmost(pNode->pRgt, vec, nLev+1);
inner_get_rightmost(pNode->pLft, vec, nLev+1);
}
vector getRightMost(NODE* pRoot)
{
vector vec;
inner_get_rightmost(pRoot, vec, 0);
return vec;
}
w****x
发帖数: 2483
24
来自主题: JobHunting版 - 比较久之前T家的面试
vector getJumpSteps(int nCur, int nMaxStep)
{
vector vec;
if (nCur <= 0 || nMaxStep < nCur)
return vec;
int flg = 1;
while (nCur + flg <= nMaxStep)
{
vec.push_back(nCur + flg);
flg = (flg << 1);
}
flg = 1;
while (nCur - flg > 0)
{
vec.push_back(nCur - flg);
flg = (flg << 1);
}
return vec;
}
int getMinStep(int n, int nMaxStep)
{
if (n <= 0 || nMaxStep < n)
return -1;
int* rec = new int[nM... 阅读全帖
d**********x
发帖数: 4083
25
来自主题: JobHunting版 - 比较久之前T家的面试
应该没问题,和coldknight的程序在2-10000之内做了对比,结果完全一致。他的
nMaxStep我设置为了2 * target,不知道会不会引起问题。
在纸面上也做了不太严格的证明。。这样复杂度就是O(logn)。
对比程序:(前半部分还是coldknight的)
#include
#include
#include
using namespace std;
vector getJumpSteps(int nCur, int nMaxStep)
{
vector vec;
if (nCur <= 0 || nMaxStep < nCur)
return vec;
int flg = 1;
while (nCur + flg <= nMaxStep)
{
vec.push_back(nCur + flg);
flg = (flg << 1);
}
flg = 1;
while (nCur - ... 阅读全帖
l**n
发帖数: 67
26
来自主题: Science版 - 高手们再帮我一把
I am confused here and don't know you are asking or answering.
Doesnot distinguish partial deriv. and deriv. is very bad notation.
But just to remind you, you are dealing with a field equation
here.(mass conservation) Whenever you want to use the field equation,
all the variables should be expressed in terms of field variables
which are coordinates \vec{x} and time. So
\rho=\rho(\vec{x},t)
\vec{u}=\vec{u}(\vec{x},t)
\vec{a}=\vec{a}(\vec{x},t)
and you have the \partial\rho/\partial t + div(\rho u
f*********5
发帖数: 576
27
void GetPath(node * root, vector&vec,int target)
{
if(!root) return;
if(vec.size()>0)
{ sum=0;
for(int i=vec.size()-1;i>=0;i--)
{ sum+=vec[i];
if(sum==target) { PRINT;break;}
}
}
vec.push_back(root->data);
if (root->left) GetPath(root->left,vec,target);
if (root->right) GetPath(root->right,vec,target);
return;
}

level
Design an
w****x
发帖数: 2483
28
来自主题: JobHunting版 - 几道F家面试题
struct NODE
{
int nVal;
NODE* pLft;
NODE* pRgt;
NODE(int x) : nVal(x), pLft(NULL), pRgt(NULL) {}
};
struct TreeIter
{
stack m_stk;
void movNext()
{
if (m_stk.empty())
return;
NODE* pCur = m_stk.top();
if (pCur->pRgt != NULL)
{
pushLft(pCur->pRgt);
return;
}

while (!m_stk.empty() && pCur != m_stk.top()->pLft)
{
pCur = m_stk.top();
m_stk.pop... 阅读全帖
M*****M
发帖数: 20
29
来自主题: JobHunting版 - 一道面试题
类似找最大BST subtree, bottom up.
bool findsubtree(TreeNode *node, unordered_set &set, vector
&vec) {
if(not node) {
return true;
}
unordered_set leftset;
unordered_set rightset;
bool left = findsubtree(node->left, leftset, vec);
bool right = findsubtree(node->right, rightset, vec);
if(left&&right) {
//leftset and rightset overlap
for(auto ele:leftset) {
if(rightset.find(ele)!=rightset.end()) {
... 阅读全帖
x*******9
发帖数: 138
30
来自主题: JobHunting版 - Google onsite一题

should
5
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define print(x) cout << x << endl
#define input(x) cin >> x
string make_result(const vector& vec, int idx) {
string res = "";
int len = vec.size();
for (int i = 0; i < idx; i++) {
res += to_string(vec[i]);
}
res += "(";
for (int i = idx; i < len; i++) {
... 阅读全帖
x******a
发帖数: 6336
31
来自主题: Programming版 - 请教C++11
在visual studio express 2012里为什么compile不过去?
#include
#include
#include
#include
int main()
{
std::vector vec{3, 4, 2, 9, 15, 267};
for(auto& elem:vec) elem*=3;
std::ostream_iterator out_it(std::cout, ", ");
std::copy(vec.begin(), vec.end(), out_it);
return 0;
}
Error 1 error C2601: 'vec' : local function definitions are illegal
c:users。。documentscodetest11test11main.cpp 8 1 test11
Error 2 error C2143: synt... 阅读全帖
s***e
发帖数: 911
32
来自主题: Science版 - 高手们再帮我一把

In my derivation, all the quantities
are field quantities which must be functions of the space coordinates and the
time. What we need to do now is to express the speed field q(\vec{x},t) by
\vec{x}(\vec{a},t).
In your picture, \vec{x}(\vec{a},t) should be the so-called streamline. A
given \vec{a} correspods to a steamline, and all the possible
\vec{a} give the field. We know that there is no intersecting streamlines
in the field, so a space coordinate only belongs to a streamline.
Then we have
f*********5
发帖数: 576
33
//assume that a[]={1,5,10,25} already sorted
void GetCombination(int a[],int size,int target,vector& vec)
{
if(target==0) {cout<< < if(target<=0) return;
for(int i=0,i {
if(vec.size()>0)
{
if(a[i] }
if (a[i]>target) break;
vec.push_back(a[i]);
GetCombination(a,size,target-a[i],vec);
vec.pop_back();
}
return;
}
x***y
发帖数: 633
34
another way to use backtracking
//find all the commbination
typedef vector::size_type VecIndex;
void find_all_comb ( unsigned target, vector & vec, vector >& eleCount, VecIndex vIndex){
//vec is assumed sorted
if(vIndex==vec.size())
return ;
unsigned mul = target/vec[vIndex];
eleCount[vIndex] = mul;
if(!(target%vec[vIndex])){

for(VecIndex vi=0; vi for(VecIndex vc=0; vc cout<< vec[vi] <<
w****x
发帖数: 2483
35
来自主题: JobHunting版 - 刚才重新回顾了一下那题
struct NODE
{
vector vecGUID;
NODE* nodes[256];

NODE() { memset(nodes, 0, sizeof(nodes)); }
};
void _inner_get_guid(NODE* pNode, const char* str, int k, vector& vec)
{
if (NULL == pNode)
return;
if (k <= 0)
{
vec = pNode->vecGUID;
return;
}
_inner_get_guid(pNode->nodes[*str], str+1, k-1, vec);
}
vector getGUID(const char* str, NODE* pRoot, int k)
{
vector vecRet;
if (NULL == pRoot || NULL == str || *str == 0 ... 阅读全帖
w****x
发帖数: 2483
36
来自主题: JobHunting版 - 几道F家面试题
//serialize, deserialize vector
int serialize(vector& vec, char* str)
{
if (str == NULL)
return 0;
char* pWriter = str;
*((int*)pWriter) = vec.size();
pWriter += sizeof(int);
for (int i = 0; i < vec.size(); i++)
{
strcpy(pWriter, vec[i].c_str());
pWriter += 1 + strlen(pWriter);
}
return pWriter - str;
}
void deserialize(char* str, vector& vec)
{
if (NULL == str)
return;
int nSize = *((int*)str);
c... 阅读全帖
d**********x
发帖数: 4083
37
实际上是O(logn)的空间,但是既然长度为2^32的数列可以借助一个int来作为辅助空间
,这点overhead基本可以忽略不计了。欢迎找bug:
#include
#include
#include
using namespace std;
#include
static int get_index(int i) {
if (i == 0) {
return 1;
}
return (1 << i) + 1;
}
void rearrange(vector& vec) {
int bitmap = 0; //"O(1)" space for length < (1 << 32)
int k = vec.size() / 2;
int n = vec.size();
for (int i = 0; get_index(i) < k; ++i) {
int cur = get_index(i);
... 阅读全帖
p*****2
发帖数: 21240
38
(defn f [vec]
(defn- dfs [vec start p len]
(let [next (nth vec p)]
(if (= next start)
(inc len)
(dfs vec start next (inc len)))))
(apply max (for [i (range 0 (count vec))]
(dfs vec i i 0))))
p*****2
发帖数: 21240
39
(defn f [vec]
(defn- dfs [vec start p len]
(let [next (nth vec p)]
(if (= next start)
(inc len)
(dfs vec start next (inc len)))))
(apply max (for [i (range 0 (count vec))]
(dfs vec i i 0))))
G****A
发帖数: 4160
40
来自主题: JobHunting版 - 一道面试题
void increment(vector& vec)
{
int pos = vec.size() - 1;
uint carry = 1;

do{
if (pos < 0)
vec.insert(vec.begin(), 1);
else{
int sum = vec[pos] + carry;
vec[pos] = sum % 10;
carry = sum / 10;
pos--;
}
} while(carry);
}

that
c**********x
发帖数: 32
41
int getArithSeq(vector & vec){
if (vec.size() < 3)
return 0;
int start = 0, i=2, ret=0;
for (; i < vec.size(); ++i){
if (vec[i - 1] * 2 == vec[i] + vec[i - 2]){
if (start == 0)
start = i - 2;
}
else{
ret += cal(start, i-1);
start = 0;
}
}
if (start != 0)
ret += cal(start, i - 1);
return ret;
}
x*******9
发帖数: 138
42
来自主题: JobHunting版 - google onsite的套盒子题目
SPOJ MDOLLS
4A(有点蠢
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define print(x) cout << x << endl
#define input(x) cin >> x
int n;
vector > vec;
int main() {
int T;
int a, b;
input(T);
while (T--) {
input(n);
vec.clear();
multiset st;
for (int i = 0; i < n; i++) {
input(a >> b);
vec.push_back({a, b})... 阅读全帖
D**u
发帖数: 204
43
Here is a solution by using vector calculations.
Let a = |BC|, c = |AB|, then easy to calculate that:
(1) |AM|^2 = |MB|^2 + |AB|^2 = a^2 -2ac + 2c^2
(2) |CN|^2 = |CB|^2 + \NB|^2 = 2a^2 - 4ac + 4c^2.
We also have
vec(MA)\cdot vec(CN) = (vec(BM)-vec(BA))\cdot (vec(BC)-vec(BN))
= a^2 - 2ac + 2c^2 = cos(pi/4) * |AM| * |CN|.
so 角MPC=45度
X***9
发帖数: 7385
44
来自主题: Automobile版 - 欣赏一下小X的姿势水平

哦?你很了解 动量守恒定律?动量定理?和其区别?关系?
根据wiki解释
动量具有一个特殊属性:只要是在一个封闭系统中,它总会保持恒定,即使是物体碰撞
发生时。而对动能而言,非弹性碰撞的物体的动能将不会守恒。因此,当碰撞过后可利
用动量守恒来计算未知速度。
在物理学上,这个特殊属性被用来来解决两个相碰物体的问题。因为动量始终保持恒定
,碰撞前动量的总和一定与碰撞后动量的总和相等:
m_1 vec{v}_{1,i} + m_2 vec{v}_{2,i} = m_1 vec{v}_{1,f} + m_2 vec{v}_
{2,f},
其中,i表示碰撞前的初量,f表示碰撞后的末量。要注意的是此時vec{v}為向量。
通常来说,我们只需知道碰撞前(或碰撞后)物体的速度便可计算出碰撞后(或碰撞前
)物体的速度。要正确解决这个问题意味着你必须知道将会发生怎样的碰撞。碰撞有两
种类型,两种类型中动量都保持恒定:
大哥
飞鸟撞飞机是非弹性碰撞
你不能否定非弹性碰撞和动量守恒的关系。
D***h
发帖数: 183
45
来自主题: JobHunting版 - Amazon onsite面试的惨痛经历
how about this. I test it seems ok.
#include
#include
using namespace std;
void num2alpha(int n){
vector vec;
vector::reverse_iterator it;
int i=n;
if(n==0)
vec.push_back('a');
else{
while(i>0){
vec.push_back('a'+n%26);
i=n/26;
n = n/26 -1;

}
}
for(it=vec.rbegin();it!=vec.rend();it++)
cout<<*it;
cout<
}
l*****a
发帖数: 14598
46
来自主题: JobHunting版 - 贡献两道的面试题
void GetCombination(int a[],int size,int start,vector &vec)
{
for(int i=start;i<=size-1;i++)
{
if((i!=start)&&(a[i]==a[i-1])) continue;
vec.push_back(a[i]);
PrintCombination(vec);
if(i vec.pop_back();
}
}
l*****a
发帖数: 14598
47
来自主题: JobHunting版 - 贡献两道的面试题
void GetCombination(int a[],int size,int start,vector &vec)
{
for(int i=start;i<=size-1;i++)
{
if((i!=start)&&(a[i]==a[i-1])) continue;
vec.push_back(a[i]);
PrintCombination(vec);
if(i vec.pop_back();
}
}
l*****a
发帖数: 14598
48
来自主题: JobHunting版 - Subset of size m Problem
void GetSubset(T array[],size_t size,int start,size_t target,vector&vec)
{
if (vec.size()==target) {PRINT; return;}
if(start ==size) return;
for(int i=start;i {
vec.push_back(array[i]);
GetSubset(array,size,i+1,target,vec);
vec.pop_back();
}
return;
}
w****x
发帖数: 2483
49
来自主题: JobHunting版 - 发几个面试题
/*
Serialize/DeSerialize a tree
*/
struct NODE
{
int nVal;
vector vec;
NODE(int n) : nVal(n) {}
};
void _inner_serial(NODE* pNode, char*& p)
{
if (NULL == pNode)
return;
*p++ = pNode->vec.size();
*p++ = pNode->nVal;
for (vector::iterator it = pNode->vec.begin();
it != pNode->vec.end(); it++)
_inner_serial(*it, p);
}
const char* Serialize(NODE* pRoot, char mem[])
{
if (NULL == mem || NULL == pRoot)
return NULL;
char... 阅读全帖
w****x
发帖数: 2483
50
来自主题: JobHunting版 - F家面经
//Get all trees according to preorder
struct NODE
{
int nVal;
NODE* pLft;
NODE* pRgt;
NODE(int n) : nVal(n), pLft(NULL), pRgt(NULL) {}
};
void GetComb(int a[], int n, vector& vec)
{
if (n <= 0)
return ;
if (n == 1)
{
vec.push_back(new NODE(a[0]));
return;
}
vector vecTmp1;
GetComb(a+1, n-1, vecTmp1);
for (vector::iterator it = vecTmp1.begin();
it != vecTmp1.end(); it++)
{
NODE* pRoot = ne... 阅读全帖
1 2 3 4 下页 末页 (共4页)