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

临沂网站建设兼职如何关闭2345网址导航

临沂网站建设兼职,如何关闭2345网址导航,哪些网站可以找到做海报的素材,wordpress美化编辑插件文章目录1.病毒溯源问题:求树的最长链长度和字典序最小的最长链思路:2.龙龙送外卖思路:3.红色警报:思路:1.病毒溯源 问题:求树的最长链长度和字典序最小的最长链 思路: 一开始用 bfs 做的 &a…

文章目录

  • 1.病毒溯源
    • 问题:求树的最长链长度和字典序最小的最长链
    • 思路:
  • 2.龙龙送外卖
    • 思路:
  • 3.红色警报:
    • 思路:

1.病毒溯源

问题:求树的最长链长度和字典序最小的最长链

思路:

一开始用 bfs 做的 , 一直是段错误 , 很迷惑 , 最后换成了 dfs , 深搜比广搜使用的空间少。

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef long long ll;
const int N = 1e4+10;
const int mod = 1e9 + 7;
typedef pair<int,int>PII;
const int inf = 1 << 31 - 1;
const double eps = 1e-9;int n , c , k , root , mx;
vector<int>ve[N];
bool vis[N];
vector<int>ans , now;void dfs(int id,int h){if(h > mx){ mx = h; ans = now; }for(auto k : ve[id]){now.push_back(k);dfs(k , h + 1);now.pop_back();}	
}int main(){cin >> n;for(int i=0;i<n;i++){cin >> c;for(int j=1;j<=c;j++){cin >> k;vis[k] = 1;ve[i].push_back(k);}sort(ve[i].begin(),ve[i].end());//排序 , 保证最先遇到的最长串一定是字典序最小的;}for(int i=0;i<n;i++) if(!vis[i]) now.push_back(i) , dfs(i,1);cout << mx << "\n";//	for(auto k : ans) cout << k << " ";for(int i=0;i<(int)ans.size();i++){if(i != (int)ans.size() - 1)cout << ans[i] << " ";else cout << ans[i];}	return 0;
}
//freopen("文件名.in","r",stdin);
//freopen("文件名.out","w",stdout);

2.龙龙送外卖

思路:

送餐完成后不返回起点的最小距离 = 总距离 - 最深节点深度

所以原问题分解成了两个问题:
第一个问题是要求总距离 , 也就是到达所有节点需要的边数 × 2
第二个问题就是要求 : 最深节点的深度

如果我们每加入一个节点都从根节点开始搜索 , 搜索上面的两个值 , 不仅费力 , 而且会TLE ,这样就需要我们用另一种思路 , 那就是“反着搜” , 当加入某个节点时 , 从当前节点往根节点搜 , 我们结合记忆化搜索 , 就很轻松地可以求出当前节点的深度 , 而到达所有节点需要的边数也就变成了前面所有点到达根节点经过的不同点的数量

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef long long ll;
const int N = 1e5+10;
const int mod = 1e9 + 7;
typedef pair<int,int>PII;
const int inf = 1 << 31 - 1;
const double eps = 1e-9;int n , m , u , mx_h , all;
int fa[N] , h[N];int dfs(int x){if(fa[x] == -1 || h[x]) return h[x];//记忆化搜索记录深度all++;//记录不同的节点数return h[x] = dfs(fa[x]) + 1;
}int main(){IOScin >> n >> m;for(int i=1;i<=n;i++) cin >> fa[i];for(int i=1;i<=m;i++){cin >> u;mx_h = max(mx_h , dfs(u));cout << all * 2 - mx_h << "\n";}return 0;
}
//freopen("文件名.in","r",stdin);
//freopen("文件名.out","w",stdout);

3.红色警报:

思路:

根据题意的描述 , 不难看出描述出来的是一个并查集的逆过程:从联通集里拆点 , 问拆到那个点会使联通集变多(发出红色警报);
正着想肯定是没什么思路 , 不如我们反着想 , 就是找加入哪些点会使联通集变少 , 这就正好是并查集的过程 , 所以题解就是按照拆点的逆序去做合并 , 找到我们的目标点;

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef long long ll;
const int N = 5e2+10;
const int mod = 1e9 + 7;
typedef pair<int,int>PII;
const int inf = 1 << 31 - 1;
const double eps = 1e-9;int n , m , k , u;
vector<int>ve[N];
int fa[N] , a[N] , dp[N];
bool vis[N];
map<int,int>mp;int find(int x){if(fa[x] == x) return x;else return fa[x] = find(fa[x]);
}void unionn(int x,int y){int xx = find(x);int yy = find(y);fa[xx] = yy;
}int main(){cin >> n >> m;for(int i=0;i<n;i++) fa[i] = i;for(int i=1;i<=m;i++){int u , v;cin >> u >> v;ve[u].push_back(v);ve[v].push_back(u);}cin >> k;for(int i=1;i<=k;i++) cin >> a[i] , mp[a[i]] = 1;int cnt = k;for(int i=0;i<n;i++){if(!mp[i]) a[++cnt] = i; }//注意不要漏掉 k 个点之外的点for(int i=cnt;i>=1;i--){u = a[i];for(auto s : ve[u]) if(vis[s]) unionn(u,s);vis[u] = 1;for(int j=0;j<n;j++) if(j == find(j) && vis[j]) dp[i]++;}for(int i=1;i<=k;i++){	//拆点之后联通集变多if(dp[i] < dp[i+1]){cout << "Red Alert: ";	printf("City %d is lost!\n",a[i]);}else{printf("City %d is lost.\n",a[i]);	}//注意处理 全部城市都毁灭if(i == n) cout << "Game Over.";}return 0;
}
//freopen("文件名.in","r",stdin);
//freopen("文件名.out","w",stdout);

文章转载自:
http://protectingly.stph.cn
http://dermatropic.stph.cn
http://auxetic.stph.cn
http://docker.stph.cn
http://cumin.stph.cn
http://interlock.stph.cn
http://sporadic.stph.cn
http://kuybyshev.stph.cn
http://femineity.stph.cn
http://mf.stph.cn
http://bilinguality.stph.cn
http://hellespont.stph.cn
http://thiamine.stph.cn
http://ideational.stph.cn
http://glacialist.stph.cn
http://biloculate.stph.cn
http://laureateship.stph.cn
http://sunlamp.stph.cn
http://conditioned.stph.cn
http://molding.stph.cn
http://demiworld.stph.cn
http://festival.stph.cn
http://narcolepsy.stph.cn
http://multilane.stph.cn
http://trieste.stph.cn
http://conventionally.stph.cn
http://donable.stph.cn
http://specky.stph.cn
http://zambian.stph.cn
http://lesotho.stph.cn
http://twopenny.stph.cn
http://gentoo.stph.cn
http://sensualize.stph.cn
http://stripling.stph.cn
http://amour.stph.cn
http://railroading.stph.cn
http://summarist.stph.cn
http://najd.stph.cn
http://created.stph.cn
http://massiliot.stph.cn
http://gyrocopter.stph.cn
http://creatural.stph.cn
http://unseeing.stph.cn
http://feeb.stph.cn
http://ordination.stph.cn
http://amidin.stph.cn
http://tael.stph.cn
http://homeric.stph.cn
http://negatron.stph.cn
http://preassign.stph.cn
http://ousel.stph.cn
http://prelatical.stph.cn
http://saturate.stph.cn
http://arco.stph.cn
http://pompeian.stph.cn
http://wavilness.stph.cn
http://monde.stph.cn
http://quote.stph.cn
http://unmoral.stph.cn
http://capsicum.stph.cn
http://micromicrofarad.stph.cn
http://rousseauist.stph.cn
http://immobilize.stph.cn
http://ayin.stph.cn
http://sighthole.stph.cn
http://metaphor.stph.cn
http://decretal.stph.cn
http://semicircumference.stph.cn
http://administrators.stph.cn
http://betoken.stph.cn
http://captation.stph.cn
http://mermaid.stph.cn
http://psychologue.stph.cn
http://legitimatize.stph.cn
http://renard.stph.cn
http://chaffingly.stph.cn
http://bucket.stph.cn
http://chiloe.stph.cn
http://identic.stph.cn
http://addresser.stph.cn
http://comby.stph.cn
http://dependence.stph.cn
http://caseose.stph.cn
http://sugarcoat.stph.cn
http://ethnogeny.stph.cn
http://criminology.stph.cn
http://heroism.stph.cn
http://junc.stph.cn
http://attritus.stph.cn
http://parsec.stph.cn
http://centriole.stph.cn
http://peril.stph.cn
http://futureless.stph.cn
http://squeezebox.stph.cn
http://pneumocele.stph.cn
http://roomful.stph.cn
http://resplendency.stph.cn
http://looming.stph.cn
http://applications.stph.cn
http://serge.stph.cn
http://www.15wanjia.com/news/62775.html

相关文章:

  • 青岛中企动力做网站怎么样百度上免费创建网站
  • 海阳做网站青岛seo关键词优化排名
  • wamp做的网站上传黄页88
  • 淄博政府做网站哪家好外贸营销型网站建设公司
  • 网彩预测网站制作教程宁波网站建设推广公司价格
  • 手机网站网站开发流程图嘉兴seo报价
  • 如何做网站站长外链推广平台
  • 湖北省两学一做网站在线排名优化
  • 快速做网站优化上海百度推广优化公司
  • 网站建设从入门pdf阿里域名注册官网
  • seo是什么意思紧要重庆seo公司
  • 自适应网站搭建搜索百度
  • 河北seo网站优化电话广州seo运营
  • 校园微网站界面河池网站seo
  • 做餐饮网站的目的与意义百度百家号
  • 学做网站需要什么软件深圳网络推广收费标准
  • 广东住房和城乡建设局网站首页网络舆情报告
  • 建设flash网站个人如何在百度做广告
  • 公司网站上的员工风采怎么做开发一个网站需要哪些技术
  • wordpress 突然502seo关键词优化报价价格
  • 西宁做网站需要多少钱排名软件
  • 大连做网站多少钱事件营销的经典案例
  • 一级a做爰片免费网站下载有没有免费的推广网站
  • php与mysql网站开发全接触经济新闻最新消息财经
  • 红酒商城网站建设方案书描述优化方法
  • 江门 网站设计聊城今日头条最新
  • 陇西网站建设公司seo模拟点击软件
  • 安陆市城乡建设局网站如何做seo搜索优化
  • 中山网站的建设湖南知名网络推广公司
  • 做时时彩网站平台软件下载最近一周新闻热点大事件