2015年阿里巴巴实习生招生在线笔试部分试题
2015-04-07 15:16
197 查看
1.
假设an表示利用这两种图形填充的方案数。
a7=a6+a5+2(a4+a3+a2+a1+1)
a6=a5+a4+2(a3+a2+a1+1)
a5=a4+a3+2(a2+a1+1)
a4=a3+a2+2(a1+1)
a3=a2+a1+2*1
a2=2
a1=1
a2=2
a3=2+1+2=5
a4=5+2+4=11
a5=11+5+8=24
a6=24+11+18=53
a7=53+24+40=117
2.
答案是7,7-4-5-3-4-3-3-2-7-7.
3.
#include <iostream>
using namespace std;
double findkth(double A[], int m, double B[], int n, int k)
{
if (m > n)
return findkth(B, n, A, m, k);
if (m == 0)
return B[k-1];
if (k == 1)
return min(A[0], B[0]);
int pa = min(k/2, m);
int pb = k - pa;
if (A[pa-1] < B[pb-1])
return findkth(A+pa, m-pa, B, n, k-pa);
else if (A[pa-1] > B[pb-1])
return findkth(A, m, B+pb, n-pb, k-pb);
else
return A[pa-1];
}
int min(int x, int y)
{
return x > y ? y : x;
}
double findMedianSortedArrays(double A[], int m, double B[], int n) {
int total = m + n;
if (total & 0x1)
return findkth(A, m, B, n, total/2+1);
else
return (findkth(A, m, B, n, total/2) + findkth(A, m, B, n, total/2+1 ))/2;
}
int main()
{
double A[] = {1,2,4,6,7};
double B[] = {-1,3,5,8};
cout<<findMedianSortedArrays(A,5,B,4)<<endl;
system("pause");
return 0;
}
4.
#include <iostream>
using namespace std;
int Volumn(int Height[],int m)
{
int i = 0;
int j = m-1;
int volumn = 0;
while(i<j)
{
if(Height[i]<=Height[j])
{
int temp = 1;
while(Height[i+temp]<Height[i]&&(i+temp)<=j)
{
volumn += Height[i] - Height[i+temp];
temp++;
}
i+=temp;
}
else
{
int temp = 1;
while(Height[j-temp]<Height[j]&&(j-temp)>=i)
{
volumn += Height[j] - Height[j-temp];
temp++;
}
j-=temp;
}
}
return volumn;
}
int main()
{
int A[]={3,1,0,3,1,0,1,3,2,1,3,1,3};
int m = 13;
cout<<Volumn(A,m)<<endl;
system("pause");
return 0;
}
假设an表示利用这两种图形填充的方案数。
a7=a6+a5+2(a4+a3+a2+a1+1)
a6=a5+a4+2(a3+a2+a1+1)
a5=a4+a3+2(a2+a1+1)
a4=a3+a2+2(a1+1)
a3=a2+a1+2*1
a2=2
a1=1
a2=2
a3=2+1+2=5
a4=5+2+4=11
a5=11+5+8=24
a6=24+11+18=53
a7=53+24+40=117
2.
答案是7,7-4-5-3-4-3-3-2-7-7.
3.
#include <iostream>
using namespace std;
double findkth(double A[], int m, double B[], int n, int k)
{
if (m > n)
return findkth(B, n, A, m, k);
if (m == 0)
return B[k-1];
if (k == 1)
return min(A[0], B[0]);
int pa = min(k/2, m);
int pb = k - pa;
if (A[pa-1] < B[pb-1])
return findkth(A+pa, m-pa, B, n, k-pa);
else if (A[pa-1] > B[pb-1])
return findkth(A, m, B+pb, n-pb, k-pb);
else
return A[pa-1];
}
int min(int x, int y)
{
return x > y ? y : x;
}
double findMedianSortedArrays(double A[], int m, double B[], int n) {
int total = m + n;
if (total & 0x1)
return findkth(A, m, B, n, total/2+1);
else
return (findkth(A, m, B, n, total/2) + findkth(A, m, B, n, total/2+1 ))/2;
}
int main()
{
double A[] = {1,2,4,6,7};
double B[] = {-1,3,5,8};
cout<<findMedianSortedArrays(A,5,B,4)<<endl;
system("pause");
return 0;
}
4.
#include <iostream>
using namespace std;
int Volumn(int Height[],int m)
{
int i = 0;
int j = m-1;
int volumn = 0;
while(i<j)
{
if(Height[i]<=Height[j])
{
int temp = 1;
while(Height[i+temp]<Height[i]&&(i+temp)<=j)
{
volumn += Height[i] - Height[i+temp];
temp++;
}
i+=temp;
}
else
{
int temp = 1;
while(Height[j-temp]<Height[j]&&(j-temp)>=i)
{
volumn += Height[j] - Height[j-temp];
temp++;
}
j-=temp;
}
}
return volumn;
}
int main()
{
int A[]={3,1,0,3,1,0,1,3,2,1,3,1,3};
int m = 13;
cout<<Volumn(A,m)<<endl;
system("pause");
return 0;
}
相关文章推荐
- 2015年秋季阿里巴巴在线笔试——Java研发师——部分试题分析
- 2015年阿里巴巴实习生招聘在线笔试题
- 2016阿里巴巴实习生在线笔试
- 2015年阿里巴巴校园招聘研发岗在线笔试题(超全)
- 2014阿里巴巴WEB前端实习生在线笔试题
- 2015阿里巴巴前端实习生在线笔试题
- 2014阿里巴巴WEB前端实习生在线笔试题
- 2015年阿里巴巴实习生招聘笔试题详细解析(研发大类:Java研发/C++研发)
- 2014阿里巴巴WEB前端实习生在线笔试题
- 阿里巴巴2015年秋季在线笔试附加题---树求最大差值
- 360公司2015年秋季校园招聘笔试考卷(技术类 D)部分试题程序验证和解析1
- 阿里,20150402春季实习生招聘在线试题(单选部分+附加题)
- 360公司2015年秋季校园招聘笔试考卷(技术类 D)部分试题程序验证和解析2
- 360公司2015年秋季校园招聘笔试考卷(技术类 D)部分试题程序验证和解析3
- 2014阿里巴巴WEB前端实习生在线笔试题
- 360公司2015年秋季校园招聘笔试考卷(技术类 D)部分试题程序验证和解析4
- 2016年tencent实习生笔试部分试题分析
- 2013-5-5阿里巴巴实习生部分笔试题-武汉
- 阿里巴巴2015实习生在线笔试题
- 360公司2015年秋季校园招聘笔试考卷(技术类 D)部分试题程序验证和解析5