概述

题号 标题 已通过代码 通过率 团队的状态
A Broadcast Stations 点击查看 17/55 未通过
B Connect3 点击查看 167/234 未通过
C Game Map 点击查看 645/2356 通过(图论爆搜)
D Happy Number 点击查看 1177/1908 通过(数字枚举)
E How Many to Be Happy? 点击查看 19/103 未通过
F Philosopher‘s Walk 点击查看 433/1283 通过(分形图或模拟)
G Rectilinear Regions 点击查看 5/26 未通过
H Rock Paper Scissors 点击查看 58/410 未通过
I Slot Machines 点击查看 354/1866 通过(KMP,队友开的)
J Strongly Matchable 点击查看 4/57 未通过
K Untangling Chain 点击查看 159/353 未通过
L Vacation Plans 点击查看 8/83 未通过

C Game Map

链接:https://ac.nowcoder.com/acm/contest/13506/C
来源:牛客网

题目描述

输入描述:

输出描述:

示例1
输入
复制
6 9
0 1
0 4
1 2
1 3
1 4
1 5
2 5
3 4
4 5
输出
复制
4
示例2
输入
复制
12 11
1 2
2 3
3 4
4 5
5 0
6 3
7 4
8 5
9 4
10 5
11 5
输出
复制
5

//题意:给出n个点m条边的无向图,每次只能从度数小的点向度数大的点走,求图中的最长路
//思路:新建一个有向图,从度数小的往大的连有向边,从每个入度为0的节点开始dfs,搜最长链并统计
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e5+10;
vector<int>G[maxn],G2[maxn];
int vis[maxn],in[maxn], tmp = 0;
void dfs(int u,int h){tmp = max(tmp,h);for(int v:G2[u]){if(vis[v])continue;vis[v] = 1;dfs(v,h+1);vis[v] = 0;}
}
int main(){ios::sync_with_stdio(false);int n, m;cin>>n>>m;for(int i = 0; i < m; i++){int x, y;  cin>>x>>y;G[x].push_back(y);G[y].push_back(x);}queue<int>q;for(int i = 0; i < n; i++){for(int u : G[i]){if(G[u].size()<G[i].size()){in[i]++;G2[u].push_back(i);}}if(in[i]==0)q.push(i);}int ans = 0;while(q.size()){int u = q.front(); q.pop();dfs(u,1);ans = max(ans,tmp);}cout<<ans<<"\n";return 0;
}

D. Happy Number

Happy Number
比赛主页

团队提交

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 524288K,其他语言1048576K
64bit IO Format: %lld
题目描述

输入描述:

输出描述:

示例1
输入
复制
19
输出
复制
HAPPY
示例2
输入
复制
5
输出
复制
UNHAPPY

//题意:给出一个数n,每次令n=n的位数平方和,若最后能变成1那就是快乐数,不能就是不快乐。
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main(){LL x;  cin>>x;set<LL>se;int ok = 1;while(1){LL sum = 0;while(x>0){ LL k=x%10; sum+=k*k; x/=10;}if(se.count(sum)){ok = 0; break;}LL tmp = sum;while(tmp%10==0){tmp/=10;}if(tmp==1){ok = 1; break;}se.insert(sum);x = sum;}if(ok==1)cout<<"HAPPY\n";else cout<<"UNHAPPY\n";return 0;
}

F. Philosopher‘s Walk

链接:https://ac.nowcoder.com/acm/contest/13506/F
来源:牛客网

题目描述

输入描述:

输出描述:

示例1
输入
复制
4 10
输出
复制
3 4
示例2
输入
复制
8 19
输出
复制
2 6

//题意:模拟画图
//思路:分形图或者直接模拟,没开longlong改了一个多小时
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
typedef long long LL;LL x=1, y=1, dir=0;
//当前在边长为n的正方形,第k个子正方形中的第res个,子正方形的方向是dir,1表示顺时针,-1表示逆时针,0表示不动,2表示反转
void dfs(LL n, LL k, LL res){//cout<<n<<" "<<dir<<" "<<k<<" "<<res<<":"<<x<<" "<<y<<"\n";if(n==2){//return ;//cout<<n<<" "<<dir<<" "<<k<<" "<<res<<":"<<x<<" "<<y<<"\n";return ;}//cout<<n<<" "<<dir<<" "<<k<<" "<<res<<":"<<x<<" "<<y<<"\n";LL n4 = n*n/4/4;//子正方形的点数if(dir==0){if(res>n4*3){dir=-1;//dir--;x += n/4;dfs(n/2,4,res-n4*3);}else if(res>n4*2){dir = 0;x += n/4; y+=n/4;dfs(n/2,3,res-n4*2);}else if(res>n4){dir = 0;y+=n/4;dfs(n/2,2,res-n4);}else{dir=1;//dir++;dfs(n/2,1,res);}}else if(dir==1){if(res>n4*3){dir=2;//dir++;//y += n/4;//y += n/4;dfs(n/2,4,res-n4*3);}else if(res>n4*2){dir=1;//dir++;//dir = 0;x += n/4; y+=n/4;dfs(n/2,3,res-n4*2);}else if(res>n4){dir=1;//dir++; //dir = 0;x+=n/4;dfs(n/2,2,res-n4);}else{dir = 0;//dir--;dfs(n/2,1,res);}}else if(dir==-1){if(res>n4*3){dir = 0;//dir=1;//dir--;x += n/4; //y+=n/4;dfs(n/2,4,res-n4*3);}else if(res>n4*2){dir=-1;//dir = 0;//y+=n/4;dfs(n/2,3,res-n4*2);}else if(res>n4){dir=-1;//dir = 0;y+=n/4;//x+=n/4;dfs(n/2,2,res-n4);}else{x+=n/4;y+=n/4;dir = 2;//dir++;dfs(n/2,1,res);}}else if(dir==2){if(res>n4*3){dir = 1;y += n/4;dfs(n/2,4,res-n4*3);}else if(res>n4*2){dir=2;dfs(n/2,3,res-n4*2);}else if(res>n4){dir=2;x+=n/4;dfs(n/2,2,res-n4);}else{dir = -1;x += n/4;  y+=n/4;dfs(n/2,1,res);}}
}
int main(){ios::sync_with_stdio(false);LL n, m;  cin>>n>>m;dfs(n*2,1, m);cout<<x<<" "<<y<<"\n";//cout<<y<<" "<<x<<"\n";return 0;
}

