第一题AC
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int ans = 0;
auto getZoneId = [](int x, int y) -> int {
if (x <= 1)
return 0 + y / 3;
if (x <= 3)
return 2 + y / 3;
return 4 + y / 3;
};
while (n--) {
vector<vector<int>> board(6, vector<int>(6));
vector<unordered_set<int>> zones(6);
vector<unordered_set<int>> rows(6);
vector<unordered_set<int>> cols(6);
for (int i = 0; i < 6; ++i) {
string s;
cin >> s;
for (int j = 0; j < 6; ++j) {
int x = s[j] - '0';
board[i][j] = x;
// cout << "i=" << i << "j=" << j << ",x=" << x << endl;
auto zId = getZoneId(i, j);
// cout << "zonId=" << zId << endl;
if (rows[i].find(x) != rows[i].end()) {
continue;
}
if (cols[j].find(x) != cols[j].end()) {
continue;
}
if (zones[zId].find(x) != zones[zId].end()) {
continue;
}
rows[i].insert(x);
cols[j].insert(x);
zones[zId].insert(x);
// cout << "zone[" << zId << "].size=" << zones[zId].size() << endl;
}
}
// for (int i = 0; i < 6; ++i) {
// for (int j = 0; j < 6; ++j) {
// cout << getZoneId(i, j);
// }
// cout << endl;
// }
int correct = 0;
for (int i = 0; i < 6; ++i) {
if (zones[i].size() == 6)
++correct;
}
if (correct == 6)
++ans;
}
cout << ans << endl;
}
第二题98.33%
#include <bits/stdc++.h>
using namespace std;
int oldMp;
int lowHp;
int highHp;
int N;
int ans = 0;
unordered_map<int, int> memo;
int dfs(const vector<int> &damage, int curHp) {
int res = 0x3ffffff;
if (lowHp <= curHp && curHp <= highHp) {
// memo[curHp] = 0;
return 0;
}
if (curHp < lowHp){
// memo[curHp] = -1;
return -1;
}
auto maxToler = curHp - lowHp;
// > maxToler
auto maxAllowIdx = upper_bound(damage.begin(), damage.end(), maxToler) - damage.begin();
for (int i = 0; i < maxAllowIdx; ++i) {
auto &&d = damage[i];
if (curHp - d < lowHp)
break;
int k;
if(curHp > highHp)
k = max(1, (curHp - highHp - 1) / d - 3);
else {
k = max(1,(curHp - lowHp + 1) / d - 1);
}
auto ret = dfs(damage, curHp - d * k);
if (ret >= 0) {
res = min(res, ret + k);
}
}
if (res == 0x3ffffff)
return -1;
return res;
}
int solve(const vector<int> &damage) {
int ans = dfs(damage, oldMp);
if (ans == -1)
return 0;
return ans;
}
int main() {
int M;
cin >> M;
while (M--) {
cin >> oldMp >> lowHp >> highHp;
cin >> N;
vector<int> damage(N);
for (int i = 0; i < N; ++i) {
cin >> damage[i];
}
cout << solve(damage) << endl;
}
}
第三题AC
太尼玛极限了。做完前两道才八点,结果他妈开第三题九点五十tm才调出来。现在反应过来所有数字也是16进制。曰
#include <bits/stdc++.h>
using namespace std;
struct functionRPC {
int no;
string func_name;
string args;
string strIndex;
int
parseStringParam() {
size_t len = args.size();
strIndex.clear();
for (size_t i = 0; i < len; ++i) {
if (args[i] == 's')
strIndex.push_back(i);
}
return strIndex.size();
}
int n_args() {
return args.length();
}
vector<int> acc_param;
int getParamLen(int idx) {
return acc_param[idx];
}
};
struct rpc_result {
string func_name;
int no;
vector<std::string> acc_param;
};
int to_dig(char c) {
if ('0' <= c && c <= '9')
return c - '0';
c = toupper(c);
if ('A' <= c && c <= 'F')
return c - 'A' + 10;
return -1;
}
int parseInt(string s) {
int ans = 0;
int e = 1;
int slen = s.length();
for (int i = slen - 1; i >= 0; --i) {
// cout << "to_dig," << to_dig(s[i]) << endl;
ans = (to_dig(s[i])) * e + ans;
e *= 16;
}
if (s[0] == 'F') {
// cout << bitset<32>(ans).to_string();
ans = -~(ans - 1);
}
return ans;
}
vector<functionRPC> rpcCall;
unordered_map<int, functionRPC> rpcHash;
ostream &operator<<(ostream &os, rpc_result &r) {
os << r.func_name + "(";
for (size_t i = 0; i < r.acc_param.size(); ++i) {
auto &&true_val = r.acc_param[i];
os << true_val;
if (i != r.acc_param.size() - 1)
os << ",";
}
os << ")";
return os;
}
void solve(const string &rpcReq) {
auto len_req = rpcReq.length();
size_t i = 0;
while (i < len_req) {
auto str_no = rpcReq.substr(i, 2);
i += 2;
// cout << "hello" <<endl;
int rpc_no = 0;
try {
rpc_no = parseInt(str_no);
} catch (exception e) {
}
// cout << "rpc_no=" << rpc_no << endl;
auto &&rpc_object = rpcHash[rpc_no];
rpc_result ans;
rpc_object.acc_param.resize(rpc_object.n_args(), 8);
ans.func_name = rpc_object.func_name;
ans.acc_param.resize(rpc_object.n_args());
ans.no = rpc_no;
// cout << "func_name=" << ans.func_name << endl;
int n_stringPram = rpc_object.parseStringParam();
// cout << "n string param: " << n_stringPram << endl;
if (n_stringPram > 0) {
for (int j = 0; j < n_stringPram; ++j) {
try {
int stringLen = parseInt(rpcReq.substr(i, 2)) * 2;
rpc_object.acc_param[rpc_object.strIndex[j]] = stringLen;
i += 2;
} catch (exception e) {
}
// cout << "string len=" << stringLen << endl;
}
}
int paramIdx = 0;
while (paramIdx < rpc_object.n_args()) {
int le = rpc_object.getParamLen(paramIdx);
// cout << le << endl;
auto s = rpcReq.substr(i, le);
if (rpc_object.args[paramIdx] == 'i') {
int val = parseInt(s);
// cout << "parseInt, val=" << val << endl;
ans.acc_param[paramIdx] = to_string(val);
} else {
ans.acc_param[paramIdx] = """ + s + """;
}
i += le;
++paramIdx;
}
cout << ans << endl;
}
}
int main() {
int N;
string rpcRequest;
cin >> N;
rpcCall.resize(N);
for (int i = 0; i < N; ++i) {
cin >> rpcCall[i].no >> rpcCall[i].func_name >> rpcCall[i].args;
rpcHash[rpcCall[i].no] = rpcCall[i];
}
cin >> rpcRequest;
// cout << rpcRequest <<endl;
solve(rpcRequest);
}
#面经笔经##网易雷火##实习##笔试题目#