![](https://img-blog.csdnimg.cn/20190927151117521.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
HDU、OJ、CF...
航电、OJ、CF等网站中刷的题
percation
快乐coding,coding快乐~
展开
-
【洛谷】P1162 填涂颜色(bfs)
穿越隧道关键对矩阵周围一圈的0进行判断哪些0和他联通,进行标记#include <bits/stdc++.h>#define x first#define y second using namespace std;typedef pair<int,int> pii;const int N = 2e2 + 10;int g[N][N];int n;pii q[N*N];bool st[N][N];bool vis[N][N];int dx[4] = {-原创 2022-04-22 21:09:28 · 315 阅读 · 0 评论 -
【洛谷】P2372 yyy2015c01挑战算周长(BFS)
穿越隧道算(x,y)坐标所在位置的连通块的周长。周长:判断四个方向有无X,是否越界,统计答案。#include <bits/stdc++.h>#define x first#define y secondusing namespace std;typedef pair<int,int> pii;const int N = 2e2 + 10;char g[N][N];int n,m;int x,y;int ans;pii q[N*N];bool st[原创 2022-04-22 16:11:00 · 185 阅读 · 0 评论 -
【洛谷】P1464 Function*(记忆化搜索)
穿越隧道输出有坑,ans和前面的部分要分开输出。。。。奇奇怪怪#include <bits/stdc++.h>using namespace std;typedef long long ll;const int N = 25;//将搜索的结果,存起来就是记忆化搜索//防止重复递归,TLE ll path[N][N][N]; ll dfs(ll a, ll b, ll c){ if(a <= 0 || b <= 0 || c <= 0){ retu原创 2022-04-22 15:00:36 · 172 阅读 · 0 评论 -
【洛谷】P1036 [NOIP2002 普及组] 选数(DFS)
穿越隧道递归组合型的微变型#include <bits/stdc++.h>using namespace std;const int N = 1e2 + 10;int ans;int n,m;int res = 0;int a[N];bool st[N];int path[N];bool is_prime(int x){ for(int i = 2; i <= x/i; i++){ if(x % i == 0) return false; } retu原创 2022-04-22 14:17:15 · 170 阅读 · 0 评论 -
【洛谷】P1157 组合的输出(dfs)
穿越隧道题面微变型的递归枚举组合型#include <bits/stdc++.h>using namespace std;const int N = 30;int n,m;bool st[N];int path[N];void dfs(int u, int start){ if(u >= m){ for(int i = 0; i < m; i++){ printf("%3d",path[i]); } puts(""); return ;原创 2022-04-22 14:06:43 · 477 阅读 · 0 评论 -
【洛谷】P1734 最大约数和(01背包|数学)
穿越隧道01背包模板题#include <bits/stdc++.h>using namespace std;const int N = 1e3 + 10;int a[N];int sum[N];int n;int f[N];void chk(int x){ sum[x]++;//1是所有数的约数 for(int i = 2; i < x; i++){ if(x % i == 0){ sum[x] += i; } }}int main(){原创 2022-04-18 14:07:41 · 169 阅读 · 0 评论 -
【洛谷】P1141 01迷宫
穿越隧道也是连通块的面积问题(flood fill)#include <iostream>#include <algorithm>#include <cstring>#include <queue>using namespace std;#define x first#define y secondtypedef pair<int,int> pii;const int N = 200;char g[N][N];pii原创 2022-03-29 15:45:05 · 109 阅读 · 0 评论 -
【洛谷】P1451 求细胞数量(flood fill)
穿越隧道求连通块的数量,类似flood fill#include <iostream>#include <cstring>#include <algorithm>#include <queue>#define x first#define y secondusing namespace std;const int N = 1e2 + 10;typedef pair<int,int> pii;char g[N][N];bo原创 2022-03-29 15:08:21 · 179 阅读 · 0 评论 -
【洛谷】P2298 Mzc和男家丁的游戏*
穿越隧道有点点谜,和离开中山路一样,有点谜将’d’,置为‘.’,只判断是否为g[i][j]是否为’.'就wa如果判断‘.‘和‘d’,反而没啥问题#include <iostream>#include <cstring>#include <algorithm>#include <queue>#define x first#define y secondusing namespace std;const int N = 2e3 + 10;原创 2022-03-29 14:46:48 · 4346 阅读 · 0 评论 -
【洛谷】P1746 离开中山路*(bfs搜索)
穿越隧道有些怪,好像转成整型就会RE。使用他的字符型,就ac了#include <iostream>#include <cstring>#include <algorithm>#include <queue>#define x first#define y secondusing namespace std;typedef pair<int,int> pii;const int N = 2e3 + 10;char g[N原创 2022-03-29 14:25:04 · 244 阅读 · 0 评论 -
【洛谷】P1747 好奇怪的游戏(bfs)
穿越隧道水题#include <iostream>#include <algorithm>#include <cstring>#include <cmath>#define x first#define y secondusing namespace std;const int N = 210;typedef pair<int,int> pii;pii q[N *N];int g[N][N];int dx[] = {原创 2022-03-29 12:14:48 · 3829 阅读 · 1 评论 -
【洛谷】P1443 马的遍历*(bfs搜索)
穿越隧道看到题意说的最短,说明bfs。然后,坑点在于输出格式printf("%-kd")-表示负号k表示数字占几格(若数字位数不够k,会用空格补足).这道题还是比较简单滴。#include <iostream>#include <algorithm>#include <cstring>#include <cmath>#include <queue>#define x first#define y secondusi原创 2022-03-29 12:04:41 · 318 阅读 · 0 评论 -
【洛谷】P2904 River Crossing S***(背包思想)
穿越隧道图片中的说明:17是人(m=10) + 前两头牛的前缀和(3+4)#include <bits/stdc++.h>using namespace std;typedef long long ll;const int N = 5e4 + 10;int sum[N];int w[N];int n,m;int f[N];int main(){ cin >> n >> m; for(int i = 1; i <= n; i++){原创 2022-03-27 16:57:03 · 227 阅读 · 0 评论 -
【洛谷】P1757 通天之分组背包**(分组背包)
穿越隧道还是数组模拟快。通过数组模拟,来找到有多少组。每组有哪几样背包,每个背包的体积和价值是咋样的。#include <bits/stdc++.h>using namespace std;const int N = 1e3 + 10;int s[N];int v[N][N],w[N][N];int f[N];int n,m;int a,b,c;unordered_map<int,int> mp;//统计有多少组 int d[N];int main()原创 2022-03-27 16:26:17 · 295 阅读 · 0 评论 -
【洛谷】P1832 A+B Problem(再升级)***(完全背包)
穿越隧道需理解求方案数的dp是咋实现的。#include <bits/stdc++.h>using namespace std;typedef long long ll;const int N = 1e4 + 10;bool st[N];int primes[N];int cnt;ll f[N]; int main(){ for(int i = 2; i <= 1000; i++){ if(!st[i]) primes[cnt++] = i; for(i原创 2022-03-27 16:07:38 · 258 阅读 · 0 评论 -
【洛谷】P6771 Space Elevator 太空电梯***(多重背包)
穿越隧道没有理清所限制的高度之间的关系。需要反复理解。#include <bits/stdc++.h>using namespace std;const int N = 1e3 + 10, M = 5e5 + 10;int n;//int h[N],a[N],s[N];//int hh,aa,ss;int t = 0;int f[M];struct node{ int h; int a,s;}c[N];bool cmp(node a, node b){ re原创 2022-03-27 15:50:45 · 378 阅读 · 0 评论 -
【洛谷】P2347 [NOIP1996 提高组] 砝码称重*
穿越隧道将多重背包硬拆成01背包。结合map,来算方案数。#include <iostream>#include <cstring>#include <algorithm>#include <cmath>#include <map>using namespace std;const int N = 1e5;int n,m;map<int,int> mp;int v[N],w[N];int s;int t原创 2022-03-27 11:24:11 · 439 阅读 · 0 评论 -
【洛谷】P2918 [USACO08NOV]Buying Hay S***(完全背包)
穿越隧道和音量调节有些类似,具体又有点说不出来,都要最后在一个范围里找到他们的极值。注意数据范围,有一个坑至少H磅干草#include <iostream>#include <bits/stdc++.h>using namespace std;const int N = 200, M = 2e5 + 10;int p[N],c[N];int f[M];int n,h;int main(){ cin >> n >> h; for(原创 2022-03-26 21:52:04 · 311 阅读 · 0 评论 -
【牛客】2022上海理工大学校内选拔赛(GPLT)*
A+B Problem穿越隧道思路如题意#include <bits/stdc++.h>using namespace std;const int N = 1e6 + 10;// int a[N];struct node{ int idx; int v;}a[N];int n;int b[N];bool cmp(node a, node b){ return a.v <= b.v;}int main(){ scanf("%d"原创 2022-03-26 20:42:23 · 606 阅读 · 0 评论 -
【洛谷】P1509 找啊找啊找GF**(二维价值的01背包)
穿越隧道两个dp数组,一个记录最多的mm数量一个dp数组,记录在最多的mm数量下的最短时间。#include <iostream>#include <algorithm>#include <cstring>using namespace std;const int N = 999;int num[N][N];int n;int f[N][N];int rmb[N],rp[N],ti[N];int main(){ cin >> n;原创 2022-03-25 21:47:39 · 218 阅读 · 0 评论 -
【洛谷】P1877 [HAOI2012]音量调节***(01背包)
穿越隧道方法1到达型dp.#include <iostream>#include <algorithm>#include <cstring>#include <cmath>using namespace std;const int N = 1e3 + 10;int n, bg, mx;int a[N];int f[N][N];int main(){ cin >> n >> bg >> mx;原创 2022-03-25 17:21:47 · 555 阅读 · 0 评论 -
【洛谷】P1507 NASA的食物计划&P1910 L国的战斗之间谍&P1855 榨取kkksc03(二维价值01背包)
穿越隧道同宠物小精灵的收服,也是二维价值的01背包问题。#include <iostream>#include <cstring>using namespace std;const int N = 500;int f[N][N];int n,m,vv;int v[N],p[N],k[N];int main(){ cin >> vv >> m; cin >> n; for(int i = 1; i<= n; i++原创 2022-03-25 16:08:00 · 188 阅读 · 0 评论 -
【洛谷】P1679 神奇的四次方数***(完全背包|dfs)
穿越隧道需抽象成完全背包#include <iostream>#include <cmath>#include <algorithm>#include <cstring>using namespace std;const int N = 2e5 + 10;int f[N],s[N];int n;int main(){ scanf("%d",&n); int up = ceil(sqrt(sqrt(n) + 1));//原创 2022-03-25 15:30:20 · 456 阅读 · 0 评论 -
【洛谷】P1853 投资的最大效益*(完全背包)
穿越隧道往模板上套#include <iostream>#include <cstring>using namespace std;const int N = 1e7 + 10, M = 20;int f[N];int v[M],w[M];int m,n,d;int main(){ scanf("%d%d%d",&m,&n,&d); for(int i = 1; i <= d; i++){ scanf("%d%d",&原创 2022-03-25 14:50:01 · 196 阅读 · 0 评论 -
【洛谷】P2392 kkksc03考前临时抱佛脚**(01背包)
穿越隧道需将一次可以处理两个题目,视为左脑一题右脑一题。即01背包的抽象#include <iostream>#include <algorithm>#include <cstring>#include <cmath>using namespace std;const int N = 1210;//注意范围 int s[N];int b[N],c[N],d[N];int n,m,k,g;int f[N];int main(){原创 2022-03-25 14:32:45 · 172 阅读 · 0 评论 -
【洛谷】P1926 小书童——刷题大军*
穿越隧道与精卫填海类似#include <iostream>#include <cstring>#include <algorithm>#include <cmath>using namespace std;const int N = 200;int f[N];int ff[N];int jt[N];//作业时间 int jf[N];//作业分数 int tm[N];//题目所需要的时间int main(){ int n,m,k原创 2022-03-25 12:21:31 · 155 阅读 · 0 评论 -
【洛谷】P1802 5 倍经验日*
穿越隧道二维dp#include <iostream>#include <algorithm>#include <cstring>#include <cmath>using namespace std;typedef long long ll;const int N = 1e3 + 10;int n,m;int lose[N],win[N],use[N];ll f[N][N];int main(){ scanf("%d%d",&原创 2022-03-25 10:34:49 · 131 阅读 · 0 评论 -
【洛谷】P2722 [USACO3.1]总分 Score Inflation
穿越隧道注意看题目,价值和花费的顺序稍微反了。#include <iostream>#include <cstring>using namespace std;typedef long long ll;const int N = 1e4 + 10;ll f[N];int n,m;int v[N],w[N];int main(){ scanf("%d%d",&m,&n); for(int i = 1; i <= n; i++) {原创 2022-03-24 22:14:54 · 231 阅读 · 0 评论 -
【洛谷】P1616 疯狂的采药*(完全背包)
穿越隧道注意数据范围!!#include <iostream>#include <cmath>#include <algorithm>using namespace std;typedef long long ll;const int N = 1e7 + 10, M = 1e4 + 10;ll f[N];int n,m;int v[M],w[M];//int ff[N][N];int main(){ scanf("%d%d",&m,&原创 2022-03-24 22:10:26 · 168 阅读 · 0 评论 -
【洛谷】P1144 最短路计数***(spfa | bfs)
穿越隧道需反复理解,spfa函数中的dis[j] == dis[t] + 1这段代码不太理解重边,它(上述代码)是如何实现计算的。实现:链式前向星、队列(类似bfs)以及因边权为1,所以最短路为上一个结点加1.#include <iostream>#include <algorithm>#include <cstring>#include <queue>using namespace std;int n,m;const int N =原创 2022-03-23 21:55:46 · 254 阅读 · 0 评论 -
【洛谷】P1629 邮递员送信*(Dijkstra 邻接矩阵 + 正反建图)
穿越隧道首先,是直接采用邻接矩阵的方式来正向建图,算1到各个结点的最短距离,ans累加。然后,算2到各个结点的最短距离,res累加各结点到1的距离。然后,超时。毕竟O(n3)O(n^3)O(n3)再之后,看了各大佬题解后(洛谷)看到了反向建图的思路,于是有了,如下AC代码#include <iostream>#include <cstring>#include <algorithm>#include <queue>#include &l原创 2022-03-23 10:26:53 · 914 阅读 · 0 评论 -
【洛谷】P3371 【模板】单源最短路径(弱化版和标准版)
穿越隧道纯蛮力准备明天3.23把扩展欧几里得的知识看看,然后补上扩展欧几里得版#include <iostream>using namespace std;int main(){ // 请在此输入您的代码 int ans = 0; int flag =0; for(int i = 0; i < 100000; i++){ for(int j = 0; j < 10000; j++){ if(i*97 - j * 127 == 1){原创 2022-03-22 15:00:05 · 218 阅读 · 0 评论 -
【poj】放苹果**(dp|搜索|暴力)
穿越隧道打表找规律分析方案数。方案数一般与dp相关。数据量较小,也可以用搜索和暴力来做。#include <iostream>#include <cstring>#include <algorithm>using namespace std;const int N = 20;int t;int n,m;int f[N][N];int main(){ scanf("%d",&t); while(t--){ scanf("%d%原创 2022-03-20 13:07:04 · 85 阅读 · 0 评论 -
【洛谷】P1510 精卫填海(01背包)*
穿越隧道01背包的微微变型#include <bits/stdc++.h>using namespace std;const int N = 1e4 + 10, M = 1e4 + 10;int n,m,c;int v[N],e[N];int f[M],a[N];int res;int main(){ scanf("%d%d%d",&res,&n,&c); for(int i =1; i<= n; i++){ scanf("%d%d",原创 2022-03-18 18:32:12 · 460 阅读 · 0 评论 -
【洛谷】P2814 家谱(并查集)**
穿越隧道需要注意输入输出的使用以及查找某个字符串的父亲字符串,这种数据结构若没想清直接用string p[N],是行不通的。;N为整型,不能为字符串。看到大佬的题解,有的使用的是map<string,string>。。顿悟哭#include <bits/stdc++.h>using namespace std;const int N = 5e4 + 10;map<string,string> p;//开始我用的是string p[N],报错是肯定的,p[原创 2022-03-17 20:54:49 · 501 阅读 · 0 评论 -
【洛谷】P1455 搭配购买**
穿越隧道并查集和01背包的搭配01背包需优化,防止TLE.#include <bits/stdc++.h>using namespace std;const int N = 1e4 + 10;int p[N];int n,m,k;int w[N];//第i朵云的价钱int v[N];//第i朵云的价值 int f[N];int ans;int find(int x){ if(p[x] != x){ p[x] = find(p[x]);//路径压缩,直接除根节点外原创 2022-03-17 20:17:52 · 482 阅读 · 0 评论 -
【2022软院选拔】 待续
你叉叉你叉叉模拟找规律。#include <bits/stdc++.h>using namespace std;typedef long long ll;const ll N = 1e3 + 10,M = 49;int cnt;char f[N][N];double zy[N];int n,m;int main(){ while(scanf("%d %d",&n,&m) != EOF){ for(int i = 1; i <= n; i原创 2022-03-15 22:22:25 · 195 阅读 · 0 评论 -
【算法竞赛进阶指南】前缀统计
穿越隧道题意:查询已有的字典树中,字符串m的前缀有多少个。参照Trie字符串统计代码来进行,进行相应改变。思路还是使用cnt[N]数组来统计,建字典树时,每个字符串结尾的数量。查询:遍历需要查询字符串,在遍历的过程中,加上该字符串前缀的数量cnt[p]。#include <bits/stdc++.h>using namespace std;const int N = 1e6 + 10, M = 5e6 + 10;int son[M][30];int cnt[M],i原创 2022-03-11 16:42:08 · 180 阅读 · 0 评论 -
【牛客】锦标赛
穿越隧道题意小美是第一位参赛者,她能坚持多少轮比赛.每轮比赛两个人进行积分pk,积分高的人获胜.思路:统计 积分小于等于小美(含小美)的人数cnt判断经过多少次cnt=1(cnt=1,表明在小于等于小美积分的群体中,产生了冠军),也是小美最多能活的轮次.#include <bits/stdc++.h>using namespace std;const int N = 2e6 + 10;int a[N];int b[N];int n;int main(){原创 2022-03-10 10:49:57 · 112 阅读 · 0 评论 -
【CF #734 (Div. 3)】A. Polycarp and Coins
穿越隧道很魔幻,意外猜对了。(侥幸)题意:n为要支付的钱。使值为1的硬币C1C_1C1 和值为2的硬币C2C_2C2数量只差尽可能小,并且C1+C2∗2=nC_1 + C_2 *2 = nC1+C2∗2=n猜测是当n为3的倍数时,C1C_1C1和C2C_2C2的数量可以相等当n不是3的倍数时,有C1C_1C1比C2C_2C2数量多的情况,也有C2C_2C2比C1C_1C1数量多的情况。具体是看样例来猜测,当n%3为2时,C2C_2C2比C1C_1C1多一个,当n%3为原创 2022-03-03 20:17:26 · 99 阅读 · 0 评论