7-9.小字辈

思路:建立一个类,并且类中存有其父节点,其地位,其儿子节点(因为儿子节点有很多,所以要用vector进行存储),通过-1这个祖先节点进行查找。首先找到-1这个祖先节点,并且读入其他位置的父节点,与此同时其父节点中儿子节点也有此节点————>然后进行递归查找,以类为类型建立队列,祖先节点进队列,然后for循环给其儿子节点的地位+1,并且让其儿子节点进行入队列,自己出队列,直到队列空————>找到地位的最大值,输出结果

代码:

 1 #include<iostream>
2 #include<algorithm>
3 #include<cmath>
4 #include<cstdio>
5 #include<cstring>
6 #include<set>
7 #include<queue>
8 #include<vector>
9 using namespace std;
10 const int maxx=1e5+10;
11 struct num{
12 int father;
13 int rankk;
14 vector<int> son;
15 }a[maxx];
16 int dfs(int x){
17 queue<num> s;
18 s.push(a[x]);
19 num Q;
20 while(!s.empty()){
21 Q=s.front();
22 for(int i=0;i<Q.son.size();i++){
23 a[Q.son[i]].rankk=Q.rankk+1;
24 s.push(a[Q.son[i]]);
25 }
26 s.pop();
27 }
28 return Q.rankk;
29 }
30 int main(){
31 int t;
32 scanf("%d",&t);
33 int temp;
34 int nus;
35 for(int i=1;i<=t;i++){
36 scanf("%d",&a[i].father);
37 if(a[i].father==-1){
38 temp=i;
39 a[i].rankk=1;
40 }else{
41 a[a[i].father].son.push_back(i);
42 }
43 }
44 int mm=dfs(temp);
45 printf("%d\n",dfs(temp));
46 int flag=0;
47
48 for(int i=1;i<=t;i++){
49 if(a[i].rankk==mm&&flag==0){
50 printf("%d",i);
51 flag=1;
52 }else if(a[i].rankk==mm){
53 printf(" %d",i);
54 }
55 }
56 }

7-12 深入虎穴

思路:首先题目说不存在两条路通向同一扇门,说明本题的图是一棵树。入口唯一,所以入度为 0 的那个点既是树的根节点。然后求一下树中每一个节点的深度,深度最大的那个点即为距离入口最远的那扇门。

 1 #include <iostream>
2 #include <algorithm>
3 #include <cstring>
4 using namespace std;
5 const int maxn = 100010;
6 int head[maxn], Next[maxn], ver[maxn];
7 int vis[maxn], d[maxn], degree[maxn];
8 int n, k, tot;
9 int ans, maxx;
10 void add(int x, int y){//数组模拟邻接表
11 ver[++tot] = y, Next[tot] = head[x];
12 head[x] = tot;
13 }
14 void dfs(int x){
15 vis[x] = 1;
16 for(int i = head[x]; i; i = Next[i]){
17 int y = ver[i];
18 if(!vis[y]){
19 d[y] = d[x] + 1;
20 dfs(y);
21 }
22 }
23 }
24 int main(){
25 cin >> n;
26 for(int i = 1; i <= n; i++){
27 cin >> k;
28 int x;
29 for(int j = 0; j < k; j++){
30 cin >> x;
31 degree[x]++;
32 add(i, x);// i -> x 的有向边
33 }
34 }
35 int rt = 1;
36 for(int i = 1; i <= n; i++){
37 if(!degree[i]){//入度为0的那个点为入口,即根节点
38 rt = i;
39 break;
40 }
41 }
42 d[rt] = 1;//初始化根节点的深度为1
43 dfs(rt);
44 for(int i = 1; i <= n; i++){//寻找深度最大的那个点
45 if(d[i] > maxx) {
46 maxx = d[i];
47 ans = i;
48 }
49 }
50 cout << ans << endl;
51 return 0;
52 }

B - Power Sequence

思路:就是从1-1.0/n遍历一遍找到最小的就可以

代码:

 1 #include<cstdio>
2 #include<algorithm>
3 #include<iostream>
4 #include<queue>
5 #include<map>
6 #include<cmath>
7 #include<cstring>
8
9 using namespace std;
10 const int N = 500007, M = 5000007;
11 const ll INF = 1e14;
12
13 int n, m;
14 ll a[N];
15
16 int main(){
17 scanf("%d", &n);
18 for(int i = 1; i <= n; ++ i){
19 scanf("%lld", &a[i]);
20 }
21 ll ans = INF ;
22 int t = pow(INF, 1.0 / n);
23 sort(a + 1, a + 1 + n);
24 for(int c = 1; c <= t; ++ c){
25 ll sum = 0, tmp = 1;//c^0
26 for(int i = 1; i <= n; ++ i){
27 sum += abs(a[i] - tmp);
28 tmp *= c;
29 }
30 ans = min(ans, sum);
31 }
32 printf("%lld\n", ans);
33 return 0;
34 }

