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

2023/8/11题解

时间限制:

1000MS

内存限制:

65536KB

在这里插入图片描述
image.png

image.png

解题思路

建树 + 模拟 ,复杂在于建树,此处从题目需求可知需要按层建树,所以需要队列模拟,查找比较容易就是普通的深搜

参考代码
#include<bits/stdc++.h>
using namespace std;
vector<int> v;
vector<int> a;
vector<int> b;
int n,q,num;
int cnt = 1;
const int N = 1e5 + 10;
class node{public:int val;vector<node*> chil;node(int num){val = num;}
};vector<node*> mp(N,nullptr);node *root = nullptr;void build(node *head){if(!head){return;}queue<node*> que;que.push(head);while(!que.empty()){int len = que.size();for(int k = 0; k < len; ++k){head = que.front();que.pop();int i = cnt - 2;int begin = v[i];while(i < n - 1 && begin == v[i++]){node *t = new node(cnt);mp[cnt++] = t;head->chil.push_back(t);}for(node* z : head->chil){que.push(z);}}}}int find(node *p){if(!p){return 1;}int s = 0;for(node *i : p->chil){s += find(i);}return s == 0 ? 1 : s;
}void debug(node* head){if(!head){return;}queue<node*> que;que.push(head);while(!que.empty()){      int len = que.size();for(int k = 0; k < len; ++k){node* p = que.front();que.pop();cout << p->val << ' ';for(node* i : p->chil){que.push(i);}}cout << endl;}return;
}int main(){root = new node(cnt);mp[cnt++] = root;cin >> n >> q;for(int i = 0; i < n - 1; ++i){cin >> num;v.push_back(num);}sort(v.begin(), v.end());build(root);
//   debug(root);for(int i = 0; i < q; ++i){cin >> num;a.push_back(num);}for(int i = 0; i < q; ++i){cin >> num;b.push_back(num);}int res = 0;for(int i = 0 ; i < q; ++i){int res_a = find(mp[a[i]]);int res_b = find(mp[b[i]]);// cout << res_a << ' ' << res_b << endl;res ^= res_a * res_b;}cout << res;return 0;
}
http://www.lryc.cn/news/118918.html

相关文章:

  • 构造函数
  • JS 原型与继承
  • 解决 Oracle 数据库中表被锁问题的方案和方法
  • ORACLE行转列、列转行实现方式及案例
  • AI自动驾驶
  • 思维导图在职业规划中的应用:从职业选择到职业发展的思维导图
  • antv l7每次刷新无法加载iconFont
  • 28 玻尔兹曼机
  • 命令提示符之操作基础(Windows)
  • 【C语言】初识C语言+进阶篇导读
  • wxWidgets学习笔记:wxListCtrl使用详解
  • 酷炫的python日志库-loguru
  • html根据图片变换背景色
  • “深入探究JVM:揭秘Java虚拟机的工作原理“
  • 小程序的api使用 以及一些weui组件实列获取头像 扫码等
  • 海思ss928部署手写数字识别模型
  • 组学知识速递(五)|ChIP-seq知多少?
  • 2308C++内存序概略
  • 【C++】string的使用
  • Android 周期任务
  • 修改第三方组件默认样式
  • 【游戏客户端】制作你玩我猜Like玩法
  • 分页查询从接口到实现,统一对日期类型进行格式化处理
  • 栈和队列详解(1)
  • 苏州OV泛域名RSA加密算法https
  • 凯迪正大—微机继电保护校验仪
  • Linux文件属性与权限管理(可读、可写、可执行)
  • Centos7.9安装lrzsz进行文件传输---Linux工作笔记059
  • 酒吧座位全解析 小白必看
  • DAY19