请问大佬,阿里机试只有A两道才可以有面试机会吗?
4.13日晚上机试,只把第一道做出来,第二道实在没时间了,竟然只有一个小时~~~~
贴出代码,第二道是机试完本地自己做的
/*****机试1*****/ #include<iostream> #include<vector> #include<string> using namespace std; void func(int num) { int obj = 0; vector<int> arr; arr.push_back(-1); for (int i = 0; i < num; i++) { cin >> obj; arr.push_back(obj); } int length = arr.size(); vector<int> dp(length, 1); for (int i = length - 1; i >= 1; i--) { if (arr[i] != 0) { dp[arr[i]] = dp[arr[i]] + dp[i]; } } for (int i = 1; i < dp.size(); i++) cout << dp[i] << endl; } int main() { int num; while (cin >> num) { func(num); } }
/****机试2*****/ #include<iostream> #include<vector> #include<string> using namespace std; int minlength = 1000; //寻找最短路径 void findPath(int a, int b, vector<vector<int>> Path, vector<int> &visit, int &length) { if (a == b) { if (length < minlength) minlength = length; } bool res = false; for (int i = 0; i < Path.size(); i++) { if (Path[i][0] == a && visit[i] == 0) { visit[i] = 1; length = length + Path[i][2]; findPath(Path[i][1], b, Path, visit, length); length = length - Path[i][2]; visit[i] = 0; } } } void func(int n, int m, int x) { vector<vector<int>> Path(m, vector<int>(3, 0)); int temp; vector<int> visit(m, 0); int length = 0; for (int i = 0; i < m; i++) { for (int j = 0; j < 3; j++) { cin >> temp; Path[i][j] = temp; } } vector<int> minPath(n+1, 0); int max = 0; //去 for (int i = 1; i <= n; i++) { //变量初始化 length = 0; minlength = 1000; for (int i = 0; i < visit.size(); i++) visit[i] = 0; findPath(i, x, Path, visit, length); minPath[i] = minPath[i] + minlength; } //回 for (int i = 1; i <= n; i++) { //变量初始化 length = 0; minlength = 1000; for (int i = 0; i < visit.size(); i++) visit[i] = 0; findPath(x, i, Path, visit, length); minPath[i] = minPath[i] + minlength; if (minPath[i] > max) max = minPath[i]; } cout << max << endl; } int main() { int n, m, x; while (cin >> n >> m >> x) { func(n, m, x); } }