QFNU 10-16 training
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的更多相关文章
- 背水一战 Windows 10 (16) - 动画: ThemeAnimation(主题动画)
[源码下载] 背水一战 Windows 10 (16) - 动画: ThemeAnimation(主题动画) 作者:webabcd 介绍背水一战 Windows 10 之 动画 PopInThemeA ...
- ERROR 2003 (HY000): Can't connect to MySQL server on '10.16.115.101' (111)
ubuntu安装之后mysql,使用apt-get安装命令,默认为同意只本地访问 root@idata1:~/software# mysql -uroot -p123456 -h10.16.115.1 ...
- 10.16 NOIP模拟赛
目录 2018.10.16 NOIP模拟赛 A 购物shop B 期望exp(DP 期望 按位计算) C 魔法迷宫maze(状压 暴力) 考试代码 C 2018.10.16 NOIP模拟赛 时间:2h ...
- 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 ...
- 2019.10.16&17小结
话说也蛮久没写小结了,主要这两次考试失分严重,还是总结下吧. 10.16 T1 小奇挖矿2 100/0 [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿石交易市 ...
- [NOIP2018模拟赛10.16]手残报告
[NOIP2018模拟赛10.16]手残报告 闲扯 炉石乱斗模式美滋滋啊,又颓到好晚... 上来T2先敲了树剖,看T1发现是个思博DP,然后没过大样例,写个暴力发现还是没过大样例!?才发现理解错题意了 ...
- windows10 下访问 virtualbox 虚拟机的linux15.10/16.04 系统 及 用 putty 访问虚拟机的配置
参考: http://www.doc88.com/p-915707596190.html --- 安装samba http://my.oschina.net/u/2260265/blog/405598 ...
- java 2 8 10 16
An integer literal may be expressed in decimal (base 10), hexadecimal (base 16), octal (base 8), or ...
- JS实现2,8,10,16进制的相互转换
// 10进制转为16进制 var a=1234567890; console.log(a.toString(16)) //499602d2 // 16进制转为10进制 var num=parseIn ...
- A 题解————2019.10.16
[题目描述] 对于给定的一个正整数n, 判断n是否能分成若干个正整数之和 (可以重复) ,其中每个正整数都能表示成两个质数乘积. [输入描述]第一行一个正整数 q,表示询问组数.接下来 q 行,每行一 ...
随机推荐
- Qt3D使用assimp加载常规模型文件
Qt3D使用assimp加载三维模型文件,assimp支持很多常规格式的三维模型格式: 其中支持导入的格式有: 3D 3DS 3MF AC AC3D ACC AMJ ASE ASK B3D BLEND ...
- 攻防世界 reverse EASYHOOK
EASYHOOK XCTF 4th-WHCTF-2017 1 data=[ 0x61, 0x6A, 0x79, 0x67, 0x6B, 0x46, 0x6D, 0x2E, 0x7F, 0x5F, 2 ...
- sqli-labs系列——第六关
less6 这个本质上跟第五关相同都是使用报错注入,这一关使用的是双引号闭合 还是使用updatexml()这个函数 ?id=1" union select updatexml(1,conc ...
- 使用ant design vue的日历组件,实现一个简单交易日与非交易日的切换
使用ant design vue的日历组件,实现一个简单交易日与非交易日的切换 需求: 日历区分交易日.非交易日 可以切换面板查看整年交易日信息 可以在手动调整交易日.非交易日 演示实例 序--使用软 ...
- 走进docker-swarm 带大家快速掌握docker自带编排工具
什么是Docker Swarm? 对比Docker 前面我们介绍过Docker可以理解成是一个我们的服务的独立运行的容器,那么在实际工作中,我们的系统可能是一个微服务应用,系统中根据业务拆分成多个模块 ...
- HTML5获取地理位置定位信息
如何使用HTML5地理位置定位功能 定位功能(Geolocation)是HTML5的新特性,因此只有在支持HTML5的现代浏览器上运行,特别是手持设备如iphone,地理定位更加精确.首先我们要检测用 ...
- Leedcode算法专题训练(哈希表)
Java 中的 HashSet 用于存储一个集合,可以查找元素是否在集合中.如果元素有穷,并且范围不大,那么可以用一个布尔数组来存储一个元素是否存在.例如对于只有小写字符的元素,就可以用一个长度为 2 ...
- SecureCRT 连接Win10内置ubuntu问题及解决办法
1: 输入hostname, username 后连接提示: ubuntu The remote system refused the connection. 因为没有安装或启动 ssh. 使用命令 ...
- Proxy.newProxyInstance源码探究
JDK动态代理案例实现:实现 InvocationHandler 接口重写 invoke 方法,其中包含一个对象变量和提供一个包含对象的构造方法: public class MyInvocationH ...
- 906. Super Palindromes
Let's say a positive integer is a superpalindrome if it is a palindrome, and it is also the square o ...