QFNU 10-16 training的更多相关文章

  1. 背水一战 Windows 10 (16) - 动画: ThemeAnimation(主题动画)

    [源码下载] 背水一战 Windows 10 (16) - 动画: ThemeAnimation(主题动画) 作者:webabcd 介绍背水一战 Windows 10 之 动画 PopInThemeA ...

  2. ERROR 2003 (HY000): Can&#39;t connect to MySQL server on &#39;10.16.115.101&#39; (111)

    ubuntu安装之后mysql,使用apt-get安装命令,默认为同意只本地访问 root@idata1:~/software# mysql -uroot -p123456 -h10.16.115.1 ...

  3. 10.16 NOIP模拟赛

    目录 2018.10.16 NOIP模拟赛 A 购物shop B 期望exp(DP 期望 按位计算) C 魔法迷宫maze(状压 暴力) 考试代码 C 2018.10.16 NOIP模拟赛 时间:2h ...

  4. ERROR: openstack Error finding address for http://10.16.37.215:9292/v1/images: [Errno 32] Broken pipe

    Try to set: no_proxy=10.16.37.215 this should help 转自: http://askubuntu.com/questions/575938/error-i ...

  5. 2019.10.16&17小结

    话说也蛮久没写小结了,主要这两次考试失分严重,还是总结下吧. 10.16 T1 小奇挖矿2 100/0 [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿石交易市 ...

  6. [NOIP2018模拟赛10.16]手残报告

    [NOIP2018模拟赛10.16]手残报告 闲扯 炉石乱斗模式美滋滋啊,又颓到好晚... 上来T2先敲了树剖,看T1发现是个思博DP,然后没过大样例,写个暴力发现还是没过大样例!?才发现理解错题意了 ...

  7. windows10 下访问 virtualbox 虚拟机的linux15.10/16.04 系统 及 用 putty 访问虚拟机的配置

    参考: http://www.doc88.com/p-915707596190.html --- 安装samba http://my.oschina.net/u/2260265/blog/405598 ...

  8. java 2 8 10 16

    An integer literal may be expressed in decimal (base 10), hexadecimal (base 16), octal (base 8), or ...

  9. JS实现2,8,10,16进制的相互转换

    // 10进制转为16进制 var a=1234567890; console.log(a.toString(16)) //499602d2 // 16进制转为10进制 var num=parseIn ...

  10. A 题解————2019.10.16

    [题目描述] 对于给定的一个正整数n, 判断n是否能分成若干个正整数之和 (可以重复) ,其中每个正整数都能表示成两个质数乘积. [输入描述]第一行一个正整数 q,表示询问组数.接下来 q 行,每行一 ...

随机推荐

  1. 电影AI修复,让重温经典有了新的可能

    摘要:有没有一种呈现,不以追求商业为第一目的,不用花大价钱,不用翻拍,没有画蛇添足,低成本的可共赏的让经典更清晰? 本文分享自华为云社区<除了重映和翻拍,重温经典的第三种可能>,原文作者: ...

  2. salesforce零基础学习(一百零二)Limitation篇之 CPU Limit

    本篇参考: https://help.salesforce.com/articleView?id=000339361&type=1&mode=1 https://developer.s ...

  3. 学《跟我一起写Makefile》笔记发博词

    目录 笔记发博词 参考 笔记发博词 本系列笔记主要记录学了<跟我一起写Makefile>后的一些笔记 由于<跟我一起写Makefile>已经写得很详细了,所以我只是提取其中重要 ...

  4. 单链表c语言实现的形式

    包括初始化,创建,查询,长度,删除,清空,销毁等操作 代码如下: #include<stdio.h> #include<stdlib.h> //定义单链表的数据类型 typed ...

  5. C# net Emgu.CV.World 人脸识别 根据照片将人脸抠图出来。

    Emgu.CV.World 人脸识别 根据照片将人脸抠图出来.效果如下: 应用范围:配合摄像头,抓取的图像,抠出人脸照片,这样人脸照片的大小会很小,传输速度快.这样识别速度也就快. 目前我正在做百度人 ...

  6. 经常问到的 BFC 和 IFC 是什么?

    什么是BFC?什么作用? Block Formatting Context 块盒子布局发生的区域,浮动元素和其他元素交互的区域 浮动定位和清除浮动的时候只会应用于同一个BFC内的元素.浮动不会影响其他 ...

  7. 201871010130-周学铭 实验二 个人项目—D{0-1}问题项目报告

    项目 内容 课程班级博客链接 18级卓越班 这个作业要求链接 实验二 软件工程个人项目 我的课程学习目标 掌握软件项目个人开发流程.掌握Github发布软件项目的操作方法. 这个作业在哪些方面帮助我实 ...

  8. Spring Boot 2.4 配置文件将加载机制大变化

    Spring Boot 2.4.0.M2 刚刚发布,它对 application.properties 和 application.yml 文件的加载方式进行重构.如果应用程序仅使用单个 applic ...

  9. 浅入Kubernetes(10):控制节点的部署,选择器、亲和性、污点

    目录 标签和nodeSelector 标签选择 亲和性和反亲和性 污点和容忍度 系统默认污点 容忍度 DaemonSet 在前面的学习中,我们学到了 Deployment 部署,以及副本数(Repli ...

  10. 进击中的Vue 3——“电动车电池范围计算器”开源项目

    转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 原文参考:https://dzone.com/articles/build-a-tesla-battery- ...