![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
GXNU题单的题解
打工仔
mingyu19
这个作者很懒,什么都没留下…
展开
-
【523. 电话列表(cv)】
原题解#include<bits/stdc++.h>using namespace std;#define fir(i,a,b) for(int i=a;i<=b;i++)const int Len=1e5+10;char st[10100][10];int End[Len],trie[Len][10],tot;void init(){ tot=1; memset(trie[0],0,sizeof(trie[0])); memset(End,0,s原创 2022-04-17 21:02:59 · 147 阅读 · 0 评论 -
【526. 堆排序(cv)】
更多详细介绍/* * Project: 10_堆 * File Created:Wednesday, January 13th 2021, 10:03:02 pm * Author: Bug-Free * Problem:AcWing 838. 堆排序 */#include <algorithm>#include <iostream>using namespace std;const int N = 1e6 + 10;int n, m;int h[N],原创 2022-04-17 21:01:09 · 452 阅读 · 0 评论 -
【512. Trie字符串统计(cv)】
原题解#include <iostream>using namespace std;const int N = 100010;int son[N][26], cnt[N], idx;char str[N];void insert(char *str){ int p = 0; for (int i = 0; str[i]; i ++ ) { int u = str[i] - 'a'; if (!son[p][u]) so原创 2022-04-17 20:58:43 · 175 阅读 · 0 评论 -
【525. 模拟堆】
原题解#include<iostream>#include<algorithm>using namespace std;const int N=1e5+10;int n,m,s;int h[N];void down(int u){ int t=u; if(u*2<=s&&h[u*2]<h[t]) t=u*2;//判断左儿子是否比当前的结点要小 if(u*2+1<=s&&h[u*2+1]<原创 2022-04-17 20:55:47 · 101 阅读 · 0 评论 -
【174. 连通块中点的数量(cv)】
#include<bits/stdc++.h>#define read(x) scanf("%d",&x)using namespace std;const int N = 1e5+5;int n,m,a,b,fa[N], size[N];string act;void init() { for (int i=1; i<=n; i++) { fa[i] = i; size[i] = 1; }}int find(..原创 2022-04-17 20:51:59 · 49 阅读 · 0 评论 -
【513. 最大异或对(cv)】
异或性质+前缀+字典树这道题目很难想到是字典树,如果不是放在字典树单元的话.其实来说,一个整数,是可以转化成为一个32位的二进制数,而也就可以变成长度为32位的二进制字符串.既然如此话,那么我们可以这么做,每一次检索的时候,我们都走与当前AiAi这一位相反的位置走,也就是让Xor值最大,如果说没有路可以走的话,那么就走相同的路.#include<bits/stdc++.h>using namespace std;#define fic(i,a,b) for(int i=a;i&g.原创 2022-04-17 20:49:20 · 87 阅读 · 0 评论 -
【436.亲戚】
一样的板子题练习:合并集合#include <bits/stdc++.h>using namespace std;const int N = 1e5 + 10;int fa[N];int n, m, p;int find(int x){ return x == fa[x] ? x : fa[x] = find(fa[x]); // 非常简洁的写法}int main(){ cin >> n >> m >> p;原创 2022-04-17 20:29:45 · 190 阅读 · 0 评论 -
【合并集合】
基本操作: 模板题并查集:最优美的数据结构建议多敲几遍理解 本题模板的路径压缩, 有兴趣的可以了解一下按秩合并的优化方式, 当路径优化和按秩合并在一起时, 他们的时间复杂度将是 O(n(α)) 的大小#include <bits/stdc++.h>#define int long longusing namespace std;const int N = 1e5 + 10;int fa[N];int n, m;int find(int x){ return原创 2022-04-17 20:23:39 · 898 阅读 · 0 评论 -
【544. 安迪的第一个字典】
原题转载初始化:#include <iostream>#include <cstdio>#include <set>#include <string>using namespace std;int main(){ string str; char ch = getchar(); set <string> S; set <string> ::iterator it; return 0;}首先读入怎么处理,原创 2022-04-10 11:54:54 · 62 阅读 · 0 评论 -
【545. 丑数】
原题转载注意这题输出不带尖括号,要带句号!!WA了2次丑数的素因子都是2,3,5,我们不妨称它们为“丑因子”。由丑数性质可得,一个丑数必然可以由另一个丑数和丑因子(或1)相乘得到。因此我们可以从2,3,5这些最小的丑数开始,分别乘以自身的丑因子递增,然后从乘得的结果中选一个最小的记录下来。这样一次操作就得到一个新的丑数。最后答案输出第1500个丑数就可以了。AC代码:#include<stdio.h>#define N 1500int s[N]={1};int min(in原创 2022-04-10 11:49:21 · 51 阅读 · 0 评论 -
【548. 卡片游戏】
原题转载这是一道很好的队列练手题当然也可以用vectorvector做,只是要用到迭代器,有些许的麻烦所以这题用队列(queue)(queue)会更方便,但vectorvector我也会说先看queuequeue:解题分3步走:1:1:输入数据2:2:执行中间的一大堆指令3:3:输出你可能会说:这不简单?别急,我们先会议一遍队列的基本知识1.1. 定义需要头文件#include2.2. 定义格式为:queue<变量类型,如int,double等> 变量名3.3. 一些原创 2022-04-10 11:46:35 · 3814 阅读 · 0 评论 -
【兔子与兔子】
转载/* * Project: 0x14_Hash * File Created:Monday, January 18th 2021, 2:44:28 pm * Author: Bug-Free * Problem:AcWing 138. 兔子与兔子 */#include <cstring>#include <iostream>using namespace std;typedef unsigned long long ULL;const int N =原创 2022-04-10 11:36:09 · 65 阅读 · 0 评论 -
【单词识别】
#include<bits/stdc++.h>using namespace std;map<string,int> used;string s;int main(){ getline(cin,s); if(s.size()>1000) s=s.substr(0,1000); string now = ""; for(auto x:s){ if(x==' '||x==','||x=='.'){ .原创 2022-04-10 11:28:02 · 1448 阅读 · 0 评论 -
【模拟散列表 (cv)】
转载拉链法开放寻址法拉链法代码/* * Project: 11_哈希表 * File Created:Sunday, January 17th 2021, 2:11:23 pm * Author: Bug-Free * Problem:AcWing 840. 模拟散列表 拉链法 */#include <cstring>#include <iostream>using namespace std;const int N = 1e5 + 3; // 取大于原创 2022-04-10 11:20:37 · 60 阅读 · 0 评论 -
【区间和(模板题)】
前缀和 +离散化(因为内存过不去)#include <bits/stdc++.h>#include <algorithm>#include <cstring>#include <queue>#include <vector>#define IO (ios::sync_with_stdio(false),cin.tie(0),cout.tie(0))#define rep(i,a,n) for(int i=a;i<=n...原创 2022-03-27 14:25:55 · 76 阅读 · 0 评论 -
【喜迎过新春挂灯笼】
算法: 前缀和 + 离散化离散化的两种常用方法1, 排序, 去重, 二分;2, 用map离散化#include <bits/stdc++.h>#include <algorithm>#include <cstring>#include <queue>#include <vector>#define IO (ios::sync_with_stdio(false),cin.tie(0),cout.tie(0))#def...原创 2022-03-27 14:22:48 · 482 阅读 · 0 评论 -
【玩转二进制】
算法: lowbitint lowbit(int x){ return x & -x ;}#include <iostream>using namespace std;int main(){ int n; scanf("%d", &n); while (n -- ) { int x, s = 0; scanf("%d", &x); for (int i = x...原创 2022-03-27 14:17:58 · 47 阅读 · 0 评论 -
【统计单词数(cv)】
注: cv的#include<iostream>#include<cstdio>#include<algorithm>using namespace std;//排序+前缀和 O(nlogn)const int M = 1e6+10;int s[M];//用前缀和数组统计第一到第i个人中没挂的人数int cnt_m=-1,y_m=-1,l;//正确判断的个数最大值;较大的阈值;左边界处理struct STU//用结构体数组定义每个同学的结果...原创 2022-03-27 14:02:23 · 66 阅读 · 0 评论 -
【期末预测之最佳阈值(cv)】
注: cv的, 可自行寻找其他题解#include<iostream>#include<cstdio>#include<algorithm>using namespace std;//排序+前缀和 O(nlogn)const int M = 1e6+10;int s[M];//用前缀和数组统计第一到第i个人中没挂的人数int cnt_m=-1,y_m=-1,l;//正确判断的个数最大值;较大的阈值;左边界处理struct STU//用结构体数...原创 2022-03-27 13:59:59 · 87 阅读 · 0 评论 -
【火星购物(cv)】
注: cv的, 可自行取寻找题解//前缀和加双指针#include<iostream>#include<cstring>using namespace std;const int maxn = 100010, inf = 1e9;int s[maxn];int n, m;int main(){ cin >> n >> m; for(int i = 1; i <= n; i ++){ cin ...原创 2022-03-27 13:57:09 · 48 阅读 · 0 评论 -
【无线网络(cv)】
注: cv的, 可以自行去查找题解//3973. 无线网络#include<iostream>#include<cmath>using namespace std;int m,n;int a[100010],b[100010];int ans=0;int main(){ std::ios::sync_with_stdio(false); int i; cin>>m>>n; for(i=1;i<...原创 2022-03-27 13:53:38 · 72 阅读 · 0 评论 -
【数字游戏 (cv)】
注:CV的, 也可以自行去查找题解按照题意模拟即可,每次取最高位可以不断用x−=lowbit(x)x-=lowbit(x)x−=lowbit(x)减去最低位,直到剩下最高位 每次操作是logxlog xlogx的,最多操作logxlogxlogx次,因为位运算常数小,所以可以通过#include<bits/stdc++.h>#define lowbit(x) (x & -x)using namespace std;int t, n;int main() { ...原创 2022-03-27 13:46:56 · 4118 阅读 · 0 评论 -
【古代文明】
很容易就发现只要将所有数转化成 2 进制, 然后比对每个二进制的每一位, 然后取 max(cnt0, cnt1);// 1;// 5 30;// 1 2 3 4 5#include <iostream>#include <cstring>#include <algorithm>#include <vector>#define fors(i, a, b) for(int i = a; i < b; i ++ )using n...原创 2022-03-27 13:42:56 · 76 阅读 · 0 评论 -
【最小或的和】
规律题, 把所有的样例试一下, 然后会发现#include <iostream>using namespace std;int main(){ int T; cin >>T; while(T -- ) { int n; cin >>n; int res = 0; while(n -- ) { ...原创 2022-03-27 13:31:50 · 287 阅读 · 0 评论 -
【数学考试】
数学考试计 dp[i]dp[i]dp[i] 为 [i,n][i, n][i,n] 区间内,所有的 [i−k,i][i - k, i][i−k,i] 这样的区间中,数之和的最大值。那么只要遍历一遍,当左区间取 [i−k,i][i - k, i][i−k,i] 时,右区间的最大值可以 O(1)O(1)O(1) 读取,即 dp[i+k]dp[i + k]dp[i+k] 。所有以上计算均可以用前缀和达成 O(n)O(n)O(n) 预处理。完整代码如下:#include<bits/st原创 2022-03-20 16:15:06 · 208 阅读 · 1 评论 -
【434.a + b】
434.a + b原创 2022-03-20 15:32:47 · 72 阅读 · 0 评论 -
【382.送分了】
送分了QAQ这道题比较简单, 就是输入的时候需要注意是多组输入.#include <bits/stdc++.h>#include <algorithm>#include <cstring>#define IO (ios::sync_with_stdio(false),cin.tie(0),cout.tie(0))#define rep(i,a,n) for(int i=a;i<=n;i++)using namespace std;typed原创 2022-03-20 15:41:55 · 48 阅读 · 0 评论 -
【414.干草堆】
干草堆#include <iostream>#include <cstring>#include <algorithm>using namespace std;typedef long long ll;typedef pair<int, int> PII;const int N = 1e6 + 10;const int mod = 1e9 + 7;ll res, cnt;int n, m;int x, y;int b[原创 2022-03-20 15:45:32 · 139 阅读 · 0 评论 -
【430.地毯】
地毯#include <bits/stdc++.h>#include <algorithm>#include <cstring>#include <queue>#include <vector>#define IO (ios::sync_with_stdio(false),cin.tie(0),cout.tie(0))#define rep(i,a,n) for(int i=a;i<=n;i++)#define x原创 2022-03-20 15:53:30 · 365 阅读 · 1 评论