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

设计师一般用什么网站个人网站用备案吗

设计师一般用什么网站,个人网站用备案吗,ppt模板网站大全,泊头网站建设价格目录 题目算法标签: d f s dfs dfs, 树上差分思路 d f s dfs dfs代码树上差分代码 题目 CF29D Ant on the Tree 算法标签: d f s dfs dfs, 树上差分 思路 由于点的数量很少 300 300 300, 因此时间复杂度在 O ( n 3 ) O(n ^ 3) O(n3)之内都可以通过, 考虑 d f s dfs dfs,…

题目

CF29D Ant on the Tree
在这里插入图片描述

算法标签: d f s dfs dfs, 树上差分

思路

由于点的数量很少 300 300 300, 因此时间复杂度在 O ( n 3 ) O(n ^ 3) O(n3)之内都可以通过, 考虑 d f s dfs dfs, 从叶子结点开始搜, 因为 d f s dfs dfs记录顺序是逆序, 因此倒着搜就是正序, 时间复杂度 O ( n 2 ) O(n ^ 2) O(n2)

d f s dfs dfs代码

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>using namespace std;const int N = 310;vector<int> head[N], ans;void add(int u, int v) {head[u].push_back(v);
}bool dfs(int u, int fa, int t) {if (u == t) return true;for (int v : head[u]) {if (v != fa && dfs(v, u, t)) {ans.push_back(v);return true;}}return false;
}int main() {ios::sync_with_stdio(false);cin.tie(0), cout.tie(0);int n;cin >> n;for (int i = 0; i < n - 1; ++i) {int u, v;cin >> u >> v;add(u, v), add(v, u);}int t = 1, s;while (cin >> s) dfs(s, 0, t), t = s;dfs(1, 0, t);ans.push_back(1);if (ans.size() != 2 * n - 1) {cout << -1 << "\n";return 0;}for (int x : ans) cout << x << " ";cout << "\n";return 0;
}

树上差分代码

在差分过程中, 计算每个节点应该经过的次数, 然后在统计的时候就能计算出每个节点应该被经过多少次, 从而判断是否是合法的

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>using namespace std;const int N = 310, M = 10;int n;
int fa[N][M], depth[N];
int diff[N], order[N], cnt;
vector<int> head[N];void add(int u, int v) {head[u].push_back(v);
}void dfs(int u, int pre, int dep) {fa[u][0] = pre, depth[u] = dep;int is_leaf = 1;for (int v : head[u]) {if (v == pre) continue;dfs(v, u, dep + 1);is_leaf = 0;}cnt += is_leaf;
}int lca(int u, int v) {if (depth[u] < depth[v]) swap(u, v);for (int i = M - 1; i >= 0; --i) {if (depth[fa[u][i]] >= depth[v]) u = fa[u][i];}if (u == v) return u;for (int i = M - 1; i >= 0; --i) {if (fa[u][i] != fa[v][i]) {u = fa[u][i];v = fa[v][i];}}return fa[u][0];
}void check(int u, int pre) {for (int v : head[u]) {if (v == pre) continue;check(v, u);diff[u] += diff[v];}if (u > 1 && diff[u] != 2) {cout << -1 << "\n";exit(0);}
}void move(int u, int v) {int rev = 0;if (depth[u] < depth[v]) {swap(u, v);rev = 1;}vector<int> ans;while (u != v) {ans.push_back(rev ? u : fa[u][0]);u = fa[u][0];}if (rev) reverse(ans.begin(), ans.end());for (int u : ans) cout << u << " ";
}int main() {ios::sync_with_stdio(false);cin.tie(0), cout.tie(0);cin >> n;for (int i = 0; i < n - 1; ++i) {int u, v;cin >> u >> v;add(u, v), add(v, u);}dfs(1, 0, 1);// 处理倍增数组for (int i = 1; i < M; ++i) {for (int u = 1; u <= n; ++u) {fa[u][i] = fa[fa[u][i - 1]][i - 1];}}// 起点终点都是1order[0] = order[cnt + 1] = 1;// 处理差分数组for (int i = 1; i <= cnt; ++i) {if (i <= cnt) cin >> order[i], diff[order[i]] += 2;int p = lca(order[i - 1], order[i]);diff[p] -= 2;}check(1, 0);cout << "1 ";for (int i = 1; i <= cnt + 1; ++i) {int p = lca(order[i - 1], order[i]);move(order[i - 1], p);move(p, order[i]);}cout << "\n";return 0;
}

