NOIP/ACM/ICPC
高中学习NOIP竞赛时做的一些题目。以及大学练习竞赛时做的一些题目。
Coder.AN
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
严格次小生成树 洛谷P4180题解
先粘代码,后期更新原理。#include <cstdio>#include <cmath>#include <iostream>#include <algorithm>using namespace std;#define MaxN 100005#define MaxM 300005#define LogN 20#define INF 0x7fffffffffffffffLLint N, M;struct EDGE{ i原创 2021-01-05 15:28:50 · 189 阅读 · 0 评论 -
洛谷P1967题解
首先找出图中每个连通分量的最大生成树,然后在树上跑LCA。寻找LCA的时候寻找路径上的最小权值。#include <cstdio>#include <cmath>#include <iostream>#include <algorithm>using namespace std;#define MaxN 10005#define MaxM 50005#define LogN 20#define INF 0x7fffffffint N原创 2021-01-04 14:10:24 · 234 阅读 · 0 评论 -
洛谷P3379题解
树上LCA倍增板子题。#include <cstdio>#include <iostream>using namespace std;#define MaxN 500005#define MaxM 500005*2#define LogN 20int N, M, S;int point[MaxN], tot;int nxt[MaxM], v[MaxM];int deep[MaxN];bool flag[MaxN];int f[MaxN][LogN];原创 2021-01-04 12:36:52 · 205 阅读 · 0 评论 -
洛谷P1991题解
要求最大值最小,不难想到使用二分法。我们每次二分一个“最大的D”,然后将大于D的边舍去,然后看一下去边后的图有多少个连通分量。连通分量的数目就是增配卫星电话的数目。至于求连通分量数目我们可以使用并查集。#include <cstdio>#include <algorithm>#include <cmath>using namespace std;#define MaxP 505int S, P;struct NODE{ double x,原创 2021-01-03 11:34:03 · 223 阅读 · 0 评论 -
洛谷P2872题解
我们假设图G是完全图,预先计算好所有边的权值并加入边集。for(int i = 1; i<=N; ++i) for(int j = i+1; j<=N; ++j){ edge[++cnt].x = i; edge[cnt].y = j; edge[cnt].w = cal_dis(i, j); }在读入输入数据已给的M条边时,直接进行并查集合并处理。 for(int i = 1原创 2021-01-03 11:33:35 · 276 阅读 · 0 评论 -
CodeVS 2924 数独挑战 题解
#include #include using namespace std;int board[9+2][9+2];bool Const[9+2][9+2];bool row[9+2][9+2], col[9+2][9+2], pal[9+2][9+2];int PAL[9+2][9+2]={ {1, 1, 1, 2, 2, 2, 3, 3, 3}, {1, 1,原创 2021-01-02 00:01:56 · 488 阅读 · 0 评论 -
CodeVS 3344 迷宫 题解
#include #include #include using namespace std;const int dn[4]={-1, 0, +1, 0};const int dm[4]={0, +1, 0, -1};int N, M, ans;bool flag[100+2][100+2];char Map[100+2][100+2];bool word[26+2];s原创 2021-01-02 00:01:43 · 870 阅读 · 0 评论 -
CodeVS 1026 逃跑的拉尔夫 题解
#include #include #include #include using namespace std;const int dr[]={-1, 0, +1, 0};const int dc[]={0, +1, 0, -1};const char T[]="NESW";char Map[50+2][50+2];int flag[50+2][50+2];int R, C原创 2021-01-02 00:01:30 · 630 阅读 · 0 评论 -
POJ 1363 Rails 题解
#include #include #include using namespace std;int N;int order[1000+2];stackst;bool Work(){ int i = 1, j = 0; while(i<=N){ if(order[j]!=i && order[j]!=st.top()) st.push(i++); else if(o原创 2021-01-02 00:01:13 · 437 阅读 · 0 评论 -
CodeVS 1018 单词接龙 题解
#include #include #include #include #include using namespace std;int N, ans;char word[20+2][255+2], root;int connect[20+2][20+2];int cnt[20+2];void DFS(int n, int len){ for(int i = 0; i<N原创 2021-01-02 00:00:55 · 751 阅读 · 0 评论 -
CodeVS 1099 字串变换 题解
恩……正常来说第42行代码和第65行代码应该删去……但是被逼无奈……为了应对一组特殊数据耍了一点小聪明……但是呢,没有失大体,不是那种针对输入数据打表骗分……而是针对某组数据进行的剪枝恩……就说这么多,下附代码#include #include #include #include #include #include using namespace std;c原创 2021-01-01 11:52:40 · 409 阅读 · 0 评论 -
CodeVS 1710 生日蛋糕 题解
#include using namespace std;int N, M;int ans = ~0u>>1;bool flag;void DFS(int R, int H, int V, int S, int m){ if(S>ans)return; if(V>R*R*H*m)return; if(m && !V)return; if(!m && V)return; if原创 2021-01-01 11:52:24 · 623 阅读 · 0 评论 -
2.0版 CodeVS1099 字串变换 题解
昨晚十一点第一次完成这道题目……但是呢因为上次的算法用了一点“小聪明”,所以一直觉得不妥。于是今天下午绞尽脑汁地想怎么对广搜进行优化无意间看了一下老师的教案,发现这道题的分类竟然在“双向广搜”里面!!What??还有双向广搜这种东西??以前竟然从来没有听说过于是乎上网查了一下双向广搜是什么东西,用新的方法处理了这道题目。这次稳妥了。又Get了一个新技能,哈哈哈下附代原创 2021-01-01 11:52:07 · 482 阅读 · 0 评论 -
CodeVS 1094 FBI树 题解
#include #include using namespace std;int N;char s[1024+2];char FBI(int L, int R){ if(L == R){ if(s[L]=='0') {cout << 'B'; return 'B';} else if(s[L]=='1') {cout << 'I'; retu原创 2021-01-01 11:51:51 · 580 阅读 · 0 评论 -
CodeVS 1102 采药 题解
恩……最简单的01背包问题时间复杂度O(T*M)空间复杂度O(T)#include using namespace std;int T, M, t, v;int f[1000+2];int main() { scanf("%d %d", &T, &M); for(int i = 1; i<=M; ++i){ scanf("%d %d", &t, &v); for原创 2021-01-01 11:51:30 · 268 阅读 · 0 评论 -
CodeVS 1155 金明的预算方案 题解
分组背包问题时间复杂度:O(M*N/10)空间复杂度:O(N/10)#include #include using namespace std;int N, M;int v, p, q;int tmp, Sum, Max;struct THING{ bool Main; short int num; int Sum[4]; int V[4];}thing[60原创 2021-01-01 11:51:12 · 658 阅读 · 0 评论 -
CodeVS 1063 合并果子 题解
#include #include using namespace std;int a[10000+2];int N, ans;void Heap_adjust(int s, int e){ a[0] = a[s]; for(int i = s+s; i<=e; i += i){ if(i<e && a[i+1]<a[i]) ++i; if(a[i]>=a[0]) bre原创 2021-01-01 11:50:52 · 431 阅读 · 0 评论 -
[解法二] CodeVS1063 合并果子 题解
单调队列解法#include #include using namespace std;int N, a;int ans;priority_queue, greater >que;int main() { scanf("%d", &N); for(int i = 0; i<N; ++i){ scanf("%d", &a); que.push(a); } whil原创 2021-01-01 11:50:34 · 462 阅读 · 0 评论 -
NOIP2016 提高二试 蚯蚓 题解
根据题意,每次都选取长度最长的蚯蚓将其切开,这不由的让我们想到了大顶堆和优先队列(其实优先队列的实质也是堆),但这种做法的复杂度却达到了O[M*log(N+M)],将题目最大数据规模代入约为1.4亿,这显然无法在1s的时间内通过。那还有什么更好的算法能让我们快速的在一组数据中找到一个最大值呢?假设存在长度分别为a[ i ]和a[ j ]的蚯蚓,令其满足i=a[ j ](可以认为a[]数组是原创 2021-01-01 11:50:04 · 621 阅读 · 0 评论 -
2005年全国信息学分区联赛模拟赛 猫猫的小鱼 题解
第一题 猫猫的小鱼提交文件:catfish.pas/c/cpp输入文件:catfish.in输出文件:catfish.out 猫猫是丛林里很多动物心中的天使,她为此十分自豪。猫猫最爱吃鱼了,她每天都要去池塘钓鱼吃。猫猫经常吃鱼脑,数学特别强,然而,小女生的性格决定了她的贪玩。 一天,猫猫钓到了很多条鱼。她并不想马上就把可怜的鱼儿吃掉,而是先折磨够之后再吃(有句话叫什么来原创 2021-01-01 11:49:43 · 917 阅读 · 0 评论
分享