蘑菇街春招Android岗编程题

第一道题:
小峰疯狂的爱上了小兰,他想要向小兰告白,小峰是个内向的男孩子,不好意思当面说, 正好小兰家的对面是一个很大的广告牌,所以他想要借助广告牌说出自己的爱情***。 小峰想要在广告牌上写数字表达自己对小兰的爱意,数字越大代表队小兰的爱意越深, 越容易获得小兰的垂青。不幸的是小峰只有v升油漆来书写数字,而数字d需要ad升油漆才能写好, 并且小峰知道小兰不喜欢数字0,所以他不会让0出现在自己的爱情数字当中。 请帮助小峰找到他利用手里的油漆能够完成的最大数字。 输入 第一行数据是一个整数:v (0≤v≤106),表示拥有的总油漆数量。 第二行数据是九个整数:a1,a2, ...,a9 (1≤ai≤105),表示数字1~9 分别需要的油漆数量。 输出 输出能够完成的最大数字,如果一个数字也完成不了输出-1  样例输入 5 5 4 3 2 1 2 3 4 5 样例输出 55555

第二道题: 小M有4个饮料瓶子,家里来了一个好朋友,它要和它的好朋友玩游戏:
游戏的规则是4个瓶子之间互相分饮料,4个瓶子的容量分别是:10升, 6升,5升, 4升, 开始的状态是 [10,0,0,0],也就是说:第一个瓶子满着,其它的都空着。 游戏允许把饮料从一个瓶子倒入另一个瓶子,但只能把一个瓶子倒满或把一个瓶子倒空, 不能有中间状态。这样的一次倒饮料动作称为1次操作。 假设瓶子的容量和初始状态不变, 小M给好友设定目标状态,让好友用最少的操作才能实现分饮料动作。 输入 输入4个整数,分别表示目标状态,中间用空格隔开。这四个整数之和为10,否则输出为-1。 输出 输出为最少的操作次数,如果不满足条件,则输出-1。  样例输入 9 0 0 0 样例输出 -1

全部评论
//四个瓶子 10 6 5 4,给以中间态,求最小倒饮料次数,要求每次必须倒完或者倒满; #include<vector> #include<iostream> #include<set> #include<map> #include<algorithm> #include<numeric> std::set<std::vector<int>> states; std::map<std::vector<int>, int> min_times,changtimes; std::vector<int> bottle{ 10,6,5,4 }; void state_change(std::vector< int> state) { using namespace std; if (states.find(state) != states.end()) return; states.insert(state); for (int i{}; i < 4;++i) { if (state[i] == 0) continue; for (int j{};j < 4;++j) { if (j == i)continue; if (state[j]== bottle[j]) continue; else { vector<int> nst(state); if (state[i] >= bottle[j] - state[j]) { nst[j] = bottle[j]; nst[i] -= bottle[j] - state[j]; } else { nst[j] += state[i]; nst[i] = 0; } if (changtimes.find(nst) == changtimes.end()) { changtimes.emplace(nst, changtimes[state] + 1); } auto nstcp = nst; sort(nstcp.begin(), nstcp.end()); if (min_times.find(nstcp) != min_times.end() && min_times[nstcp] < changtimes[state] + 1); else { min_times[nstcp] = changtimes[state] + 1; } state_change(nst); } } } } int main() { using namespace std; vector<int> initi{10 ,0 , 0, 0 } ,nein{initi}; changtimes[initi] = 0; sort(nein.begin(), nein.end()); min_times[nein] = 0; state_change(initi); while (true) { vector<int> vec(4, 0); for (int i{ 0 };i < 4;++i) cin >> vec[i]; sort(vec.begin(), vec.end()); if(min_times.find(vec)!=min_times.end()) cout<< min_times[vec]<<'\n'; else { cout << -1 << '\n'; } } }
点赞 回复 分享
发布于 2016-04-01 20:59
http://blog.csdn.net/wsnbb123456789/article/details/50548841 看这里
点赞 回复 分享
发布于 2016-03-31 21:43
http://www.tuicool.com/articles/vMNbUrj 看这里
点赞 回复 分享
发布于 2016-03-31 21:41
后端 第一个是砍桌子腿  第二个一样
点赞 回复 分享
发布于 2016-03-31 21:33
Android岗也是这两题。。。
点赞 回复 分享
发布于 2016-03-31 21:17
我是算法岗啊,也是这两个题目。
点赞 回复 分享
发布于 2016-03-31 21:15
后端开发。第二题一样,感觉实现起来对我有点困难。。
点赞 回复 分享
发布于 2016-03-31 21:12
第二题有没有思路啊,感觉摸不着头脑啊
点赞 回复 分享
发布于 2016-03-31 21:07

相关推荐

不愿透露姓名的神秘牛友
07-04 14:23
steelhead:你回的有问题,让人感觉你就是来学习的
点赞 评论 收藏
分享
评论
1
11
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务