小米编程题,树的高度一直是只通过10%
今天考试第一个编程题如下:
题目不算难,暴力思路,用vector存储每条路径,包括新的旧的,计算所有路径中最大值。代码如下:
int main()
{
int n;
while(cin>>n)
{
if(n<=1)//0 1
{
cout<<n<<endl;
break;
}
int res=0;
vector<vector<int> > v;//store all path
int a,b;//father and son
n--;
while(n--)
{
cin>>a>>b;
if(a==0)//root
{
vector<int> t;
t.push_back(a);
t.push_back(b);
v.push_back(t);
res=2;
continue;
}
for(int i=0;i<v.size();i++)
{
if(*v[i].rbegin()==a)
{
vector<int> t=v[i];
t.push_back(b);
v.push_back(t);
int tlen=t.size();
res=max(res,tlen);
break;
}
}
}
cout<<res<<endl;
}
return 0;
}
/*
5
0 1
0 2
1 3
1 4
*/
为什么都这么暴力了却只过10%,哪个答案错了呢?难道还不够暴力?
吐槽一下赛码
编程题做不下去了,想做问答,又怕不能回来修改,所以就问客服
客服说可以
然后我高兴的提交了
然后就懵逼了
查看8道真题和解析