自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(25)
  • 收藏
  • 关注

原创 方格分割 | 蓝桥杯

方格分割 | 蓝桥杯题目链接 https://www.lanqiao.cn/problems/644/learning/题目分析dfs 深度优先搜索以(3,3)为中心点 向外搜索,搜索到边回溯,每次标记对称点和自身,结果需要除以4(四条边旋转)代码#include<iostream>#include<algorithm>int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};bool book[6][6];bool map[6][6]

2022-03-27 22:18:31 861

原创 承压计算 | 蓝桥杯

承压计算 | 蓝桥杯 7 5 8 7 8 8 9 2 7 2 8 1 4 9 1 8 1 8 8 4 1 7 9 6 1 4 5 4

2022-03-21 23:19:40 152

原创 Weight of the System of Nested Segments

Weight of the System of Nested Segments题目分析贪心+结构体排序由于输出按照输入的顺序,所以将num定义为输入顺序;对结构体排序,将权值最小的放在前2n项,再将它们用坐标排序;需要n个嵌套,所以前2*n一定符合条件;代码#include<iostream>#include<algorithm>using namespace std;struct k{ int val; int num; int pos;}ok[20

2022-03-13 22:59:01 819

原创 P1149 火柴棒等式

洛谷P1149 火柴棒等式题目链接https://www.luogu.com.cn/problem/P1149题目分析数据量较小,采用dfs暴力搜索#include<iostream>#include<algorithm>int huochai[1001] = { 6,2,5,5,4,5,6,3,7,6 };using namespace std;int n;int ans = 0;bool vis[1001];int book[3];void dfs(in

2022-03-07 22:15:13 278

原创 Lotto

Lotto全排列问题用dfs遍历所有情况,但这里需要考虑升序,类似洛谷的选数代码#include<iostream>#include<string.h>#include<algorithm>using namespace std;int n, k;int a[101];bool vis[101];int book[1001];void dfs(int step, int sc){ if (step == 6) { for (int i

2022-03-02 19:22:27 456

原创 动态规划入门

动态规划入门写一点我对动态规划的理解和相关题解首先,我们来看看斐波那契数列 1,1,2,3,5…每一项是前两项的和,这是一个逐渐递增的数组;我们都知道它的算式是F(n)=F(n-1)+F(n-2);输出斐波那契数列的前二十项#include<iostream>using namespace std;int fib(int k){ if (k == 1)return 1; if (k == 2)return 1; else return fib(k - 1) + fib(k -

2022-02-28 19:22:33 211

原创 P1036 [NOIP2002 普及组] 选数

P1036 [NOIP2002 普及组] 选数题目链接https://www.luogu.com.cn/problem/P1036题目分析类似全排列,但是考虑到有重复的问题,需要去重这里我运用了sc 表示(开始查找的位置),每次将i+1的位置标记为下次查找的开始代码#include<iostream>using namespace std;int n, k;int a[101];bool vis[101];int book[1001];int ans = 0;bo

2022-02-26 15:42:34 136

原创 P1068 [NOIP2009 普及组] 分数线划定

P1068 [NOIP2009 普及组] 分数线划定题目链接https://www.luogu.com.cn/problem/P1068题目分析结构体排序代码#include<iostream>#include<algorithm>using namespace std;int n, m;struct student{ int bianhao; int sco;}stu[10001];bool cmp(student x, student y){

2022-02-26 15:19:53 227

原创 P1143 进制转换

P1143 进制转换题目链接 https://www.luogu.com.cn/problem/P1143将n进制转换为m进制数题目分析先将其转换为十进制数,再转换为m进制数;代码#include<iostream>#include<string>#include<cmath>using namespace std;char a[100001];char he[16] = { '0','1','2','3','4','5','6','7','8',

2022-02-18 23:27:47 302

原创 P1162 填涂颜色

P1162 填涂颜色题目链接https://www.luogu.com.cn/problem/P1162题目分析本题考查联通块,采用dfs,但直接查找被一围住的零有些困难,所以先查找外围的0,将它们都替换为3,最后将所有3变为0,0变为2。但是考虑到如下情况:在map二维数组的外围再加入一圈0,将它们联通。代码#include<iostream>using namespace std;int dir[4][2] = {{ 1,0 }, { -1,0 }, { 0,1 }, {

2022-02-17 16:17:02 346

原创 跳跃|蓝桥杯

跳跃|蓝桥杯题目链接https://www.lanqiao.cn/problems/553/learning/题目分析这道题数据结构不大,可以采用dfs;也可以dp;能走的距离只有9个,向斜下方走两格不可以(虽然是距离小于三),这里题目好像有些问题代码dfs#include<iostream>#include<cmath>#include<algorithm>using namespace std;int squ[101][101];int

2022-02-14 23:32:22 6629

原创 部分背包问题|洛谷p2240

部分背包问题|洛谷p2240https://www.luogu.com.cn/problem/P2240题目分析贪心+结构体排序每堆金币包含一个重量和价值的性价比,因为金币可以分割所以只要每次选择性价比最高的金币。代码#include<iostream>#include<algorithm>using namespace std;struct bin{ int m; int v; double rate;}mon[10001];bool cmp(bin

2022-02-12 23:54:48 666

原创 全球变暖|蓝桥杯

全球变暖|蓝桥杯https://www.lanqiao.cn/problems/178/learning/题目分析dfs先查找有多少岛屿和这一题相似,再减去没有淹没的岛屿洛谷 P1596 [USACO10OCT]Lake Counting Shttps://www.luogu.com.cn/problem/P1596Lake Counting代码#include<iostream>using namespace std ;char squ[10001][10001];i

2022-02-09 22:27:32 6569

