700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 网易互娱游戏研发工程师笔试

网易互娱游戏研发工程师笔试

时间:2018-10-25 07:38:23

相关推荐

网易互娱游戏研发工程师笔试

//第三题 流量统计问题,二分查找区间#include <iostream>#include <string>#include <vector>#include <algorithm>using namespace std;int main(){int n,m;cin >> n;vector<string> time(n);vector<int> flow(n);string a, b, c, d;int k;for (int i = 0; i<n; i++){cin >> a >> b >> k;//注意字符串的输入和处理time[i] = a.substr(6) + a.substr(0, 2) + a.substr(3, 2) + b;flow[i] = k;}cin >> m;for (int i = 0; i < m; i++){cin >> a >> b >> c >> d;a = a.substr(6) + a.substr(0, 2) + a.substr(3, 2) + b;c = c.substr(6) + c.substr(0, 2) + c.substr(3, 2) + d;int res = 0;//这两个函数不知道能不能直接用,就是二分查找找左右值。int l = lower_bound(time.begin(), time.end(), a)-time.begin();int r = upper_bound(time.begin(), time.end(), c)-time.begin();for (int j = l; j < r; j++)res += flow[j];cout << res << endl;}return 0;}

//第四题 三杀,得到杀死每个小乖的时间,然后考虑每种击杀顺序的最小怪伤害#include <iostream>#include <vector>#include <algorithm>using namespace std;//判断杀死每个小怪需要多少时间,注意下技能冷却的cd, 每个技能的攻击力大小。int kill(int p, int cd, int k1, int k2, int k3, int hp){if (k1 < p) k1 = p;if (k2 < p) k2 = p;if (k3 < p) k3 = p;if (k1 < k3) swap(k1, k3);if (k1 < k2) swap(k1, k2);if (k2 < k3) swap(k2, k3);int res = 0;int t1 = 0, t2 = 0, t3 = 0;while (hp>0){if (!t1){hp -= k1; t1 = cd; res++;t2 = t2 == 0 ? 0 : t2--;t3 = t3 == 0 ? 0 : t3--;}else if (!t2){hp -= k2; t2 = cd; res++;t1 = t1 == 0 ? 0 : t1--;t3 = t3 == 0 ? 0 : t3--;}else if (!t3){hp -= k3; t3 = cd; res++;t1 = t1 == 0 ? 0 : t1--;t2 = t2 == 0 ? 0 : t2--;}else{hp -= p; t1--; t2--; t3--; res++;}}return res;}int main(){int n;cin >> n;for (int i = 0; i < n; i++){int h, p, cd, k1, k2, k3;cin >> h >> p >> cd;cin >> k1 >> k2 >> k3;vector<pair<int, int>> m(3);cin >> m[0].first >> m[0].second;cin >> m[1].first >> m[1].second;cin >> m[2].first >> m[2].second;vector<int> time(3);for (int i = 0; i < 3; i++)time[i] = kill(p, cd, k1, k2, k3, m[i].first);//计算每种策略的最小值,我把每种击杀顺序都罗列了一遍int d = m[0].second*time[0] + m[1].second*time[1] + m[2].second*time[2];int d1 = d + time[0] * (m[1].second + m[2].second) + min(time[1] * m[2].second, time[2] * m[1].second);int d2 = min(d1, d + time[1] * (m[0].second + m[2].second) + min(time[0] * m[2].second, time[2] * m[0].second));int d3 = min(d2, d + time[2] * (m[0].second + m[1].second) + min(time[0] * m[1].second, time[1] * m[0].second));h -= d3;if (h>0) cout << h << endl;else cout << -1 << endl;}return 0;}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。