http://company.dajie.com/huawei/job/shhf/topic/206711/detail
传送门:http://company.dajie.com/huawei/job/shhf/topic/206711/detail
需进行上机考试的岗位:软件开发工程师、操作系统工程师、底层软件开发工程师、云计算开发工程师、DSP工程师
在线考试:机考系统的内核为VS2005及JDK1.7,使用Java答题时,类名必须为“Main”;使用C/C++答题时,使用VS2005支持的数据类型和函数。题目类型:涉及数组、链表、指针、字符串、循环、枚举、排序等等。考试时长:2小时考试题目:3道题(共计320分),初级题(60分),中级题(100),高级题(160分),难度递增。 各难度上机考试样题 初级题:从考试成绩中划出及格线 10个学生考完期末考试评卷完成后,A老师需要划出及格线,要求如下:(1) 及格线是10的倍数;(2) 保证至少有60%的学生及格;(3) 如果所有的学生都高于60分,则及格线为60分 中级题:亮着电灯的盏数 一条长廊里依次装有n(1 ≤ n ≤ 65535)盏电灯,从头到尾编号1、2、3、…n-1、n。每盏电灯由一个拉线开关控制。开始,电灯全部关着。有n个学生从长廊穿过。第一个学生把号码凡是1的倍数的电灯的开关拉一下;接着第二个学生把号码凡是2的倍数的电灯的开关拉一下;接着第三个学生把号码凡是3的倍数的电灯的开关拉一下;如此继续下去,最后第n个学生把号码凡是n的倍数的电灯的开关拉一下。n个学生按此规定走完后,长廊里电灯有几盏亮着。注:电灯数和学生数一致。 高级题:地铁换乘已知2条地铁线路,其中A为环线,B为东西向线路,线路都是双向的。经过的站点名分别如下,两条线交叉的换乘点用T1、T2表示。编写程序,任意输入两个站点名称,输出乘坐地铁最少需要经过的车站数量(含输入的起点和终点,换乘站点只计算一次)。地铁线A(环线)经过车站:A1 A2 A3 A4 A5 A6 A7 A8 A9 T1 A10 A11 A12 A13 T2 A14 A15 A16 A17 A18地铁线A(直线)经过车站:B1 B2 B3 B4 B5 T1 B6 B7 B8 B9 B10 T2 B11 B12 B13 B14 B15
第一题
不用算法
第二题(代码已改正,请看代码)
有关的算法:
1.Eratosthenes筛法求素数
2.判断一个数是否为素数
3.说白了,就是求一个整数的所有约数个数
第三题:
有关算法:Floyed求任意两点之间的最短路径,关键在于建图,即如何用邻接矩阵建图
(Eratosthenes筛法给两个链接:
http://blog.pfan.cn/bclz/37462.html
http://hi.baidu.com/yyvszh/item/b074622d20dbbf0f42634a56
判断素数的算法:
http://www.cppblog.com/amazon/archive/2009/06/20/88107.aspx
关于如何求一个自然数的所有约数个数,看这里:
http://wenku.baidu.com/view/9776d5d8ce2f0066f5332270.html
一个不会TLE的代码看这里:
http://hi.baidu.com/neuxxm01/item/d7c914b88bad9543ba0e12db)
先把几题的思路写在这里,明天再上具体的代码。To be continued
华为机试一般会给出统一的函数接口,不需要自己写main()函数。这里未给出。
格式请看这里(华为2013机试题):http://blog.csdn.net/arcsinsin/article/details/11017169
PS:今年华为的机试没有给出统一的函数接口,而是自己写好程序,然后submit,和OJ判题是一样的。不过测试数据给得没OJ那么严。
题目共三题,一二两题都很简单,只有第三题稍难(但是也很基础,就是著名的取石子游戏),如果你不知道斐波那契博弈的话。
第三题分析及代码请看这里(9月12号新鲜出炉):
http://blog.csdn.net/arcsinsin/article/details/11618517
上代码
第一题:
暴力。分别求出0,10,20,......100作为及格线的通过率,取通过率高于60%且最接近60%的及格线为最终的及格线。
PS:此题数据量小,所以可以暴力。若数据量大,则必须自己写排序。但是在机试时时间宝贵,暴力写起来快,可以为后面的题腾出时间。说实话,这道题就是为小白准备的。
[cpp]
view plaincopyprint?
- #include
- #include
- using namespace std;
-
-
- int main()
- {
- int a[10];
- int line[11];
- double p[11];
- int res;
- bool flags = true;
- for (int i = 0; i < 10; i++)
- {
- scanf("%d",&a[i]);
- if (a[i] < 60) flags = false;
- }
- for (int i = 0; i <= 10; i++)
- {
- line[i] = 10*i;
- }
- for (int i = 0; i <= 10; i++)
- {
- int count = 0;
- for (int j = 0; j < 10; j++)
- {
- if (a[j]-line[i] >= 0) count++;
- }
- p[i] = count*1.0/10;
- }
- double min = 1;
- double temp;
- int k;
- for (int i = 0; i < 10; i++)
- {
- temp = p[i] - 0.6;
- if (temp >= 0 && temp < min)
- {
- min = temp;
- k = i;
- }
- }
- res = line[k];
- if (flags) res = 60;
- cout<
- system("pause");
- return 0;
- }
#include
#include
using namespace std;
int main()
{
int a[10];
int line[11];
double p[11];
int res;
bool flags = true;
for (int i = 0; i < 10; i++)
{
scanf("%d",&a[i]);
if (a[i] < 60) flags = false;
}
for (int i = 0; i <= 10; i++)
{
line[i] = 10*i;
}
for (int i = 0; i <= 10; i++)
{
int count = 0;
for (int j = 0; j < 10; j++)
{
if (a[j]-line[i] >= 0) count++;
}
p[i] = count*1.0/10;
}
double min = 1;
double temp;
int k;
for (int i = 0; i < 10; i++)
{
temp = p[i] - 0.6;
if (temp >= 0 && temp < min)
{
min = temp;
k = i;
}
}
res = line[k];
if (flags) res = 60;
cout<
第二题:
比较简单的做法,就是直接模拟。
[cpp]
view plaincopyprint?
-
- #include "stdafx.h"
- #include
- using namespace std;
- bool form[1001];
- int n,count;
- int _tmain(int argc, _TCHAR* argv[])
- {
- while(cin>>n)
- {
- memset(form,1,sizeof(form));
- count = 0;
- for(int i=1;i<=n;i++)
- for(int j=i;j<=n;j++)
- if(j%i==0)
- form[j]=!form[j];
- for(int i=1;i<=n;i++)
- if(form[i]==0)
- count++;
- cout<<"有 "<" 盏灯是亮着的"<
- }
- system("pause");
- return 0;
- }
//VS2010环境
#include "stdafx.h"
#include
using namespace std;
bool form[1001];
int n,count;
int _tmain(int argc, _TCHAR* argv[])
{
while(cin>>n)
{
memset(form,1,sizeof(form));
count = 0;
for(int i=1;i<=n;i++)
for(int j=i;j<=n;j++)
if(j%i==0)
form[j]=!form[j];
for(int i=1;i<=n;i++)
if(form[i]==0)
count++;
cout<<"有 "<
第三题:
[cpp]
view plaincopyprint?
- #include
- #include
- #include
- using namespace std;
-
-
- const int inf = 0x3f3f3f3f;
- struct Graph
- {
- char vertex[35][4];
- int edges[35][35];
- int visited[35];
- };
- char s1[21][4]={"A1","A2","A3","A4","A5","A6","A7","A8","A9","T1",
- "A10","A11","A12","A13","T2","A14","A15","A16","A17","A18","A1"};
- char s2[17][4]={"B1","B2","B3","B4","B5","T1","B6","B7","B8","B9",
- "B10","T2","B11","B12","B13","B14","B15"};
- char v[35][4]={"A1","A2","A3","A4","A5","A6","A7","A8","A9","T1",
- "A10","A11","A12","A13","T2","A14","A15","A16","A17","A18",
- "B1","B2","B3","B4","B5","B6","B7","B8","B9","B10","B11",
- "B12","B13","B14","B15"};
-
-
- void CreateGraph(Graph * &G)
- {
- int i, j, k;
- for (i = 0; i < 35; i++)
- {
- memcpy(G->vertex[i],v[i],sizeof(v[i]));
- G->visited[i] = 0;
- }
- for (i = 0; i < 35; i++)
- {
- for (j = 0; j < 35; j++)
- {
- G->edges[i][j] = inf;
- }
- }
- for (k = 0; k < 20; k++)
- {
- for (i = 0;strcmp(s1[k],G->vertex[i])!=0; i++);
- for (j = 0;strcmp(s1[k+1],G->vertex[j])!=0;j++);
- G->edges[i][j] = 1;
- G->edges[j][i] = 1;
- }
- for (k = 0; k < 16; k++)
- {
- for (i = 0;strcmp(s2[k],G->vertex[i])!=0; i++);
- for (j = 0; strcmp(s2[k+1],G->vertex[j])!=0; j++);
- G->edges[i][j] = 1;
- G->edges[j][i] = 1;
- }
- }
-
- void Floyed(Graph * &G)
- {
- int i,j,k;
- for (k = 0; k < 35; k++)
- {
- for (i = 0; i < 35; i++)
- {
- for (j = 0; j < 35; j++)
- {
- if (G->edges[i][k] + G->edges[k][j] < G->edges[i][j])
- {
- G->edges[i][j] = G->edges[i][k] + G->edges[k][j];
- }
- }
- }
- }
- }
-
- void ace(Graph *G)
- {
- char s1[4],s2[4];
- int i,j;
- cout<<"请输入起点站与终点站"<
- cin>>s1>>s2;
- for (i = 0;strcmp(s1,G->vertex[i])!=0;i++);
- for (j = 0;strcmp(s2,G->vertex[j])!=0;j++);
- cout<edges[i][j]+1<
- }
- int main()
- {
- Graph *G = new Graph;
- CreateGraph(G);
- Floyed(G);
- while(1)
- {
- ace(G);
- }
- system("pause");
- return 0;
- }
#include
#include
#include
using namespace std;
//Floyed算法求任意两点之间的最短路径,算法复杂度O(n^3)虽然Floyed算法是求最短路径里面算法复杂度最大的算法,但写法简单,用于此处求任意两点之间的最短路合适
const int inf = 0x3f3f3f3f;//无穷大
struct Graph
{
char vertex[35][4];
int edges[35][35];
int visited[35];
};
char s1[21][4]={"A1","A2","A3","A4","A5","A6","A7","A8","A9","T1",
"A10","A11","A12","A13","T2","A14","A15","A16","A17","A18","A1"};
char s2[17][4]={"B1","B2","B3","B4","B5","T1","B6","B7","B8","B9",
"B10","T2","B11","B12","B13","B14","B15"};
char v[35][4]={"A1","A2","A3","A4","A5","A6","A7","A8","A9","T1",
"A10","A11","A12","A13","T2","A14","A15","A16","A17","A18",
"B1","B2","B3","B4","B5","B6","B7","B8","B9","B10","B11",
"B12","B13","B14","B15"};
//关键在于如何建图
void CreateGraph(Graph * &G)
{
int i, j, k;
for (i = 0; i < 35; i++)
{
memcpy(G->vertex[i],v[i],sizeof(v[i]));
G->visited[i] = 0;
}
for (i = 0; i < 35; i++)
{
for (j = 0; j < 35; j++)
{
G->edges[i][j] = inf;
}
}
for (k = 0; k < 20; k++)
{
for (i = 0;strcmp(s1[k],G->vertex[i])!=0; i++);
for (j = 0;strcmp(s1[k+1],G->vertex[j])!=0;j++);
G->edges[i][j] = 1;
G->edges[j][i] = 1;
}
for (k = 0; k < 16; k++)
{
for (i = 0;strcmp(s2[k],G->vertex[i])!=0; i++);
for (j = 0; strcmp(s2[k+1],G->vertex[j])!=0; j++);
G->edges[i][j] = 1;
G->edges[j][i] = 1;
}
}
//Floyed算法求任意两点之间的最短路径
void Floyed(Graph * &G)
{
int i,j,k;
for (k = 0; k < 35; k++)
{
for (i = 0; i < 35; i++)
{
for (j = 0; j < 35; j++)
{
if (G->edges[i][k] + G->edges[k][j] < G->edges[i][j])
{
G->edges[i][j] = G->edges[i][k] + G->edges[k][j];
}
}
}
}
}
void ace(Graph *G)
{
char s1[4],s2[4];
int i,j;
cout<<"请输入起点站与终点站"<>s1>>s2;
for (i = 0;strcmp(s1,G->vertex[i])!=0;i++);
for (j = 0;strcmp(s2,G->vertex[j])!=0;j++);
cout<edges[i][j]+1<
以上定有不足之处,还请多多指教。