Practice-3 亚马逊在线测评题
来源:互联网 发布:服装收银软件排行 编辑:程序博客网 时间:2024/04/29 14:56
今年帮人做了下亚马逊的在线测评题,题和代码如下如下
稍微推导一下发现符合杨辉三角,代码如下
int calcMaxVertex(vector < int > numbers) {vector<int> factor = {1,1};while (factor.size() < numbers.size()){vector<int>temp;temp.push_back(factor.front());for (vector<int>::iterator i = factor.begin() + 1; i != factor.end(); ++i)temp.push_back(*i + *(i - 1));temp.push_back(factor.back());factor = temp;}int result = 0;sort(numbers.begin(), numbers.end());sort(factor.begin(), factor.end());for (int i = 0; i < numbers.size(); ++i)result += factor[i] * numbers[i];return result;}
可以用深度收索来做,代码如下
class Point{public:Point(){};Point(int a, int b):x(a),y(b){}int x;//行int y;//列bool operator==(const Point pt){return x == pt.x&&y == pt.y;}};int mv[8][2] = { { 1, 0 },{ -1, 0 }, { 0, -1 }, { 0, 1 }, { -1, 1 }, { -1, -1 }, { 1, 1 }, { 1, -1 } };int n, m;//n行m列int** map;int ways=0;void DFS(Point start, Point end, int step,int deadline){if (step == deadline&&start == end){++ways;return;}if (step >deadline)return;for (int i = 0; i < 8; ++i){if (start.x + mv[i][0] >= 0 && start.x + mv[i][0] < n&&start.y + mv[i][1] >= 0 && start.y + mv[i][1] < m&&map[start.x + mv[i][0]][start.y + mv[i][1]]!=1){int temp = map[start.x + mv[i][0]][start.y + mv[i][1]];map[start.x + mv[i][0]][start.y + mv[i][1]] = 1;DFS(Point(start.x + mv[i][0], start.y + mv[i][1]), end, step + 1, deadline);map[start.x + mv[i][0]][start.y + mv[i][1]] = temp;}}}int main(){//#define T 33//cout << (1 << T) << endl;//int i = 1;//unsigned j = 1;//char ch = 1;////cout << "int:" << (i << T) << endl;//printf("%p\n", i<<T);//cout <<"unsigned:"<< (j << T) << endl;//printf("%p\n", j<<T);//cout << "char:"<<(ch << T) << endl;//printf("%p\n", ch<<T);//FILE *p;//freopen_s(&p, "c:\\1.txt", "r",stdin);cin >> n >> m;map = new int*[n];Point start,end;for (int i = 0; i < n; ++i){map[i] = new int[m];for (int j = 0; j < m; ++j){cin >> map[i][j];if (map[i][j] == 1){start.x = i;start.y = j;}if (map[i][j] == 2){end.x = i;end.y = j;}}}int deadlin;cin >> deadlin;DFS(start, end, 1, deadlin);cout << ways;for (int i = 0; i < n; ++i)delete[] map[i];}
0 0
- Practice-3 亚马逊在线测评题
- cvte在线测评题总结
- 2017实习生在线测评编程题
- 链家在线测评编程题
- 亚马逊2013的一道在线笔试题
- 亚马逊2014在线面试第一题
- 阿里在线测评
- 北京大学PKU在线测评系统 3078题 Q
- 2014 亚马逊在线笔试
- 搭建程序在线测评系统
- 搜狗的在线测评
- 国内在线测评网站对比?
- 【面试题】2013亚马逊校园招聘--在线笔试题
- 2013亚马逊校园招聘在线笔试题MM-Chess
- 亚马逊在线笔试题:SpecialSubstring和elimination game
- 2013亚马逊在线笔试题目
- 2018年春季阿里前端工程师实习岗在线测评编程题总结
- 搜狗在线测评(加密解密)
- 使用fullpage.js轻松实现全屏滚动
- hdu2078 贪心
- 用友2014.9.24笔试题(部分)
- hdu 1421 dp
- 回调函数透彻理解Java
- Practice-3 亚马逊在线测评题
- 如何解决mysql安装过程中,第三步和第四步
- 使用__builtin_return_address获得程序运行栈情况
- 最大流算法之-增广路径(path augmentation)and压入与重标记算法(push-relable)
- C语言结构体的使用及注意事项
- 鸟哥的私房菜:Linux文件与目录管理
- [数位dp] ural 1057 Amount of Degrees
- Nyoj 530 K steps[矩阵乘法求两点k步的方案数]
- 用线程模拟,CountDownLatch,CyclicBarrier