2014亚马逊在线笔试题目
2014-10-09 10:43
337 查看
参考/article/5677025.html出的题目
1、
题目的意思是
1xN的棋盘上,每个格子有一定的分值,现在有m个卡片,每个卡片上有1~4四种数值,代表走几步,类似小时候的飞行棋游戏,现在有个人站在位置0的初始点,抽取一张卡片,然后根据卡片上的数值向前移动,然后获取移动后人所在的位置的分值,然后累加,求最后所能得到的最大分数。
解题思路:
就是将m个卡片全排列,每种排列代表一种走法,然后算最大累积分值,直接利用c++的next_permutation枚举全排列函数即可。
源代码:
2、Amazon Campus(2013-Sep-24)Question 2 / 2 (Amazon Campus(17):Find the differences of items in amazon)
Amazon has millions of different items in different categories right now, so when sellers want to sell items in our website, sellers want to find the right categories their items belong to. Suppose we want to build a system to help sellers find the minimal differences items and then find the right category. The difference index is a number that sum of single-word edits (insertion, deletion, substitution) required to change one phrase into the other:
For example, we get two lines from standard input Hadoop in practice
Hadoop operations
The difference index of ‘Hadoop in practice’ and ‘Hadoop operations’ is 2. Because we can remove ‘practice’ and substitute ‘in’ with ‘operations’, then ‘Hadoop in practice’ can convert to ‘Hadoop operations’
For example, we get two lines from standard input
Hadoop cookbook
Hadoop operations
The difference index of ‘Hadoop cookbook’ and ‘Hadoop operations’ is 1. Because we can substitute ‘cookbook’ with ‘operations’ then convert 'Hadoop cookbook' can convert to 'Hadoop operations'
For example, we get two lines from standard input:
Ruby in action
Hadoop operations
The difference index of ‘Ruby in action’ and ‘Hadoop operations’ is 3. Because we can substitute ‘Ruby’ with ‘Hadoop’, ‘in’ with ‘operations’ and remove ‘action’ then 'Ruby in action' can convert to 'Hadoop operations'
字符串距离的变形题
将字符串按照空格分割,然后放入vector中,然后利用动态规划求解
1、
题目的意思是
1xN的棋盘上,每个格子有一定的分值,现在有m个卡片,每个卡片上有1~4四种数值,代表走几步,类似小时候的飞行棋游戏,现在有个人站在位置0的初始点,抽取一张卡片,然后根据卡片上的数值向前移动,然后获取移动后人所在的位置的分值,然后累加,求最后所能得到的最大分数。
解题思路:
就是将m个卡片全排列,每种排列代表一种走法,然后算最大累积分值,直接利用c++的next_permutation枚举全排列函数即可。
源代码:
#include <iostream> #include <vector> #include <fstream> #include <algorithm> using namespace std; int main(){ int n,m; cin >> n >>m ; vector<int> score(n,0), cards(m,0); for(int i = 0 ; i < n; ++ i) cin >> score[i]; for(int i = 0; i < m; ++ i) cin >> cards[i]; int res = 0; do{ int sum = score[0],index = 0; for(int i = 0; i < m; ++ i){ index +=cards[i]; if(index >= n) break; sum +=score[index]; } res = max(res,sum); }while(next_permutation(cards.begin(),cards.end())); cout<<res<<endl; }
2、Amazon Campus(2013-Sep-24)Question 2 / 2 (Amazon Campus(17):Find the differences of items in amazon)
Amazon has millions of different items in different categories right now, so when sellers want to sell items in our website, sellers want to find the right categories their items belong to. Suppose we want to build a system to help sellers find the minimal differences items and then find the right category. The difference index is a number that sum of single-word edits (insertion, deletion, substitution) required to change one phrase into the other:
For example, we get two lines from standard input Hadoop in practice
Hadoop operations
The difference index of ‘Hadoop in practice’ and ‘Hadoop operations’ is 2. Because we can remove ‘practice’ and substitute ‘in’ with ‘operations’, then ‘Hadoop in practice’ can convert to ‘Hadoop operations’
For example, we get two lines from standard input
Hadoop cookbook
Hadoop operations
The difference index of ‘Hadoop cookbook’ and ‘Hadoop operations’ is 1. Because we can substitute ‘cookbook’ with ‘operations’ then convert 'Hadoop cookbook' can convert to 'Hadoop operations'
For example, we get two lines from standard input:
Ruby in action
Hadoop operations
The difference index of ‘Ruby in action’ and ‘Hadoop operations’ is 3. Because we can substitute ‘Ruby’ with ‘Hadoop’, ‘in’ with ‘operations’ and remove ‘action’ then 'Ruby in action' can convert to 'Hadoop operations'
字符串距离的变形题
将字符串按照空格分割,然后放入vector中,然后利用动态规划求解
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <sstream> using namespace std; vector<string> split(string& str){ stringstream ss; ss << str; vector<string> res; string tmp; while(ss >> tmp) res.push_back(tmp); return res; } int distanceBetweenString(string& str1,string& str2){ if(str1 == str2) return 0; vector<string> word1=split(str1); vector<string> word2=split(str2); int len1 = word1.size(),len2 = word2.size(); if(len1 == 0) return len2; if(len2 == 0) return len1; vector<vector<int> > dp(len1+1, vector<int>(len2+1,0)); for(int i = 0; i <= len1; ++ i) dp[i][0] = i; for(int j = 0; j <= len2; ++ j) dp[0][j] = j; for(int i =1; i <= len1; ++ i){ for(int j = 1; j <= len2; ++ j){ dp[i][j] = min(dp[i-1][j-1]+(word1[i-1] != word2[j-1]? 1: 0),min(dp[i-1][j]+1, dp[i][j-1]+1)); } } return dp[len1][len2]; } int main(){ string str1,str2; getline(cin,str1); getline(cin,str2); cout<<distanceBetweenString(str1,str2)<<endl; }
相关文章推荐
- 2014亚马逊在线笔试题目及解决方案(MMChess问题)
- 2013亚马逊在线笔试题目
- [2014亚马逊amazon] 在线笔试题 大于非负整数N的第一个回文数 Symmetric Number
- 2014 亚马逊在线笔试
- 2014年亚马逊在线笔试题目及解法_9_24(字符串编辑距离升级版)
- 2012 亚马逊在线笔试题目2
- 2012 亚马逊在线笔试题目1
- 微软2016校园招聘在线笔试第二场 题目1 : Lucky Substrings
- 2013亚马逊校园招聘在线笔试题MM-Chess
- 亚马逊2015校招在线笔试2
- 微软2014在线笔试第二题 (对于问题中的k是有限制的,取值范围是1~9)
- 微软2014在线笔试 第三题
- 百度2014移动研发笔试题目
- 网易互娱2017实习生招聘在线笔试第一场 题目1 : 电子数字
- 【微软2014实习生及秋令营技术类职位在线测试】题目1 : String reorder
- 亚马逊 在线测试题目 amazon (变种的)三叉树的最近公共祖先问题
- 2014 8月华为软件类上机笔试题目解答
- 百度2014移动研发笔试题目——1013清华版
- (转)百度2014移动研发笔试题目——1013清华版
- 2014腾讯校园招聘实习笔试题目广州站