原创 灌溉|蓝桥杯

灌溉|蓝桥杯https://www.lanqiao.cn/problems/551/learning/代码#include <iostream>using namespace std;int dir[4][2] = { {1,0},{-1,0},{0,1},{0,-1} };int book[101][101];int squ[101][101];int k,m,n;int ans = 0;void dfs(int x, int y,int step){ if (st

2022-02-09 20:05:15 6607 4

原创 卡片|蓝桥杯

卡片https://www.lanqiao.cn/problems/1443/learning/代码#include <iostream>using namespace std;int a[10] = { 2019,2019,2019,2019,2019,2019,2019,2019,2019 ,2019};bool find(int k){ int m; while (k != 0) { m = k % 10; k = k / 10; a[m]--; if

2022-02-07 19:10:43 623

原创 完全二叉树的权值

完全二叉树的权值蓝桥杯原题蓝桥杯https://www.lanqiao.cn/problems/183/learning/代码#include <iostream>using namespace std;const int MAXN = 1e5+7;int a[MAXN];int maxx = -1;int ans = 0;int main(){ int n; cin >> n; for (int i = 1; i <= n; i++) cin

2022-02-07 16:25:51 879

原创 The Way to Home

A - The Way to Home题目翻译一只青蛙生活在 Ox 轴上,需要到达位于 n 点的家。 她从点 1 开始。青蛙可以在不超过 d 的距离处向右跳。 所以,她从点 x 跳跃后,可以到达点 x + a,其中 a 是从 1 到 d 的整数。对于从 1 到 n 的每个点,都知道其中是否有一朵百合花。 青蛙只能用百合花点跳。 保证1点和n点都有百合花。确定青蛙需要到达家的最小跳跃次数,即从点 1 到点 n 处。考虑最初青蛙在点 1。如果青蛙无法到达家,则打印 -1。题目分析搜索每种情况+贪心

2022-01-30 21:39:28 815

原创 A Simple Problem with Integers

A Simple Problem with Integers题目翻译你有 N 个整数,A1, A2, … , AN。 您需要处理两种操作。一种类型的操作是将某个给定的数字添加到给定间隔中的每个数字。另一种是要求给定区间内的数字总和。题目分析线段树模板题(同洛谷P3372)https://www.luogu.com.cn/problem/P3372代码#include<iostream>using namespace std;const int MAXN=100005;l

2022-01-30 21:26:59 1077

原创 Can you answer these queries I

Can you answer these queries I题目翻译你得到一个序列 A[1], A[2], …, A[N] 。 ( |A[i]| ≤ 15007 , 1 ≤ N ≤ 50000 )。查询定义如下:查询(x,y) = Max { a[i]+a[i+1]+…+a[j] ; x ≤ i ≤ j ≤ y }。给定 M 个查询,您的程序必须输出这些查询的结果。求最大子序列;题目分析只要求最大序列而不要求修改使用猫树模板代码#include<iostream>#inc

2022-01-30 21:16:21 344

原创 八皇后 Checkr Challenge

**八皇后 checkr challenge**洛谷原题p1912https://www.luogu.com.cn/problem/P1219题目分析dfs搜索每行每列对角线上不能有重复的皇后棋子从第一行开始逐行搜索每次返回 行数+1;代码#include<iostream>using namespace std;int a[1001],b[1001],c[1001],book[1001];//分别代表行列对角线 book用来记录答案int n,res=0;void

2022-01-27 18:09:47 548

原创 prime ring problem|素数环问题

prime ring problem|素数环问题题目分析相邻的数字相加为素数,dfs搜索,最后看头和尾相加是否为素数;注意这题特别容易PE。。。每一行最后不能加空格每一个case之间要空行且第一个case不能空行代码#include<iostream>#include<string.h>using namespace std;int book[20],a[20];int n,z=1;int zhishu(int k){ for (int i = 2;

2022-01-23 22:43:37 179

原创 Maximum product

Maximum product题目大意找出数组中的最大乘积,如果找不到一个正数结果,输出0.题目分析遍历每一种情况,如果大于max就将其替换。注意每一个case后要空行,否则会PE代码#include<iostream>#include<stdio.h>#include<math.h>#include<string>using namespace std;int main(){ int t,n,k=0; long long pr

2022-01-23 22:37:10 167

原创 Computer games

Computer games题目翻译Monocarp 正在玩电脑游戏。 现在他要完成这个游戏的第一关。一个级别是一个 2 行和 n列的矩形网格。 Monocarp 控制一个字符,该字符从单元格 (1, 1)(1,1) 开始——在第 1 行和第 1 列的交叉处。如果单元格并排和/或角落相邻,Monocarp 的角色可以一步从一个单元格移动到另一个单元格。 形式上,可以从单元格 (x1, y1)到单元格 (x2, y2)一步如果 |x_1 - x_2| 和 |y_1 - y_2|≤1。 显然,禁止出

2022-01-23 22:29:49 2991

原创 Protect sheep

Protect sheep题目分析搜索每只狼所在的位置,将它们用狗围住。代码#include<iostream>using namespace std;char squ[501][501];int m,n;int flag=1;int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};int main(){ cin>>m>>n; int x,y,ex,ey; for(int i=1;i<=m;i++)

2022-01-23 22:12:28 139

原创 Knight moves

Knight moves题目分析bfs宽度优先搜索代码#include<iostream>#include<queue>#include<string.h>using namespace std;int t, n;int sx, sy, ex, ey, nx, ny;int book[305][305];int dir[8][2] = { {2,-1},{2,1},{1,-2},{1,2},{-1,2},{-1,-2},{-2,-1},{-2,1

2022-01-23 21:59:57 413

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除