笔试-iHandy-180927(算法/机器学习)
笔试-iHandy-180927
- 单项选择题 8 道,不定项选择题 5 道,问答题 2 道,编程题 1 道
- 时间 60 分钟
【问答】射击(概率题)
问题描述
假设有一支***,每次扣动扳机,有 50% 的概率发射子弹; 现甲和乙轮流使用该***想对方射击,直到其中一方中弹; 问甲先射击,乙先中弹的概率?
【编程】比大更大
问题描述
把数组排成最大的数(剑指Offer:把数组排成最小的数)
贪心(80%)
n = int(input()) s = [] for _ in range(n): s.append(input()) s.sort(reverse=True) #print(s) ans = ''.join(s) print(int(ans))
自定义排序(80%)
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <sstream> using namespace std; string foo(vector<string> ns) { sort(ns.begin(), ns.end(), [](const string &l, const string &r){ return r + l < l + r; }); stringstream ss; for (auto i : ns) ss << i; return ss.str(); } int main() { int n; cin >> n; vector<string> ns(n); for (int i=0; i < n; i++) cin >> ns[i]; cout << foo(ns); // 这里把结果转成整型应该就行了 return 0; }#机器学习##笔试题目#