当前位置: 首页 > news >正文

AK 9.12 百度Java后端研发B卷 笔试

T1(博弈论)

#include <bits/stdc++.h>#define endl '\n'using namespace std;typedef long long LL;const int N = 1e5 + 10;int n, m, t;void solve() {cin >> n >> m; t = n + m - 2;if(t & 1) cout << "Yes" << endl;else cout << "No" << endl;
}int main() {cin.tie(0); cout.tie(0);std::ios::sync_with_stdio(false);int T = 1;cin >> T;while(T --) {solve();}return 0;
}

T2(思维,模拟,哈希表,位运算)

#include <bits/stdc++.h>#define endl '\n'using namespace std;typedef long long LL;const int N = 1e5 + 10;int n, m;
int a[N];int xor_in = 0, XOR_M;
unordered_map<int, int> mp;
unordered_map<int, int> in, out;bool check() {if(in.size() == m && xor_in == XOR_M) {cout << "YES" << endl;cout << 0 << endl;return true;}if(in.size() == m - 1 && out.size() == 1) {int target = XOR_M ^ xor_in;int idx = mp[target];if(idx != 0) {cout << "YES" << endl;cout << 1 << endl;cout << (out.begin())->second << ' ' << idx << endl;return true;}}return false;
}void solve() {cin >> n >> m;for(int i = 1; i <= n; i ++) cin >> a[i];for(int i = 1; i <= m; i ++) XOR_M ^= i;for(int i = 1; i <= m; i ++) {if(a[i] > m) out[a[i]] = i;else in[a[i]] = i, xor_in ^= a[i];}for(int i = m + 1; i <= n; i ++) mp[a[i]] = i;if(check()) return ;for(int i = 1, j = m + 1; j <= n; i ++, j ++) {if(a[i] >= 1 && a[i] <= m) {in.erase(a[i]);xor_in ^= a[i];} else out.erase(a[i]);if(a[j] >= 1 && a[j] <= m) in[a[j]] = j, xor_in ^= a[j];else out[a[j]] = j;mp.erase(a[j]);mp[a[i]] = i;if(check()) return ;}cout << "NO" << endl;
}int main() {cin.tie(0); cout.tie(0);std::ios::sync_with_stdio(false);int T = 1;
//	cin >> T;while(T --) {solve();}return 0;
}

T3(模拟,哈希表)

#include <bits/stdc++.h>#define endl '\n'using namespace std;typedef long long LL;const int N = 1e5 + 10;unordered_map<string, unordered_map<string, unordered_set<string>>> fun; // name : args : typestring get_type(string op) {string ret;for(char c : op) {if(c == ' ') break;ret += c;}return ret;
}string get_name(string op) {string ret;int idx = op.find('('); idx -- ;for(; idx >= 0; idx --) {if(op[idx] == ' ') break;ret += op[idx];}reverse(ret.begin(), ret.end());return ret;
}string get_args(string op) {int a = op.find('('), b = op.find(')');op = op.substr(a + 1, b - a - 1); op += ',';vector<string> ss; string t;for(char c : op) {if(c == ',') ss.push_back(t), t = "";else t += c;}string ret;for(string s : ss) {if(s.find(' ') != -1) ret += s.substr(0, s.find(' ')) + ",";else ret += s + ",";}return ret;
}void solve() {int T, code;cin >> T;string op;while(T --) {cin >> code;getline(cin, op);getline(cin, op);if(code == 1) {string type = get_type(op);string name = get_name(op);string args = get_args(op);if(fun.count(name) == 0) {fun[name][args].insert(type);cout << "ok." << endl;} else {if(fun[name].count(args) == 0) {fun[name][args].insert(type);cout << "ok." << endl;} else {cout << "method " << name << " is already defined." << endl;}}} else if(code == 2) {string type = get_type(op);string name = get_name(op);string args = get_args(op);if(fun.count(name) != 0 && fun[name].count(args) != 0) cout << "ok." << endl;else if(fun.count(name) == 0) cout << "cannot find symbol " << name << "." << endl;else if(fun.count(name) != 0 && fun[name].count(args) == 0) {cout << "method " << name << " cannot be applied to given types." << endl;}}}}int main() {cin.tie(0); cout.tie(0);std::ios::sync_with_stdio(false);solve();return 0;
}
http://www.lryc.cn/news/170356.html

相关文章:

  • 使用Python和XPath解析动态JSON数据
  • 记录一个iOS实现视频分片缓存拖拽快进不能播放的问题
  • 如何解决 503 Service Temporarily Unavailable?
  • keil报错:Flash Download failed - Could not load file‘..\..\Output\Template.axf
  • 从一到无穷大 #16 ByteSeries,思考内存时序数据库的必要性
  • 分支和远程仓库
  • 编译原理 —— 编译器
  • Python灰帽编程——错误异常处理与面向对象
  • 【每日一题】154. 寻找旋转排序数组中的最小值 II
  • Linux中如何获取输入设备(如触摸屏、按键等)的事件信息
  • Java学习day05:排序,选择、冒泡、快速、二分、杨辉三角
  • Mybatis的mapper.xml批量插入、修改sql
  • Centos7部署单机版MongoDB
  • Docker实战-第一章欢迎来到Docker世界
  • 初识C语言——详细入门一(系统性学习day4)
  • python 学习笔记(6)—— Flask 、MySql
  • Deepin下vsftp服务安装配置虚拟用户
  • OpenpyxlWriter‘ object has no attribute ‘save‘
  • ES6(三)
  • Android 数据库封装(SQLite)
  • Git从入门到起飞(详细)
  • R读写parquet文件
  • Java21 LTS版本
  • 【性能优化】虚拟懒加载(下拉滚动加载长列表)element-puls+el-table
  • 一对多映射处理
  • 关于IDEA没有显示日志输出?IDEA控制台没有显示Tomcat Localhost Log和Catalina Log 怎么办?
  • 蛇形填数 rust解法
  • 一文探索SD-WAN技术进阶后与MPLS的区别
  • RocketMq(四)消息分类
  • ip地址怎么改网速快