文章转载自:

http://NislqseA.wpspf.cn
http://MVY8890Q.wpspf.cn
http://XRQLmPe4.wpspf.cn
http://MsOHsnPN.wpspf.cn
http://8XkOK9O6.wpspf.cn
http://AMxYFXMu.wpspf.cn
http://5LAyKaFM.wpspf.cn
http://WrACreVk.wpspf.cn
http://z9OM0QYk.wpspf.cn
http://NmyRcmDb.wpspf.cn
http://T3Y40nAF.wpspf.cn
http://9P44Op5M.wpspf.cn
http://5deNj6Gk.wpspf.cn
http://6cU8DvMo.wpspf.cn
http://DuLGCPlD.wpspf.cn
http://6EdKuYGJ.wpspf.cn
http://Pu87vvPq.wpspf.cn
http://r9GMFTep.wpspf.cn
http://9OQ65hML.wpspf.cn
http://2Lp88H76.wpspf.cn
http://LvtQZBJK.wpspf.cn
http://XOTyiGG2.wpspf.cn
http://GrRwmYL1.wpspf.cn
http://LAWrs2DE.wpspf.cn
http://qmLStUp8.wpspf.cn
http://XbaOGhCO.wpspf.cn
http://j2WHdof1.wpspf.cn
http://sWr2GrNI.wpspf.cn
http://5PeCqBIt.wpspf.cn
http://DeCCYoZ1.wpspf.cn
http://www.dtcms.com/wzjs/640589.html

相关文章:

  • 阿迪达斯网站建设定位网站底部公司是什么样的
  • 动漫设计工作室网站推广方法沈阳曙光医院看男科怎么样
  • 南阳网(网站).wordpress dux3.0主题
  • 房产发布网站建设品牌营销推广
  • 天津网站制作专业图片上的字体导入wordpress
  • 网站开发源程序wordpress download
  • 官方网站建设审批手续为什么网站有不同的扩展名
  • 淮北seo白杨seo教程
  • 顶尖的锦州网站建设个人网站公司网站区别经营区别
  • 太原网站建设司wordpress安装插件504
  • 网站后台的安全自己家开了一家装修公司怎么做装修网站
  • 山西利用模板建站seo最新优化技术
  • 网站流量指数设计本装修效果图
  • 上海企业自助建站系统网站备案主体 被拉黑
  • 电子商务网站建设复习题凡客建站登录入口
  • 谷歌上怎样做网站高新网站建设多少钱
  • 百度网站制作联系方式中山网站建设文化如何
  • h5页面制作软件thinkphp重庆网站seo优化
  • 做网站 接单百度快照怎么发布
  • 网站建设解决方案好处wordpress使用步骤
  • 网站备案核验号wordpress 更新翻译
  • 好看的美食网站设计网站怎么做数据库
  • 爱网站排行多用户网上商城系统
  • 前端网站开发的公用头部河北网站制作报价
  • 网站搭建平台源码衡水精品网站建设报价
  • 我国中小企业网站建设做红酒网站
  • 青海建设厅通报网站电子商务网站建设的好处有哪些
  • 网站建设的界面风格有哪些换ip 撞库 Wordpress
  • 江苏网站建设哪家专业展览会网站建设
  • 孕妇做兼职上哪家网站论坛网站建设开源工具