本题数据

4 10
3 48 19
2 64 13
4 28 15
1 38 49
8 48 52
7 48 56
6 38 64
8 116 256
16 1

2021年度训练联盟热身训练赛第四场,签到题CDF相关推荐

  1. 2021年度训练联盟热身训练赛第四场 H - Rock Paper Scissors(字符串匹配,FFT)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 2021年度训练联盟热身训练赛第四场 H - Rock Paper Scissors(字符串匹配,FF ...

  2. 2021年度训练联盟热身训练赛第五场

    2021年度训练联盟热身训练赛第五场 链接:https://ac.nowcoder.com/acm/contest/13926 A Binary Seating #include<bits/st ...

  3. 2021年度训练联盟热身训练赛第八场

    目录 2021年度训练联盟热身训练赛第八场 A-Fire on Field 题意 思路 代码 B-Gene Tree 题意 思路 代码 I-Thread Knots 题意 思路 代码 J-Triang ...

  4. 2021年度训练联盟热身训练赛第三场赛后补题

    2021年度训练联盟热身训练赛第三场赛后补题 A Circuit Math [题目分析] [代码展示] B Diagonal Cut [题目分析] [代码展示] C Gerrymandering [题 ...

  5. 2021年度训练联盟热身训练赛第三场(待补)

    文章目录 前言 一.Circuit Math(后缀表达式---栈&&fgets) 二.Diagonal Cut(gcd最大公因数,数论) 三.expected primary-expr ...

  6. 2021年度训练联盟热身训练赛第二场(全)

    传送门 怎么说呢,这次的训练赛的题目难度不是很大,但就是字多 A Binarize It Professor Boolando can only think in binary, or more sp ...

  7. 【2021年度训练联盟热身训练赛第五场】Jam-packed

    import math as ma if __name__=="__main__":n,m = map(int,input().split())if n < m:

  8. 【2021年度训练联盟热身训练赛第四场】Game Map(python C++)

    #include <bits/stdc++.h> #include <vector> #define ll long long using namespace std; int ...

  9. 【2021年度训练联盟热身训练赛第四场】Happy Number(python)

    import math import cmath import sys import string import heapq import bisect import copy from queue ...

  10. 【2021年度训练联盟热身训练赛第二场】Soccer Standings(python)

    import math import cmath import sys import string import bisect import heapq import copy from queue ...

最新文章

  1. linux cenots 查看cpu核数
  2. WebStorm 使用经验
  3. java 扇形_使用js画图之圆、弧、扇形
  4. 绝对精辟!10分钟让你全面了解当前世界金融危机
  5. Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8
  6. CentOS下安装svn,添加新用户,重启svn服务
  7. sqlserver数据库修复
  8. mysql 明文密码_后台能看到明文密码的处理
  9. 解决方案|致拓T8数字化ERP
  10. linux搭建dlna媒体服务器,群晖安装DLNA简单配置打造媒体服务器
  11. Farkas 定理的几何证明
  12. android 模拟器声音设置,android模拟器用mediaplayer播放没有声音
  13. Ubiquitous Religions 宗教信仰
  14. 叽歪网创始人李卓桓:叽歪的微信息模式
  15. 创建Mac的shell命令文件(xxx.sh)
  16. Win10--在右键菜单中添加cmd.exe(在此处打开CMD窗口)
  17. 如何修复老照片?这三个方法建议收藏
  18. 小程序开发总结(详细)
  19. Polo360网站页面制作练习
  20. 注解方式@WebFilter控制做个 filter的执行顺序

热门文章

  1. 中英文对照 —— 心理/神经科学
  2. 【读书笔记】—— 《马克思恩克斯全集》
  3. Logistic Regression 的简单推导
  4. 人,作为社会的基础单元
  5. Python 数据结构与算法 —— 哈弗曼树
  6. bash: !: event not found
  7. Git 远程操作 —— clone、push、pull、fetch
  8. C++ 设计模式 —— 控制器设计模式(实现功能模块间通信)
  9. Trick(十三)—— 数学与函数
  10. STL::算法::常见算法(二)