摘要: 并查集水题~。 const int N=10010; int p[N]; int n,m,q; int find(int x) { if(x != p[x]) p[x]=find(p[x]); return p[x]; } int main() { cin>>m; for(int i=1;i<N;i 阅读全文
posted @ 2021-03-06 21:04 Dazzling! 阅读(43) 评论(0) 推荐(0) 编辑
摘要: 注意括号序列的输出,首先叶子结点不需要括号,其次最外层也不需要括号。 const int N=25; PII tree[N]; string a[N]; int fa[N]; bool leaf[N]; int n; int root=1; void inorder(int u) { if(u == 阅读全文
posted @ 2021-03-06 20:51 Dazzling! 阅读(21) 评论(0) 推荐(0) 编辑
摘要: Project Project 的中文翻译是“项目”或者“工程”,这里的项目是指为实现某个相对独立功能的程序代码合集,这些代码不单单是放在一块,而是有相互之间的关联性,并且有专门负责管理该项目的项目文件,比如: Qt 使用 .pro 文件管理项目; VC++ 则使用 .vcproj 作为项目文件。 阅读全文
posted @ 2021-03-06 19:24 Dazzling! 阅读(4) 评论(0) 推荐(0) 编辑
摘要: 考察点:试除法求约数、方向数组。 类似题:756. 蛇形矩阵。 const int N=10010; int a[N]; int dx[]={0,1,0,-1},dy[]={1,0,-1,0}; int k,n,m; int cnt; bool check(int x,int y) { return 阅读全文
posted @ 2021-03-06 17:27 Dazzling! 阅读(54) 评论(0) 推荐(0) 编辑
摘要: 注意图不一定连通!。 const int N=510; bool g[N][N]; int d[N]; bool vis[N]; int n,m; int cnt; void dfs(int u) { vis[u]=true; cnt++; for(int i=1;i<=n;i++) if(g[u] 阅读全文
posted @ 2021-03-06 15:08 Dazzling! 阅读(27) 评论(0) 推荐(0) 编辑
摘要: 注意结果向下取整。 因为所有长度都要串在一起,每次都等于(旧的绳子长度+新的绳子长度)/2,所以越是早加入绳子长度中的段,越要对折的次数多,所以既然希望绳子长度是最长的,就必须让长的段对折次数尽可能的短。 将所有段从小到大排序,然后从头到尾从小到大分别将每一段依次加入结绳的绳子中,最后得到的结果才会 阅读全文
posted @ 2021-03-06 12:38 Dazzling! 阅读(21) 评论(0) 推荐(0) 编辑
摘要: 水~。 const int N=1010; string a[N]; unordered_set<string> S; int n,step,idx; int main() { cin>>n>>step>>idx; for(int i=1;i<=n;i++) cin>>a[i]; for(int i 阅读全文
posted @ 2021-03-06 11:57 Dazzling! 阅读(20) 评论(0) 推荐(0) 编辑
摘要: 参考柳神代码,考察$set$的自定义排序。 const int N=50010; struct Node { int item; int times; bool operator<(const Node &W) const { if(times != W.times) return times > 阅读全文
posted @ 2021-03-06 11:37 Dazzling! 阅读(54) 评论(0) 推荐(0) 编辑
摘要: 问题描述: 从arr[1, n]这n个数中,找出最大的k个数,这就是经典的TopK问题。 栗子: 从arr[1, 12]={5,3,7,1,8,2,9,4,7,2,6,6} 这n=12个数中,找出最大的k=5个。 一、排序 排序是最容易想到的方法,将n个数排序之后,取出最大的k个,即为所得。 分析: 阅读全文
posted @ 2021-03-06 11:29 Dazzling! 阅读(103) 评论(0) 推荐(0) 编辑