全部评论
同只做出来两题,第三题用了普通的,走过不能重复走的,深搜,测试样例过了,但是提交了就是超时0%,这要是走过可以重复走,时间就更爆炸了,哪个大佬来给点提示第三题怎么做。
同两题,第三题感觉还需要更多时间,但也许就是做不出来
求问一下第二题的输入怎么解决的?我用getline为什么最后一行读不进去
同问第二题,本地IDE可以过,在线提交tab键有问题
写题一小时 改输入一个半小时🙃
菜鸡看着前面的大佬瑟瑟发抖。。死磕第二题加号那个情况一直过不去。。直接凉
帮别人做了1和3,不过3写了一个小时,发给他后他没时间交,晕 感觉第三题就是记录一下状态(每个位置都要24维表示魔方状态)然后搜索就行了?
就做了一个 是不是凉凉
// 代码分享
// 第一题 100%
#include <iostream>
using namespace std;
static int dirs[4][2] = { {-1, -1}, {-1, 1}, {1, 1}, {1, -1} };
int solve(int n, int m, int x, int y, int dx, int dy, int t) {
int res = 0;
for (int i = 0; i < t; ++i) {
x += dx;
y += dy;
if (x == 2 || x == n - 1) {
++res;
dx = -dx;
}
if (y == 2 || y == m - 1) {
++res;
dy = -dy;
}
}
return res;
}
int main() {
int Q = 0;
cin >> Q;
while (Q--) {
int N = 0, M = 0;
cin >> N >> M;
int X = 0, Y = 0, W = 0, T = 0;
cin >> X >> Y >> W >> T;
int res = solve(N, M, X, Y, dirs[W][0], dirs[W][1], T);
cout << res << endl;
}
return 0;
}
// 第二题 100%
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int solve(string str) {
int res = 0;
switch(str[0]){
case '#':
res = solve(str.substr(1));
break;
case '+':
res = solve(str.substr(2)) + 1;
break;
default:
int n = str.size();
bool flag = false;
for (int i = 0; i < n; ++i) {
if (str[i] == '(') {
if (i > 0 && str[i - 1] == ']') {
flag = true;
res -= 2;
}
else {
++res;
}
}
else if (str[i] == ')'){
if (flag) {
flag = false;
}
else {
++res;
}
}
else{
if (!flag) {
++res;
}
}
}
break;
}
return res;
}
int main() {
int T = 0;
cin >> T;
while (T--) {
int N = 0;
cin >> N;
getchar();
vector<string> content(N);
for (int i = 0; i < N; ++i) {
getline(cin, content[i]);
}
int res = 0;
for (int i = 0; i < N; ++i) {
cout << content[i] << endl;
res += solve(content[i]);
}
cout << res << endl;
}
return 0;
}
// 第三题 0% 超时 深搜
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cctype>
#include <climits>
using namespace std;
// 左 右 下 上
static int dirs[4][2] = { {0, -1}, {0, 1}, {1, 0}, {-1, 0} };
void dfs(vector<string> & matrix, vector<int> &weight, vector<vector<int>> &visited,
int x, int y, int tx, int ty, int di, int qian, int you, int path, int &res){
int m = matrix.size(), n = matrix[0].size();
if (x == tx && y == ty) {
path += weight[di];
res = min(path, res);
return;
}
visited[x][y] = 1;
for (int d = 0; d < 4; ++d) {
int newx = x + dirs[d][0];
int newy = y + dirs[d][1];
int newd = di, newq = qian, newyou = you;
if (newx >= 0 && newx < m && newy >= 0 && newy < n &&
!visited[newx][newy] && matrix[newx][newy] == '.') {
switch (d) {
case 0:
newd = 5 - you;
newyou = di;
break;
case 1:
newd = you;
newyou = 5 - di;
break;
case 2:
newd = qian;
newq = 5 - di;
break;
case 3:
newd = 5 - qian;
newq = di;
break;
}
dfs(matrix, weight, visited, newx, newy, tx, ty, newd, newq, newyou,
path + weight[di], res);
}
}
visited[x][y] = 0;
}
int main() {
int T = 0;
cin >> T;
while (T--) {
int M = 0, N = 0;
cin >> M >> N;
vector<string> matrix(M);
for (int i = 0; i < M; ++i) {
cin >> matrix[i];
}
int sx, sy, tx, ty;
cin >> sx >> sy >> tx >> ty;
vector<int> weight(6);
for (int i = 0; i < 6; ++i) {
cin >> weight[i];
}
if (matrix[sx][sy] == '#' || matrix[tx][ty] == '#') {
cout << -1 << endl;
}
else {
int res = 0x3f3f3f3f;
vector<vector<int>> visited(M, vector<int>(N, 0));
dfs(matrix, weight, visited, sx, sy, tx, ty, 4, 0, 2, 0, res);
cout << (res == 0x3f3f3f3f ? -1 : res) << endl;
}
}
return 0;
}
//第二题测试用例过,提交通过 0%。有没有大佬帮看一下问题在哪里?谢过!
#include <iostream>
#include <cstdio>
#include<string>
using namespace std;
int process(string s) { int count = 0; bool flag = false; for (int i = 0; i < s.size(); i++) { if (s[i] == ')') flag = false; if (s[i] == '(') flag = true; if (flag==false&&(s[i] >= 'a'&&s[i] <= 'z') || (s[i] >= 'A'&&s[i] <= 'Z')) { count++; } } return count;
}
int main() { int T; cin >> T; for (int i = 0; i < T; i++) { int N; cin >> N; int count = 0; string s; char c = getchar(); for (int j = 0; j < N; j++) { getline(cin, s); count+=process(s); if (s[0] == '+') count++; } cout << count<<endl; } return 0;
}
//有没有大佬帮看看第二题呢,只过了测试样例,提交0%,呜呜呜呜呜~~~
#include <iostream>
#include <cstdio>
#include<string>
using namespace std;
int process(string s) {
int count = 0;
bool flag = false;
for (int i = 0; i < s.size(); i++) {
if (s[i] == ')')
flag = false;
if (s[i] == '(')
flag = true;
if (flag==false&&(s[i] >= 'a'&&s[i] <= 'z') || (s[i] >= 'A'&&s[i] <= 'Z')) {
count++;
}
}
return count;
}
int main() {
int T;
cin >> T;
for (int i = 0; i < T; i++) {
int N;
cin >> N;
int count = 0;
string s;
char c = getchar();
for (int j = 0; j < N; j++) {
getline(cin, s);
count+=process(s);
if (s[0] == '+')
count++;
}
cout << count<<endl;
}
return 0;
}
各位3题做了两题的笔试过了吗,我已经凉了😂最后一批要求这么高吗,还是人已经招满了
2题,下周二面试,我本来投的后台服务器开发,然后hr打电话问我愿意转游戏开发吗,哈哈,直接帮我改的意向
老哥收到面试了吗 我下周一
相关推荐
点赞 评论 收藏
分享
11-17 14:23
海南热带海洋学院 Java 点赞 评论 收藏
分享